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)); |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 696 | #ifdef CONFIG_EC_HOST_CMD |
| 697 | /* |
| 698 | * Make sure Zephyre uses the same status codes. |
| 699 | */ |
| 700 | #include <zephyr/mgmt/ec_host_cmd/ec_host_cmd.h> |
| 701 | |
| 702 | BUILD_ASSERT((uint16_t)EC_RES_SUCCESS == (uint16_t)EC_HOST_CMD_SUCCESS); |
| 703 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_COMMAND == |
| 704 | (uint16_t)EC_HOST_CMD_INVALID_COMMAND); |
| 705 | BUILD_ASSERT((uint16_t)EC_RES_ERROR == (uint16_t)EC_HOST_CMD_ERROR); |
| 706 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_PARAM == |
| 707 | (uint16_t)EC_HOST_CMD_INVALID_PARAM); |
| 708 | BUILD_ASSERT((uint16_t)EC_RES_ACCESS_DENIED == |
| 709 | (uint16_t)EC_HOST_CMD_ACCESS_DENIED); |
| 710 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_RESPONSE == |
| 711 | (uint16_t)EC_HOST_CMD_INVALID_RESPONSE); |
| 712 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_VERSION == |
| 713 | (uint16_t)EC_HOST_CMD_INVALID_VERSION); |
| 714 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_CHECKSUM == |
| 715 | (uint16_t)EC_HOST_CMD_INVALID_CHECKSUM); |
| 716 | BUILD_ASSERT((uint16_t)EC_RES_IN_PROGRESS == (uint16_t)EC_HOST_CMD_IN_PROGRESS); |
| 717 | BUILD_ASSERT((uint16_t)EC_RES_UNAVAILABLE == (uint16_t)EC_HOST_CMD_UNAVAILABLE); |
| 718 | BUILD_ASSERT((uint16_t)EC_RES_TIMEOUT == (uint16_t)EC_HOST_CMD_TIMEOUT); |
| 719 | BUILD_ASSERT((uint16_t)EC_RES_OVERFLOW == (uint16_t)EC_HOST_CMD_OVERFLOW); |
| 720 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER == |
| 721 | (uint16_t)EC_HOST_CMD_INVALID_HEADER); |
| 722 | BUILD_ASSERT((uint16_t)EC_RES_REQUEST_TRUNCATED == |
| 723 | (uint16_t)EC_HOST_CMD_REQUEST_TRUNCATED); |
| 724 | BUILD_ASSERT((uint16_t)EC_RES_RESPONSE_TOO_BIG == |
| 725 | (uint16_t)EC_HOST_CMD_RESPONSE_TOO_BIG); |
| 726 | BUILD_ASSERT((uint16_t)EC_RES_BUS_ERROR == (uint16_t)EC_HOST_CMD_BUS_ERROR); |
| 727 | BUILD_ASSERT((uint16_t)EC_RES_BUSY == (uint16_t)EC_HOST_CMD_BUSY); |
| 728 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_VERSION == |
| 729 | (uint16_t)EC_HOST_CMD_INVALID_HEADER_VERSION); |
| 730 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_CRC == |
| 731 | (uint16_t)EC_HOST_CMD_INVALID_HEADER_CRC); |
| 732 | BUILD_ASSERT((uint16_t)EC_RES_INVALID_DATA_CRC == |
| 733 | (uint16_t)EC_HOST_CMD_INVALID_DATA_CRC); |
| 734 | BUILD_ASSERT((uint16_t)EC_RES_DUP_UNAVAILABLE == |
| 735 | (uint16_t)EC_HOST_CMD_DUP_UNAVAILABLE); |
| 736 | BUILD_ASSERT((uint16_t)EC_RES_MAX == (uint16_t)EC_HOST_CMD_MAX); |
| 737 | |
| 738 | #endif |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 739 | |
| 740 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 741 | * Host event codes. ACPI query EC command uses code 0 to mean "no event |
| 742 | * pending". We explicitly specify each value in the enum listing so they won't |
| 743 | * change if we delete/insert an item or rearrange the list (it needs to be |
| 744 | * stable across platforms, not just within a single compiled instance). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 745 | */ |
| 746 | enum host_event_code { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 747 | EC_HOST_EVENT_NONE = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 748 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 749 | EC_HOST_EVENT_LID_OPEN = 2, |
| 750 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 751 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 752 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 753 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 754 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 755 | EC_HOST_EVENT_BATTERY = 8, |
| 756 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 757 | /* Event generated by a device attached to the EC */ |
| 758 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 759 | EC_HOST_EVENT_THERMAL = 11, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 760 | /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */ |
| 761 | EC_HOST_EVENT_GPU = 12, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 762 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 763 | /* |
| 764 | * EC has finished initializing the host interface. The host can check |
| 765 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 766 | * determine when the EC is ready to accept subsequent commands. |
| 767 | */ |
| 768 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 769 | /* Keyboard recovery combo has been pressed */ |
| 770 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 771 | |
| 772 | /* Shutdown due to thermal overload */ |
| 773 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 774 | /* Shutdown due to battery level too low */ |
| 775 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 776 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 777 | /* Suggest that the AP throttle itself */ |
| 778 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 779 | /* Suggest that the AP resume normal speed */ |
| 780 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 781 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 782 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 783 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 784 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 785 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 786 | |
| 787 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 788 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 789 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 790 | /* Battery Status flags have changed */ |
| 791 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 792 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 793 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 794 | EC_HOST_EVENT_PANIC = 24, |
| 795 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 796 | /* Keyboard fastboot combo has been pressed */ |
| 797 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 798 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 799 | /* EC RTC event occurred */ |
| 800 | EC_HOST_EVENT_RTC = 26, |
| 801 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 802 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 803 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 804 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 805 | /* EC desires to change state of host-controlled USB mux */ |
| 806 | EC_HOST_EVENT_USB_MUX = 28, |
| 807 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 808 | /* |
| 809 | * The device has changed "modes". This can be one of the following: |
| 810 | * |
| 811 | * - TABLET/LAPTOP mode |
| 812 | * - detachable base attach/detach event |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 813 | * - on body/off body transition event |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 814 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 815 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 816 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 817 | /* Keyboard recovery combo with hardware reinitialization */ |
| 818 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 819 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 820 | /* WoV */ |
| 821 | EC_HOST_EVENT_WOV = 31, |
| 822 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 823 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 824 | * The high bit of the event mask is not used as a host event code. If |
| 825 | * it reads back as set, then the entire event mask should be |
| 826 | * considered invalid by the host. This can happen when reading the |
| 827 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 828 | * not initialized on the EC, or improperly configured on the host. |
| 829 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 830 | EC_HOST_EVENT_INVALID = 32, |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 831 | |
| 832 | /* Body detect (lap/desk) change event */ |
| 833 | EC_HOST_EVENT_BODY_DETECT_CHANGE = 33, |
| 834 | |
| 835 | /* |
| 836 | * Only 64 host events are supported. This enum uses 1-based counting so |
| 837 | * it can skip 0 (NONE), so the last legal host event number is 64. |
| 838 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 839 | }; |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 840 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 841 | /* Host event mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 842 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 843 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 844 | /* clang-format off */ |
| 845 | #define HOST_EVENT_TEXT \ |
| 846 | { \ |
| 847 | [EC_HOST_EVENT_NONE] = "NONE", \ |
| 848 | [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \ |
| 849 | [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \ |
| 850 | [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \ |
| 851 | [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \ |
| 852 | [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \ |
| 853 | [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \ |
| 854 | [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \ |
| 855 | [EC_HOST_EVENT_BATTERY] = "BATTERY", \ |
| 856 | [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \ |
| 857 | [EC_HOST_EVENT_DEVICE] = "DEVICE", \ |
| 858 | [EC_HOST_EVENT_THERMAL] = "THERMAL", \ |
| 859 | [EC_HOST_EVENT_GPU] = "GPU", \ |
| 860 | [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \ |
| 861 | [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \ |
| 862 | [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \ |
| 863 | [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \ |
| 864 | [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \ |
| 865 | [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \ |
| 866 | [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \ |
| 867 | [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \ |
| 868 | [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \ |
| 869 | [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \ |
| 870 | [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \ |
| 871 | [EC_HOST_EVENT_PANIC] = "PANIC", \ |
| 872 | [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \ |
| 873 | [EC_HOST_EVENT_RTC] = "RTC", \ |
| 874 | [EC_HOST_EVENT_MKBP] = "MKBP", \ |
| 875 | [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \ |
| 876 | [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \ |
| 877 | [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \ |
| 878 | "KEYBOARD_RECOVERY_HW_REINIT", \ |
| 879 | [EC_HOST_EVENT_WOV] = "WOV", \ |
| 880 | [EC_HOST_EVENT_INVALID] = "INVALID", \ |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 881 | [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 882 | } |
| 883 | /* clang-format on */ |
| 884 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 885 | /** |
| 886 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 887 | * @flags: The host argument flags. |
| 888 | * @command_version: Command version. |
| 889 | * @data_size: The length of data. |
| 890 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 891 | * all params/response data bytes. |
| 892 | */ |
| 893 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 894 | uint8_t flags; |
| 895 | uint8_t command_version; |
| 896 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 897 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 898 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 899 | |
| 900 | /* Flags for ec_lpc_host_args.flags */ |
| 901 | /* |
| 902 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 903 | * params. |
| 904 | * |
| 905 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 906 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 907 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 908 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 909 | */ |
| 910 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 911 | /* |
| 912 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 913 | * |
| 914 | * If EC responds to a command and this flag is not set, this is an old-style |
| 915 | * response. Command version is 0 and response data from EC is at |
| 916 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 917 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 918 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 919 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 920 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 921 | /* |
| 922 | * Byte codes returned by EC over SPI interface. |
| 923 | * |
| 924 | * These can be used by the AP to debug the EC interface, and to determine |
| 925 | * when the EC is not in a state where it will ever get around to responding |
| 926 | * to the AP. |
| 927 | * |
| 928 | * Example of sequence of bytes read from EC for a current good transfer: |
| 929 | * 1. - - AP asserts chip select (CS#) |
| 930 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 931 | * 3. - - EC starts handling CS# interrupt |
| 932 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 933 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 934 | * bytes looking for EC_SPI_FRAME_START |
| 935 | * 6. - - EC finishes processing and sets up response |
| 936 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 937 | * 8. (response packet) - AP reads response packet |
| 938 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 939 | * 10 - - AP deasserts chip select |
| 940 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 941 | * next request |
| 942 | * |
| 943 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 944 | * the following byte values: |
| 945 | * EC_SPI_OLD_READY |
| 946 | * EC_SPI_RX_READY |
| 947 | * EC_SPI_RECEIVING |
| 948 | * EC_SPI_PROCESSING |
| 949 | * |
| 950 | * Then the EC found an error in the request, or was not ready for the request |
| 951 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 952 | * because the EC is unable to tell when the AP is done sending its request. |
| 953 | */ |
| 954 | |
| 955 | /* |
| 956 | * Framing byte which precedes a response packet from the EC. After sending a |
| 957 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 958 | * clock in the response packet. |
| 959 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 960 | #define EC_SPI_FRAME_START 0xec |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 961 | |
| 962 | /* |
| 963 | * Padding bytes which are clocked out after the end of a response packet. |
| 964 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 965 | #define EC_SPI_PAST_END 0xed |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 966 | |
| 967 | /* |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 968 | * 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] | 969 | * that the AP will send a valid packet header (starting with |
| 970 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 971 | * |
| 972 | * NOTE: Some SPI configurations place the Most Significant Bit on SDO when |
| 973 | * CS goes low. This macro has the Most Significant Bit set to zero, |
| 974 | * so SDO will not be driven high when CS goes low. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 975 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 976 | #define EC_SPI_RX_READY 0x78 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 977 | |
| 978 | /* |
| 979 | * EC has started receiving the request from the AP, but hasn't started |
| 980 | * processing it yet. |
| 981 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 982 | #define EC_SPI_RECEIVING 0xf9 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 983 | |
| 984 | /* 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] | 985 | #define EC_SPI_PROCESSING 0xfa |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 986 | |
| 987 | /* |
| 988 | * EC received bad data from the AP, such as a packet header with an invalid |
| 989 | * length. EC will ignore all data until chip select deasserts. |
| 990 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 991 | #define EC_SPI_RX_BAD_DATA 0xfb |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 992 | |
| 993 | /* |
| 994 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 995 | * chip select and started clocking data before the EC was ready to receive it. |
| 996 | * EC will ignore all data until chip select deasserts. |
| 997 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 998 | #define EC_SPI_NOT_READY 0xfc |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 999 | |
| 1000 | /* |
| 1001 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 1002 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 1003 | * a fully received packet but is not ready to respond yet. |
| 1004 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1005 | #define EC_SPI_OLD_READY 0xfd |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1006 | |
| 1007 | /*****************************************************************************/ |
| 1008 | |
| 1009 | /* |
| 1010 | * Protocol version 2 for I2C and SPI send a request this way: |
| 1011 | * |
| 1012 | * 0 EC_CMD_VERSION0 + (command version) |
| 1013 | * 1 Command number |
| 1014 | * 2 Length of params = N |
| 1015 | * 3..N+2 Params, if any |
| 1016 | * N+3 8-bit checksum of bytes 0..N+2 |
| 1017 | * |
| 1018 | * The corresponding response is: |
| 1019 | * |
| 1020 | * 0 Result code (EC_RES_*) |
| 1021 | * 1 Length of params = M |
| 1022 | * 2..M+1 Params, if any |
| 1023 | * M+2 8-bit checksum of bytes 0..M+1 |
| 1024 | */ |
| 1025 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 1026 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1027 | #define EC_PROTO2_REQUEST_OVERHEAD \ |
| 1028 | (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1029 | |
| 1030 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 1031 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1032 | #define EC_PROTO2_RESPONSE_OVERHEAD \ |
| 1033 | (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1034 | |
| 1035 | /* Parameter length was limited by the LPC interface */ |
| 1036 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 1037 | |
| 1038 | /* Maximum request and response packet sizes for protocol version 2 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1039 | #define EC_PROTO2_MAX_REQUEST_SIZE \ |
| 1040 | (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE) |
| 1041 | #define EC_PROTO2_MAX_RESPONSE_SIZE \ |
| 1042 | (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1043 | |
| 1044 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1045 | |
| 1046 | /* |
| 1047 | * Value written to legacy command port / prefix byte to indicate protocol |
| 1048 | * 3+ structs are being used. Usage is bus-dependent. |
| 1049 | */ |
| 1050 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 1051 | |
| 1052 | #define EC_HOST_REQUEST_VERSION 3 |
| 1053 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1054 | /** |
| 1055 | * struct ec_host_request - Version 3 request from host. |
| 1056 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 1057 | * receives a header with a version it doesn't know how to |
| 1058 | * parse. |
| 1059 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 1060 | * should total to 0. |
| 1061 | * @command: Command to send (EC_CMD_...) |
| 1062 | * @command_version: Command version. |
| 1063 | * @reserved: Unused byte in current protocol version; set to 0. |
| 1064 | * @data_len: Length of data which follows this header. |
| 1065 | */ |
| 1066 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1067 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1068 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1069 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1070 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1071 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1072 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1073 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1074 | |
| 1075 | #define EC_HOST_RESPONSE_VERSION 3 |
| 1076 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1077 | /** |
| 1078 | * struct ec_host_response - Version 3 response from EC. |
| 1079 | * @struct_version: Struct version (=3). |
| 1080 | * @checksum: Checksum of response and data; sum of all bytes including |
| 1081 | * checksum should total to 0. |
| 1082 | * @result: EC's response to the command (separate from communication failure) |
| 1083 | * @data_len: Length of data which follows this header. |
| 1084 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 1085 | */ |
| 1086 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1087 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1088 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1089 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1090 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1091 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1092 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1093 | |
| 1094 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1095 | |
| 1096 | /* |
| 1097 | * Host command protocol V4. |
| 1098 | * |
| 1099 | * Packets always start with a request or response header. They are followed |
| 1100 | * 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] | 1101 | * 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] | 1102 | * polynomial. |
| 1103 | * |
| 1104 | * Host algorithm when sending a request q: |
| 1105 | * |
| 1106 | * 101) tries_left=(some value, e.g. 3); |
| 1107 | * 102) q.seq_num++ |
| 1108 | * 103) q.seq_dup=0 |
| 1109 | * 104) Calculate q.header_crc. |
| 1110 | * 105) Send request q to EC. |
| 1111 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 1112 | * |
| 1113 | * 201) If r.struct_version != 4, go to 301. |
| 1114 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 1115 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 1116 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 1117 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 1118 | * 207) If r.seq_dup == 1, go to 301. |
| 1119 | * 208) Return error. |
| 1120 | * |
| 1121 | * 301) If --tries_left <= 0, return error. |
| 1122 | * 302) If q.seq_dup == 1, go to 105. |
| 1123 | * 303) q.seq_dup = 1 |
| 1124 | * 304) Go to 104. |
| 1125 | * |
| 1126 | * EC algorithm when receiving a request q. |
| 1127 | * EC has response buffer r, error buffer e. |
| 1128 | * |
| 1129 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 1130 | * and go to 301 |
| 1131 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 1132 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 1133 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 1134 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 1135 | * and go to 301. |
| 1136 | * 104) If q.seq_dup == 0, go to 201. |
| 1137 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 1138 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 1139 | * |
| 1140 | * 201) Process request q into response r. |
| 1141 | * 202) r.seq_num = q.seq_num |
| 1142 | * 203) r.seq_dup = q.seq_dup |
| 1143 | * 204) Calculate r.header_crc |
| 1144 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 1145 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 1146 | * 206) Send response r. |
| 1147 | * |
| 1148 | * 301) e.seq_num = q.seq_num |
| 1149 | * 302) e.seq_dup = q.seq_dup |
| 1150 | * 303) Calculate e.header_crc. |
| 1151 | * 304) Send error response e. |
| 1152 | */ |
| 1153 | |
| 1154 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1155 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1156 | /* |
| 1157 | * bits 0-3: struct_version: Structure version (=4) |
| 1158 | * bit 4: is_response: Is response (=0) |
| 1159 | * bits 5-6: seq_num: Sequence number |
| 1160 | * bit 7: seq_dup: Sequence duplicate flag |
| 1161 | */ |
| 1162 | uint8_t fields0; |
| 1163 | |
| 1164 | /* |
| 1165 | * bits 0-4: command_version: Command version |
| 1166 | * bits 5-6: Reserved (set 0, ignore on read) |
| 1167 | * bit 7: data_crc_present: Is data CRC present after data |
| 1168 | */ |
| 1169 | uint8_t fields1; |
| 1170 | |
| 1171 | /* Command code (EC_CMD_*) */ |
| 1172 | uint16_t command; |
| 1173 | |
| 1174 | /* Length of data which follows this header (not including data CRC) */ |
| 1175 | uint16_t data_len; |
| 1176 | |
| 1177 | /* Reserved (set 0, ignore on read) */ |
| 1178 | uint8_t reserved; |
| 1179 | |
| 1180 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1181 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1182 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1183 | |
| 1184 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1185 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1186 | /* |
| 1187 | * bits 0-3: struct_version: Structure version (=4) |
| 1188 | * bit 4: is_response: Is response (=1) |
| 1189 | * bits 5-6: seq_num: Sequence number |
| 1190 | * bit 7: seq_dup: Sequence duplicate flag |
| 1191 | */ |
| 1192 | uint8_t fields0; |
| 1193 | |
| 1194 | /* |
| 1195 | * bits 0-6: Reserved (set 0, ignore on read) |
| 1196 | * bit 7: data_crc_present: Is data CRC present after data |
| 1197 | */ |
| 1198 | uint8_t fields1; |
| 1199 | |
| 1200 | /* Result code (EC_RES_*) */ |
| 1201 | uint16_t result; |
| 1202 | |
| 1203 | /* Length of data which follows this header (not including data CRC) */ |
| 1204 | uint16_t data_len; |
| 1205 | |
| 1206 | /* Reserved (set 0, ignore on read) */ |
| 1207 | uint8_t reserved; |
| 1208 | |
| 1209 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1210 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1211 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1212 | |
| 1213 | /* Fields in fields0 byte */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1214 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1215 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1216 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1217 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1218 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1219 | |
| 1220 | /* Fields in fields1 byte */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1221 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1222 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1223 | |
| 1224 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1225 | /* |
| 1226 | * Notes on commands: |
| 1227 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1228 | * 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] | 1229 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1230 | * specified, the command does not input or output data, respectively. |
| 1231 | * Parameter/response length is implicit in the structs. Some underlying |
| 1232 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1233 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1234 | * |
| 1235 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1236 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1237 | */ |
| 1238 | |
| 1239 | /*****************************************************************************/ |
| 1240 | /* General / test commands */ |
| 1241 | |
| 1242 | /* |
| 1243 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1244 | * changes. |
| 1245 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1246 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1247 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1248 | /** |
| 1249 | * struct ec_response_proto_version - Response to the proto version command. |
| 1250 | * @version: The protocol version. |
| 1251 | */ |
| 1252 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1253 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1254 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1255 | |
| 1256 | /* |
| 1257 | * Hello. This is a simple command to test the EC is responsive to |
| 1258 | * commands. |
| 1259 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1260 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1261 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1262 | /** |
| 1263 | * struct ec_params_hello - Parameters to the hello command. |
| 1264 | * @in_data: Pass anything here. |
| 1265 | */ |
| 1266 | struct ec_params_hello { |
| 1267 | uint32_t in_data; |
| 1268 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1269 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1270 | /** |
| 1271 | * struct ec_response_hello - Response to the hello command. |
| 1272 | * @out_data: Output will be in_data + 0x01020304. |
| 1273 | */ |
| 1274 | struct ec_response_hello { |
| 1275 | uint32_t out_data; |
| 1276 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1277 | |
| 1278 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1279 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1280 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1281 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1282 | EC_IMAGE_UNKNOWN = 0, |
| 1283 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1284 | EC_IMAGE_RW, |
| 1285 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1286 | EC_IMAGE_RO_B, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1287 | EC_IMAGE_RW_B, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1288 | }; |
| 1289 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1290 | /** |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1291 | * 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] | 1292 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1293 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1294 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1295 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1296 | */ |
| 1297 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1298 | char version_string_ro[32]; |
| 1299 | char version_string_rw[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1300 | char reserved[32]; /* Changed to cros_fwid_ro in version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1301 | uint32_t current_image; |
| 1302 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1303 | |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1304 | /** |
| 1305 | * struct ec_response_get_version_v1 - Response to the v1 get version command. |
| 1306 | * |
| 1307 | * ec_response_get_version_v1 is a strict superset of ec_response_get_version. |
| 1308 | * The v1 response changes the semantics of one field (reserved to cros_fwid_ro) |
| 1309 | * and adds one additional field (cros_fwid_rw). |
| 1310 | * |
| 1311 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1312 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1313 | * @cros_fwid_ro: Null-terminated RO CrOS FWID string. |
| 1314 | * @current_image: One of ec_image. |
| 1315 | * @cros_fwid_rw: Null-terminated RW CrOS FWID string. |
| 1316 | */ |
| 1317 | struct ec_response_get_version_v1 { |
| 1318 | char version_string_ro[32]; |
| 1319 | char version_string_rw[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1320 | 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] | 1321 | uint32_t current_image; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1322 | char cros_fwid_rw[32]; /* Added in version 1 */ |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1323 | } __ec_align4; |
| 1324 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 1325 | /* Read test - OBSOLETE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1326 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1327 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1328 | /* |
| 1329 | * Get build information |
| 1330 | * |
| 1331 | * Response is null-terminated string. |
| 1332 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1333 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1334 | |
| 1335 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1336 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1337 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1338 | /** |
| 1339 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1340 | * @vendor: Null-terminated string for chip vendor. |
| 1341 | * @name: Null-terminated string for chip name. |
| 1342 | * @revision: Null-terminated string for chip mask version. |
| 1343 | */ |
| 1344 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1345 | char vendor[32]; |
| 1346 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1347 | char revision[32]; |
| 1348 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1349 | |
| 1350 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1351 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1352 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1353 | /** |
| 1354 | * struct ec_response_board_version - Response to the board version command. |
| 1355 | * @board_version: A monotonously incrementing number. |
| 1356 | */ |
| 1357 | struct ec_response_board_version { |
| 1358 | uint16_t board_version; |
| 1359 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1360 | |
| 1361 | /* |
| 1362 | * Read memory-mapped data. |
| 1363 | * |
| 1364 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1365 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1366 | * |
| 1367 | * Response is params.size bytes of data. |
| 1368 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1369 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1370 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1371 | /** |
| 1372 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1373 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1374 | * @size: Size to read in bytes. |
| 1375 | */ |
| 1376 | struct ec_params_read_memmap { |
| 1377 | uint8_t offset; |
| 1378 | uint8_t size; |
| 1379 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1380 | |
| 1381 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1382 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1383 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1384 | /** |
| 1385 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1386 | * @cmd: Command to check. |
| 1387 | */ |
| 1388 | struct ec_params_get_cmd_versions { |
| 1389 | uint8_t cmd; |
| 1390 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1391 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1392 | /** |
| 1393 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1394 | * versions (v1) |
| 1395 | * @cmd: Command to check. |
| 1396 | */ |
| 1397 | struct ec_params_get_cmd_versions_v1 { |
| 1398 | uint16_t cmd; |
| 1399 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1400 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1401 | /** |
| 1402 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1403 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1404 | * a desired version. |
| 1405 | */ |
| 1406 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1407 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1408 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1409 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1410 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1411 | * 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] | 1412 | * on lpc since it has its own out-of-band busy indicator. |
| 1413 | * |
| 1414 | * lpc must read the status from the command register. Attempting this on |
| 1415 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1416 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1417 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1418 | |
| 1419 | /* Avoid using ec_status which is for return values */ |
| 1420 | enum ec_comms_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1421 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1422 | }; |
| 1423 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1424 | /** |
| 1425 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1426 | * command. |
| 1427 | * @flags: Mask of enum ec_comms_status. |
| 1428 | */ |
| 1429 | struct ec_response_get_comms_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1430 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1431 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1432 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1433 | /* Fake a variety of responses, purely for testing purposes. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1434 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1435 | |
| 1436 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1437 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1438 | uint32_t ec_result; |
| 1439 | uint32_t ret_len; |
| 1440 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1441 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1442 | |
| 1443 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1444 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1445 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1446 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1447 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1448 | /* Get protocol information */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1449 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1450 | |
| 1451 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1452 | /* 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] | 1453 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1454 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1455 | /** |
| 1456 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1457 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1458 | * version n). |
| 1459 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1460 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1461 | * @flags: see EC_PROTOCOL_INFO_* |
| 1462 | */ |
| 1463 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1464 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1465 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1466 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1467 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1468 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1469 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1470 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1471 | /*****************************************************************************/ |
| 1472 | /* Get/Set miscellaneous values */ |
| 1473 | |
| 1474 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1475 | #define EC_GSV_SET 0x80000000 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1476 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1477 | /* |
| 1478 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1479 | * meaning for an individual command. |
| 1480 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1481 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1482 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1483 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1484 | uint32_t flags; |
| 1485 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1486 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1487 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1488 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1489 | uint32_t flags; |
| 1490 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1491 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1492 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1493 | /* More than one command can use these structs to get/set parameters. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1494 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1495 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1496 | /*****************************************************************************/ |
| 1497 | /* List the features supported by the firmware */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1498 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1499 | |
| 1500 | /* Supported features */ |
| 1501 | enum ec_feature_code { |
| 1502 | /* |
| 1503 | * This image contains a limited set of features. Another image |
| 1504 | * in RW partition may support more features. |
| 1505 | */ |
| 1506 | EC_FEATURE_LIMITED = 0, |
| 1507 | /* |
| 1508 | * Commands for probing/reading/writing/erasing the flash in the |
| 1509 | * EC are present. |
| 1510 | */ |
| 1511 | EC_FEATURE_FLASH = 1, |
| 1512 | /* |
| 1513 | * Can control the fan speed directly. |
| 1514 | */ |
| 1515 | EC_FEATURE_PWM_FAN = 2, |
| 1516 | /* |
| 1517 | * Can control the intensity of the keyboard backlight. |
| 1518 | */ |
| 1519 | EC_FEATURE_PWM_KEYB = 3, |
| 1520 | /* |
| 1521 | * Support Google lightbar, introduced on Pixel. |
| 1522 | */ |
| 1523 | EC_FEATURE_LIGHTBAR = 4, |
| 1524 | /* Control of LEDs */ |
| 1525 | EC_FEATURE_LED = 5, |
| 1526 | /* Exposes an interface to control gyro and sensors. |
| 1527 | * The host goes through the EC to access these sensors. |
| 1528 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1529 | */ |
| 1530 | EC_FEATURE_MOTION_SENSE = 6, |
| 1531 | /* The keyboard is controlled by the EC */ |
| 1532 | EC_FEATURE_KEYB = 7, |
| 1533 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1534 | EC_FEATURE_PSTORE = 8, |
| 1535 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1536 | EC_FEATURE_PORT80 = 9, |
| 1537 | /* |
| 1538 | * Thermal management: include TMP specific commands. |
| 1539 | * Higher level than direct fan control. |
| 1540 | */ |
| 1541 | EC_FEATURE_THERMAL = 10, |
| 1542 | /* Can switch the screen backlight on/off */ |
| 1543 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1544 | /* Can switch the wifi module on/off */ |
| 1545 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1546 | /* Monitor host events, through for example SMI or SCI */ |
| 1547 | EC_FEATURE_HOST_EVENTS = 13, |
| 1548 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1549 | EC_FEATURE_GPIO = 14, |
| 1550 | /* The EC can send i2c messages to downstream devices. */ |
| 1551 | EC_FEATURE_I2C = 15, |
| 1552 | /* Command to control charger are included */ |
| 1553 | EC_FEATURE_CHARGER = 16, |
| 1554 | /* Simple battery support. */ |
| 1555 | EC_FEATURE_BATTERY = 17, |
| 1556 | /* |
| 1557 | * Support Smart battery protocol |
| 1558 | * (Common Smart Battery System Interface Specification) |
| 1559 | */ |
| 1560 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1561 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1562 | EC_FEATURE_HANG_DETECT = 19, |
| 1563 | /* Report power information, for pit only */ |
| 1564 | EC_FEATURE_PMU = 20, |
| 1565 | /* Another Cros EC device is present downstream of this one */ |
| 1566 | EC_FEATURE_SUB_MCU = 21, |
| 1567 | /* Support USB Power delivery (PD) commands */ |
| 1568 | EC_FEATURE_USB_PD = 22, |
| 1569 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1570 | EC_FEATURE_USB_MUX = 23, |
| 1571 | /* Motion Sensor code has an internal software FIFO */ |
| 1572 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1573 | /* Support temporary secure vstore */ |
| 1574 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1575 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1576 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1577 | /* EC has RTC feature that can be controlled by host commands */ |
| 1578 | EC_FEATURE_RTC = 27, |
| 1579 | /* The MCU exposes a Fingerprint sensor */ |
| 1580 | EC_FEATURE_FINGERPRINT = 28, |
| 1581 | /* The MCU exposes a Touchpad */ |
| 1582 | EC_FEATURE_TOUCHPAD = 29, |
| 1583 | /* The MCU has RWSIG task enabled */ |
| 1584 | EC_FEATURE_RWSIG = 30, |
| 1585 | /* EC has device events support */ |
| 1586 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1587 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1588 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1589 | /* EC supports 64-bit host events */ |
| 1590 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1591 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1592 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1593 | /* EC supports CEC commands */ |
| 1594 | EC_FEATURE_CEC = 35, |
| 1595 | /* EC supports tight sensor timestamping. */ |
| 1596 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1597 | /* |
| 1598 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1599 | * setting of threshold by host command using |
| 1600 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1601 | */ |
| 1602 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1603 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1604 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1605 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1606 | * be sent to RO to be precise. |
| 1607 | */ |
| 1608 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1609 | /* The MCU is a System Companion Processor (SCP). */ |
| 1610 | EC_FEATURE_SCP = 39, |
| 1611 | /* The MCU is an Integrated Sensor Hub */ |
| 1612 | EC_FEATURE_ISH = 40, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1613 | /* New TCPMv2 TYPEC_ prefaced commands supported */ |
| 1614 | EC_FEATURE_TYPEC_CMD = 41, |
| 1615 | /* |
| 1616 | * The EC will wait for direction from the AP to enter Type-C alternate |
| 1617 | * modes or USB4. |
| 1618 | */ |
| 1619 | EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, |
| 1620 | /* |
| 1621 | * The EC will wait for an acknowledge from the AP after setting the |
| 1622 | * mux. |
| 1623 | */ |
| 1624 | EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 1625 | /* |
| 1626 | * The EC supports entering and residing in S4. |
| 1627 | */ |
| 1628 | EC_FEATURE_S4_RESIDENCY = 44, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 1629 | /* |
| 1630 | * The EC supports the AP directing mux sets for the board. |
| 1631 | */ |
| 1632 | EC_FEATURE_TYPEC_AP_MUX_SET = 45, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1633 | /* |
| 1634 | * The EC supports the AP composing VDMs for us to send. |
| 1635 | */ |
| 1636 | EC_FEATURE_TYPEC_AP_VDM_SEND = 46, |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 1637 | /* |
| 1638 | * The EC supports system safe mode panic recovery. |
| 1639 | */ |
| 1640 | EC_FEATURE_SYSTEM_SAFE_MODE = 47, |
| 1641 | /* |
| 1642 | * The EC will reboot on runtime assertion failures. |
| 1643 | */ |
| 1644 | EC_FEATURE_ASSERT_REBOOTS = 48, |
| 1645 | /* |
| 1646 | * The EC image is built with tokenized logging enabled. |
| 1647 | */ |
| 1648 | EC_FEATURE_TOKENIZED_LOGGING = 49, |
| 1649 | /* |
| 1650 | * The EC supports triggering an STB dump. |
| 1651 | */ |
| 1652 | EC_FEATURE_AMD_STB_DUMP = 50, |
| 1653 | /* |
| 1654 | * The EC supports memory dump commands. |
| 1655 | */ |
| 1656 | EC_FEATURE_MEMORY_DUMP = 51, |
| 1657 | /* |
| 1658 | * The EC supports DP2.1 capability |
| 1659 | */ |
| 1660 | EC_FEATURE_TYPEC_DP2_1 = 52, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1661 | }; |
| 1662 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1663 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1664 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1665 | |
| 1666 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1667 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1668 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1669 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1670 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1671 | /* Get the board's SKU ID from EC */ |
| 1672 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1673 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1674 | /* Set SKU ID from AP */ |
| 1675 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1676 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1677 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1678 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1679 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1680 | |
| 1681 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1682 | /* Flash commands */ |
| 1683 | |
| 1684 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1685 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1686 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1687 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1688 | /** |
| 1689 | * struct ec_response_flash_info - Response to the flash info command. |
| 1690 | * @flash_size: Usable flash size in bytes. |
| 1691 | * @write_block_size: Write block size. Write offset and size must be a |
| 1692 | * multiple of this. |
| 1693 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1694 | * multiple of this. |
| 1695 | * @protect_block_size: Protection block size. Protection offset and size |
| 1696 | * must be a multiple of this. |
| 1697 | * |
| 1698 | * Version 0 returns these fields. |
| 1699 | */ |
| 1700 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1701 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1702 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1703 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1704 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1705 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1706 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1707 | /* |
| 1708 | * Flags for version 1+ flash info command |
| 1709 | * EC flash erases bits to 0 instead of 1. |
| 1710 | */ |
| 1711 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1712 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1713 | /* |
| 1714 | * 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] | 1715 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1716 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1717 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1718 | * chip functionality. |
| 1719 | */ |
| 1720 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1721 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1722 | /** |
| 1723 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1724 | * @flash_size: Usable flash size in bytes. |
| 1725 | * @write_block_size: Write block size. Write offset and size must be a |
| 1726 | * multiple of this. |
| 1727 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1728 | * multiple of this. |
| 1729 | * @protect_block_size: Protection block size. Protection offset and size |
| 1730 | * must be a multiple of this. |
| 1731 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1732 | * size is exactly this and offset is a multiple of this. |
| 1733 | * For example, an EC may have a write buffer which can do |
| 1734 | * half-page operations if data is aligned, and a slower |
| 1735 | * word-at-a-time write mode. |
| 1736 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1737 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1738 | * Version 1 returns the same initial fields as version 0, with additional |
| 1739 | * fields following. |
| 1740 | * |
| 1741 | * 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] | 1742 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1743 | * one. |
| 1744 | * |
| 1745 | * Version 2 supports flash banks of different sizes: |
| 1746 | * The caller specified the number of banks it has preallocated |
| 1747 | * (num_banks_desc) |
| 1748 | * The EC returns the number of banks describing the flash memory. |
| 1749 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1750 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1751 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1752 | /* Version 0 fields; see above for description */ |
| 1753 | uint32_t flash_size; |
| 1754 | uint32_t write_block_size; |
| 1755 | uint32_t erase_block_size; |
| 1756 | uint32_t protect_block_size; |
| 1757 | |
| 1758 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1759 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1760 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1761 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1762 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1763 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1764 | /* Number of banks to describe */ |
| 1765 | uint16_t num_banks_desc; |
| 1766 | /* Reserved; set 0; ignore on read */ |
| 1767 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1768 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1769 | |
| 1770 | struct ec_flash_bank { |
| 1771 | /* Number of sector is in this bank. */ |
| 1772 | uint16_t count; |
| 1773 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1774 | uint8_t size_exp; |
| 1775 | /* Minimal write size for the sectors in this bank */ |
| 1776 | uint8_t write_size_exp; |
| 1777 | /* Erase size for the sectors in this bank */ |
| 1778 | uint8_t erase_size_exp; |
| 1779 | /* Size for write protection, usually identical to erase size. */ |
| 1780 | uint8_t protect_size_exp; |
| 1781 | /* Reserved; set 0; ignore on read */ |
| 1782 | uint8_t reserved[2]; |
| 1783 | }; |
| 1784 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1785 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1786 | /* Total flash in the EC. */ |
| 1787 | uint32_t flash_size; |
| 1788 | /* Flags; see EC_FLASH_INFO_* */ |
| 1789 | uint32_t flags; |
| 1790 | /* Maximum size to use to send data to write to the EC. */ |
| 1791 | uint32_t write_ideal_size; |
| 1792 | /* Number of banks present in the EC. */ |
| 1793 | uint16_t num_banks_total; |
| 1794 | /* Number of banks described in banks array. */ |
| 1795 | uint16_t num_banks_desc; |
| 1796 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1797 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1798 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1799 | /* |
| 1800 | * Read flash |
| 1801 | * |
| 1802 | * Response is params.size bytes of data. |
| 1803 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1804 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1805 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1806 | /** |
| 1807 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1808 | * @offset: Byte offset to read. |
| 1809 | * @size: Size to read in bytes. |
| 1810 | */ |
| 1811 | struct ec_params_flash_read { |
| 1812 | uint32_t offset; |
| 1813 | uint32_t size; |
| 1814 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1815 | |
| 1816 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1817 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1818 | #define EC_VER_FLASH_WRITE 1 |
| 1819 | |
| 1820 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1821 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1822 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1823 | /** |
| 1824 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1825 | * @offset: Byte offset to write. |
| 1826 | * @size: Size to write in bytes. |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1827 | * @data: Data to write. |
| 1828 | * @data.words32: uint32_t data to write. |
| 1829 | * @data.bytes: uint8_t data to write. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1830 | */ |
| 1831 | struct ec_params_flash_write { |
| 1832 | uint32_t offset; |
| 1833 | uint32_t size; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1834 | /* Followed by data to write. This union allows accessing an |
| 1835 | * underlying buffer as uint32s or uint8s for convenience. |
| 1836 | */ |
| 1837 | union { |
| 1838 | uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1839 | uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1840 | } data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1841 | } __ec_align4; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 1842 | BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1843 | |
| 1844 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1845 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1846 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1847 | /** |
| 1848 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1849 | * @offset: Byte offset to erase. |
| 1850 | * @size: Size to erase in bytes. |
| 1851 | */ |
| 1852 | struct ec_params_flash_erase { |
| 1853 | uint32_t offset; |
| 1854 | uint32_t size; |
| 1855 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1856 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1857 | /* |
| 1858 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1859 | * subcommands can returns: |
| 1860 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1861 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1862 | * EC_RES_ERROR : other errors. |
| 1863 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1864 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1865 | * |
| 1866 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1867 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1868 | * the proper result. |
| 1869 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1870 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1871 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1872 | * permitted while erasing. (For instance, STM32F4). |
| 1873 | */ |
| 1874 | enum ec_flash_erase_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1875 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1876 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1877 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1878 | }; |
| 1879 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1880 | /** |
| 1881 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1882 | * @cmd: One of ec_flash_erase_cmd. |
| 1883 | * @reserved: Pad byte; currently always contains 0. |
| 1884 | * @flag: No flags defined yet; set to 0. |
| 1885 | * @params: Same as v0 parameters. |
| 1886 | */ |
| 1887 | struct ec_params_flash_erase_v1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1888 | uint8_t cmd; |
| 1889 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1890 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1891 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1892 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1893 | |
| 1894 | /* |
| 1895 | * Get/set flash protection. |
| 1896 | * |
| 1897 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1898 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1899 | * some flags require a subsequent hard reset to take effect. Check the |
| 1900 | * returned flags bits to see what actually happened. |
| 1901 | * |
| 1902 | * If mask=0, simply returns the current flags state. |
| 1903 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1904 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1905 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1906 | |
| 1907 | /* Flags for flash protection */ |
| 1908 | /* RO flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1909 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1910 | /* |
| 1911 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1912 | * be changed. |
| 1913 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1914 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1915 | /* Entire flash code protected now, until reboot. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1916 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1917 | /* Flash write protect GPIO is asserted now */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1918 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1919 | /* 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] | 1920 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1921 | /* |
| 1922 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1923 | * flash which should be protected is not protected. Usually fixed by |
| 1924 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1925 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1926 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1927 | /* Entire flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1928 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1929 | /* RW flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1930 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1931 | /* RW flash code protected now. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1932 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1933 | /* Rollback information flash region protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1934 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1935 | /* Rollback information flash region protected now */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1936 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 1937 | /* Error - Unknown error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1938 | #define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1939 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1940 | /** |
| 1941 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1942 | * @mask: Bits in flags to apply. |
| 1943 | * @flags: New flags to apply. |
| 1944 | */ |
| 1945 | struct ec_params_flash_protect { |
| 1946 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1947 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1948 | } __ec_align4; |
| 1949 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 1950 | enum flash_protect_action { |
| 1951 | FLASH_PROTECT_ASYNC = 0, |
| 1952 | FLASH_PROTECT_GET_RESULT = 1, |
| 1953 | }; |
| 1954 | |
| 1955 | /* Version 2 of the command is "asynchronous". */ |
| 1956 | struct ec_params_flash_protect_v2 { |
| 1957 | uint8_t action; /**< enum flash_protect_action */ |
| 1958 | uint8_t reserved[3]; /**< padding for alignment */ |
| 1959 | uint32_t mask; |
| 1960 | uint32_t flags; |
| 1961 | } __ec_align4; |
| 1962 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1963 | /** |
| 1964 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1965 | * @flags: Current value of flash protect flags. |
| 1966 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1967 | * caller to distinguish between flags which aren't set vs. flags |
| 1968 | * which can't be set on this platform. |
| 1969 | * @writable_flags: Flags which can be changed given the current protection |
| 1970 | * state. |
| 1971 | */ |
| 1972 | struct ec_response_flash_protect { |
| 1973 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1974 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1975 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1976 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1977 | |
| 1978 | /* |
| 1979 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1980 | * write protect. These commands may be reused with version > 0. |
| 1981 | */ |
| 1982 | |
| 1983 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1984 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1985 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1986 | |
| 1987 | enum ec_flash_region { |
| 1988 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1989 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1990 | /* |
| 1991 | * Region which holds active RW image. 'Active' is different from |
| 1992 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1993 | * scheduled to run, active/non-active applies only to RW images (for |
| 1994 | * the same reason 'update' applies only to RW images. It's a state of |
| 1995 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1996 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1997 | * doesn't enter 'running' state but it's still active on a flash. |
| 1998 | */ |
| 1999 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2000 | /* |
| 2001 | * Region which should be write-protected in the factory (a superset of |
| 2002 | * EC_FLASH_REGION_RO) |
| 2003 | */ |
| 2004 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2005 | /* Region which holds updatable (non-active) RW image */ |
| 2006 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2007 | /* Number of regions */ |
| 2008 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2009 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2010 | /* |
| 2011 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2012 | * so the old constant is deprecated. |
| 2013 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2014 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2015 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2016 | /** |
| 2017 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 2018 | * command. |
| 2019 | * @region: Flash region; see EC_FLASH_REGION_* |
| 2020 | */ |
| 2021 | struct ec_params_flash_region_info { |
| 2022 | uint32_t region; |
| 2023 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2024 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2025 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2026 | uint32_t offset; |
| 2027 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2028 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2029 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2030 | /* Get SPI flash information */ |
| 2031 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 2032 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2033 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2034 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 2035 | uint8_t jedec[3]; |
| 2036 | |
| 2037 | /* Pad byte; currently always contains 0 */ |
| 2038 | uint8_t reserved0; |
| 2039 | |
| 2040 | /* Manufacturer / device ID from command 0x90 */ |
| 2041 | uint8_t mfr_dev_id[2]; |
| 2042 | |
| 2043 | /* Status registers from command 0x05 and 0x35 */ |
| 2044 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2045 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2046 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 2047 | /* Select flash during flash operations */ |
| 2048 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 2049 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2050 | /** |
| 2051 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 2052 | * @select: 1 to select flash, 0 to deselect flash |
| 2053 | */ |
| 2054 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 2055 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2056 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 2057 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2058 | /** |
| 2059 | * Request random numbers to be generated and returned. |
| 2060 | * Can be used to test the random number generator is truly random. |
| 2061 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 2062 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 2063 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2064 | #define EC_CMD_RAND_NUM 0x001A |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2065 | #define EC_VER_RAND_NUM 0 |
| 2066 | |
| 2067 | struct ec_params_rand_num { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2068 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2069 | } __ec_align4; |
| 2070 | |
| 2071 | struct ec_response_rand_num { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2072 | /** |
| 2073 | * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true |
| 2074 | * size of rand is determined by ec_params_rand_num's num_rand_bytes. |
| 2075 | */ |
| 2076 | uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 2077 | } __ec_align1; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2078 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 2079 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2080 | /** |
| 2081 | * Get information about the key used to sign the RW firmware. |
| 2082 | * For more details on the fields, see "struct vb21_packed_key". |
| 2083 | */ |
| 2084 | #define EC_CMD_RWSIG_INFO 0x001B |
| 2085 | #define EC_VER_RWSIG_INFO 0 |
| 2086 | |
| 2087 | #define VBOOT2_KEY_ID_BYTES 20 |
| 2088 | |
| 2089 | #ifdef CHROMIUM_EC |
| 2090 | /* Don't force external projects to depend on the vboot headers. */ |
| 2091 | #include "vb21_struct.h" |
| 2092 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 2093 | #endif |
| 2094 | |
| 2095 | struct ec_response_rwsig_info { |
| 2096 | /** |
| 2097 | * Signature algorithm used by the key |
| 2098 | * (enum vb2_signature_algorithm). |
| 2099 | */ |
| 2100 | uint16_t sig_alg; |
| 2101 | |
| 2102 | /** |
| 2103 | * Hash digest algorithm used with the key |
| 2104 | * (enum vb2_hash_algorithm). |
| 2105 | */ |
| 2106 | uint16_t hash_alg; |
| 2107 | |
| 2108 | /** Key version. */ |
| 2109 | uint32_t key_version; |
| 2110 | |
| 2111 | /** Key ID (struct vb2_id). */ |
| 2112 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 2113 | |
| 2114 | uint8_t key_is_valid; |
| 2115 | |
| 2116 | /** Alignment padding. */ |
| 2117 | uint8_t reserved[3]; |
| 2118 | } __ec_align4; |
| 2119 | |
| 2120 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 2121 | |
| 2122 | /** |
| 2123 | * Get information about the system, such as reset flags, locked state, etc. |
| 2124 | */ |
| 2125 | #define EC_CMD_SYSINFO 0x001C |
| 2126 | #define EC_VER_SYSINFO 0 |
| 2127 | |
| 2128 | enum sysinfo_flags { |
| 2129 | SYSTEM_IS_LOCKED = BIT(0), |
| 2130 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 2131 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 2132 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2133 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4), |
| 2134 | /* |
| 2135 | * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is |
| 2136 | * set and cleared when the system shuts down (not when the host event |
| 2137 | * flag is cleared). |
| 2138 | */ |
| 2139 | SYSTEM_IN_MANUAL_RECOVERY = BIT(5), |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2140 | }; |
| 2141 | |
| 2142 | struct ec_response_sysinfo { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2143 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2144 | uint32_t current_image; /**< enum ec_image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2145 | uint32_t flags; /**< enum sysinfo_flags */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2146 | } __ec_align4; |
| 2147 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2148 | /*****************************************************************************/ |
| 2149 | /* PWM commands */ |
| 2150 | |
| 2151 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2152 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2153 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2154 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2155 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2156 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2157 | |
| 2158 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2159 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2160 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2161 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2162 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2163 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2164 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2165 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2166 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2167 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2168 | uint32_t rpm; |
| 2169 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2170 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2171 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2172 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2173 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2174 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2175 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2176 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2177 | uint8_t percent; |
| 2178 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2179 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2180 | |
| 2181 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2182 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2183 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2184 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2185 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2186 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2187 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2188 | |
| 2189 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2190 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2191 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2192 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2193 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2194 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2195 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2196 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2197 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2198 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2199 | uint32_t percent; |
| 2200 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2201 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2202 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2203 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2204 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 2205 | #define EC_PWM_MAX_DUTY 0xffff |
| 2206 | |
| 2207 | enum ec_pwm_type { |
| 2208 | /* All types, indexed by board-specific enum pwm_channel */ |
| 2209 | EC_PWM_TYPE_GENERIC = 0, |
| 2210 | /* Keyboard backlight */ |
| 2211 | EC_PWM_TYPE_KB_LIGHT, |
| 2212 | /* Display backlight */ |
| 2213 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 2214 | EC_PWM_TYPE_COUNT, |
| 2215 | }; |
| 2216 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2217 | struct ec_params_pwm_set_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2218 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 2219 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2220 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2221 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2222 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2223 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2224 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2225 | struct ec_params_pwm_get_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2226 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2227 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2228 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2229 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2230 | struct ec_response_pwm_get_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2231 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2232 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2233 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2234 | /*****************************************************************************/ |
| 2235 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2236 | * 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] | 2237 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 2238 | * into a subcommand. We'll make separate structs for subcommands with |
| 2239 | * different input args, so that we know how much to expect. |
| 2240 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2241 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2242 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2243 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2244 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2245 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2246 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2247 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2248 | |
| 2249 | /* |
| 2250 | * 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] | 2251 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2252 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2253 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2254 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2255 | int32_t google_ramp_up; |
| 2256 | int32_t google_ramp_down; |
| 2257 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2258 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2259 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2260 | int32_t s0s3_ramp_down; |
| 2261 | int32_t s3_sleep_for; |
| 2262 | int32_t s3_ramp_up; |
| 2263 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2264 | |
| 2265 | /* Oscillation */ |
| 2266 | uint8_t new_s0; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2267 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2268 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2269 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2270 | |
| 2271 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2272 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2273 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2274 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2275 | |
| 2276 | /* Battery level thresholds */ |
| 2277 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2278 | |
| 2279 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2280 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2281 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2282 | |
| 2283 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2284 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2285 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2286 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2287 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2288 | /* Timing */ |
| 2289 | int32_t google_ramp_up; |
| 2290 | int32_t google_ramp_down; |
| 2291 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2292 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2293 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2294 | int32_t s0s3_ramp_down; |
| 2295 | int32_t s3_sleep_for; |
| 2296 | int32_t s3_ramp_up; |
| 2297 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2298 | int32_t s5_ramp_up; |
| 2299 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2300 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2301 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2302 | int32_t tap_display_time; |
| 2303 | |
| 2304 | /* Tap-for-battery params */ |
| 2305 | uint8_t tap_pct_red; |
| 2306 | uint8_t tap_pct_green; |
| 2307 | uint8_t tap_seg_min_on; |
| 2308 | uint8_t tap_seg_max_on; |
| 2309 | uint8_t tap_seg_osc; |
| 2310 | uint8_t tap_idx[3]; |
| 2311 | |
| 2312 | /* Oscillation */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2313 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2314 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2315 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2316 | |
| 2317 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2318 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2319 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2320 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2321 | |
| 2322 | /* Battery level thresholds */ |
| 2323 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2324 | |
| 2325 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2326 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2327 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2328 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2329 | /* s5: single color pulse on inhibited power-up */ |
| 2330 | uint8_t s5_idx; |
| 2331 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2332 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2333 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2334 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2335 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2336 | /* Lightbar command params v2 |
| 2337 | * crbug.com/467716 |
| 2338 | * |
| 2339 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2340 | * logical groups to make it more manageable ( < 120 bytes). |
| 2341 | * |
| 2342 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2343 | */ |
| 2344 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2345 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2346 | /* Timing */ |
| 2347 | int32_t google_ramp_up; |
| 2348 | int32_t google_ramp_down; |
| 2349 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2350 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2351 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2352 | int32_t s0s3_ramp_down; |
| 2353 | int32_t s3_sleep_for; |
| 2354 | int32_t s3_ramp_up; |
| 2355 | int32_t s3_ramp_down; |
| 2356 | int32_t s5_ramp_up; |
| 2357 | int32_t s5_ramp_down; |
| 2358 | int32_t tap_tick_delay; |
| 2359 | int32_t tap_gate_delay; |
| 2360 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2361 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2362 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2363 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2364 | /* Tap-for-battery params */ |
| 2365 | uint8_t tap_pct_red; |
| 2366 | uint8_t tap_pct_green; |
| 2367 | uint8_t tap_seg_min_on; |
| 2368 | uint8_t tap_seg_max_on; |
| 2369 | uint8_t tap_seg_osc; |
| 2370 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2371 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2372 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2373 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2374 | /* Oscillation */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2375 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2376 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2377 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2378 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2379 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2380 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2381 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2382 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2383 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2384 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2385 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2386 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2387 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2388 | /* Battery level thresholds */ |
| 2389 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2390 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2391 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2392 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2393 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2394 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2395 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2396 | |
| 2397 | /* s5: single color pulse on inhibited power-up */ |
| 2398 | uint8_t s5_idx; |
| 2399 | |
| 2400 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2401 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2402 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2403 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2404 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2405 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2406 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2407 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2408 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2409 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2410 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2411 | struct ec_params_lightbar { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2412 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2413 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2414 | /* |
| 2415 | * The following commands have no args: |
| 2416 | * |
| 2417 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2418 | * version, get_brightness, get_demo, suspend, resume, |
| 2419 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2420 | * get_params_v2_bright, get_params_v2_thlds, |
| 2421 | * get_params_v2_colors |
| 2422 | * |
| 2423 | * Don't use an empty struct, because C++ hates that. |
| 2424 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2425 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2426 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2427 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2428 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2429 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2430 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2431 | uint8_t ctrl, reg, value; |
| 2432 | } reg; |
| 2433 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2434 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2435 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2436 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2437 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2438 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2439 | uint8_t led; |
| 2440 | } get_rgb; |
| 2441 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2442 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2443 | uint8_t enable; |
| 2444 | } manual_suspend_ctrl; |
| 2445 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2446 | struct lightbar_params_v0 set_params_v0; |
| 2447 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2448 | |
| 2449 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2450 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2451 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2452 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2453 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2454 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2455 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2456 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2457 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2458 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2459 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2460 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2461 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2462 | struct __ec_todo_unpacked { |
| 2463 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2464 | uint8_t reg; |
| 2465 | uint8_t ic0; |
| 2466 | uint8_t ic1; |
| 2467 | } vals[23]; |
| 2468 | } dump; |
| 2469 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2470 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2471 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2472 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2473 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2474 | struct lightbar_params_v0 get_params_v0; |
| 2475 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2476 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2477 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2478 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2479 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2480 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2481 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2482 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2483 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2484 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2485 | uint32_t num; |
| 2486 | uint32_t flags; |
| 2487 | } version; |
| 2488 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2489 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2490 | uint8_t red, green, blue; |
| 2491 | } get_rgb; |
| 2492 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2493 | /* |
| 2494 | * The following commands have no response: |
| 2495 | * |
| 2496 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2497 | * set_params_v0, set_params_v1, set_program, |
| 2498 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2499 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2500 | * set_v2par_thlds, set_v2par_colors |
| 2501 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2502 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2503 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2504 | |
| 2505 | /* Lightbar commands */ |
| 2506 | enum lightbar_command { |
| 2507 | LIGHTBAR_CMD_DUMP = 0, |
| 2508 | LIGHTBAR_CMD_OFF = 1, |
| 2509 | LIGHTBAR_CMD_ON = 2, |
| 2510 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2511 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2512 | LIGHTBAR_CMD_SEQ = 5, |
| 2513 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2514 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2515 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2516 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2517 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2518 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2519 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2520 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2521 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2522 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2523 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2524 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2525 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2526 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2527 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2528 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2529 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2530 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2531 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2532 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2533 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2534 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2535 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2536 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2537 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2538 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2539 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2540 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2541 | LIGHTBAR_NUM_CMDS, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2542 | }; |
| 2543 | |
| 2544 | /*****************************************************************************/ |
| 2545 | /* LED control commands */ |
| 2546 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2547 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2548 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2549 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2550 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2551 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2552 | /* |
| 2553 | * LED to indicate system power state (on or in suspend). |
| 2554 | * May be on power button or on C-panel. |
| 2555 | */ |
| 2556 | EC_LED_ID_POWER_LED, |
| 2557 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2558 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2559 | /* LED to indicate left side */ |
| 2560 | EC_LED_ID_LEFT_LED, |
| 2561 | /* LED to indicate right side */ |
| 2562 | EC_LED_ID_RIGHT_LED, |
| 2563 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2564 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2565 | /* LED to indicate sysrq debug mode. */ |
| 2566 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2567 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2568 | EC_LED_ID_COUNT, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2569 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2570 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2571 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2572 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2573 | #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] | 2574 | |
| 2575 | enum ec_led_colors { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2576 | EC_LED_COLOR_INVALID = -1, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2577 | EC_LED_COLOR_RED = 0, |
| 2578 | EC_LED_COLOR_GREEN, |
| 2579 | EC_LED_COLOR_BLUE, |
| 2580 | EC_LED_COLOR_YELLOW, |
| 2581 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2582 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2583 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2584 | EC_LED_COLOR_COUNT, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2585 | }; |
| 2586 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2587 | struct ec_params_led_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2588 | uint8_t led_id; /* Which LED to control */ |
| 2589 | uint8_t flags; /* Control flags */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2590 | |
| 2591 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2592 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2593 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2594 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2595 | /* |
| 2596 | * Available brightness value range. |
| 2597 | * |
| 2598 | * Range 0 means color channel not present. |
| 2599 | * Range 1 means on/off control. |
| 2600 | * Other values means the LED is control by PWM. |
| 2601 | */ |
| 2602 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2603 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2604 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2605 | /*****************************************************************************/ |
| 2606 | /* Verified boot commands */ |
| 2607 | |
| 2608 | /* |
| 2609 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2610 | * reused for other purposes with version > 0. |
| 2611 | */ |
| 2612 | |
| 2613 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2614 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2615 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2616 | struct ec_params_vboot_hash { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2617 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2618 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2619 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2620 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2621 | uint32_t offset; /* Offset in flash to hash */ |
| 2622 | uint32_t size; /* Number of bytes to hash */ |
| 2623 | 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] | 2624 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2625 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2626 | struct ec_response_vboot_hash { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2627 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2628 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2629 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2630 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2631 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2632 | uint32_t size; /* Number of bytes hashed */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2633 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2634 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2635 | |
| 2636 | enum ec_vboot_hash_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2637 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2638 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2639 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2640 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2641 | }; |
| 2642 | |
| 2643 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2644 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2645 | }; |
| 2646 | |
| 2647 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2648 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2649 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2650 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2651 | }; |
| 2652 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2653 | /* |
| 2654 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2655 | * If one of these is specified, the EC will automatically update offset and |
| 2656 | * size to the correct values for the specified image (RO or RW). |
| 2657 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2658 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2659 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2660 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2661 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2662 | /* |
| 2663 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2664 | * so the old constant is deprecated. |
| 2665 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2666 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2667 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2668 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2669 | /* |
| 2670 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2671 | * different input args, so that we know how much to expect. |
| 2672 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2673 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2674 | |
| 2675 | /* Motion sense commands */ |
| 2676 | enum motionsense_command { |
| 2677 | /* |
| 2678 | * Dump command returns all motion sensor data including motion sense |
| 2679 | * module flags and individual sensor flags. |
| 2680 | */ |
| 2681 | MOTIONSENSE_CMD_DUMP = 0, |
| 2682 | |
| 2683 | /* |
| 2684 | * Info command returns data describing the details of a given sensor, |
| 2685 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2686 | * enum motionsensor_chip. |
| 2687 | */ |
| 2688 | MOTIONSENSE_CMD_INFO = 1, |
| 2689 | |
| 2690 | /* |
| 2691 | * 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] | 2692 | * in milliseconds. |
| 2693 | * It is per sensor, the EC run sample task at the minimum of all |
| 2694 | * sensors EC_RATE. |
| 2695 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2696 | * to collect all the sensor samples. |
| 2697 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2698 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2699 | */ |
| 2700 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2701 | |
| 2702 | /* |
| 2703 | * Sensor ODR command is a setter/getter command for the output data |
| 2704 | * rate of a specific motion sensor in millihertz. |
| 2705 | */ |
| 2706 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2707 | |
| 2708 | /* |
| 2709 | * Sensor range command is a setter/getter command for the range of |
| 2710 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2711 | */ |
| 2712 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2713 | |
| 2714 | /* |
| 2715 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2716 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2717 | * and when the lid angle goes less than this value, keyboard wake is |
| 2718 | * enabled. Note, the lid angle measurement is an approximate, |
| 2719 | * un-calibrated value, hence the wake angle isn't exact. |
| 2720 | */ |
| 2721 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2722 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2723 | /* |
| 2724 | * Returns a single sensor data. |
| 2725 | */ |
| 2726 | MOTIONSENSE_CMD_DATA = 6, |
| 2727 | |
| 2728 | /* |
| 2729 | * Return sensor fifo info. |
| 2730 | */ |
| 2731 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2732 | |
| 2733 | /* |
| 2734 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2735 | * The host can use that element to synchronize its operation. |
| 2736 | */ |
| 2737 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2738 | |
| 2739 | /* |
| 2740 | * Return a portion of the fifo. |
| 2741 | */ |
| 2742 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2743 | |
| 2744 | /* |
| 2745 | * Perform low level calibration. |
| 2746 | * On sensors that support it, ask to do offset calibration. |
| 2747 | */ |
| 2748 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2749 | |
| 2750 | /* |
| 2751 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2752 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2753 | * The offsets can be calculated by the host, or via |
| 2754 | * PERFORM_CALIB command. |
| 2755 | */ |
| 2756 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2757 | |
| 2758 | /* |
| 2759 | * List available activities for a MOTION sensor. |
| 2760 | * Indicates if they are enabled or disabled. |
| 2761 | */ |
| 2762 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2763 | |
| 2764 | /* |
| 2765 | * Activity management |
| 2766 | * Enable/Disable activity recognition. |
| 2767 | */ |
| 2768 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2769 | |
| 2770 | /* |
| 2771 | * Lid Angle |
| 2772 | */ |
| 2773 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2774 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2775 | /* |
| 2776 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2777 | * By default the FIFO does not send interrupt to process the FIFO |
| 2778 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2779 | */ |
| 2780 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2781 | |
| 2782 | /* |
| 2783 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2784 | * to arbitrary values, or will lock to the last read actual values. |
| 2785 | */ |
| 2786 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2787 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2788 | /* Set lid angle for tablet mode detection. */ |
| 2789 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2790 | |
| 2791 | /* |
| 2792 | * Sensor Scale command is a setter/getter command for the calibration |
| 2793 | * scale. |
| 2794 | */ |
| 2795 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2796 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2797 | /* |
| 2798 | * Read the current online calibration values (if available). |
| 2799 | */ |
| 2800 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2801 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2802 | /* |
| 2803 | * Activity management |
| 2804 | * Retrieve current status of given activity. |
| 2805 | */ |
| 2806 | MOTIONSENSE_CMD_GET_ACTIVITY = 20, |
| 2807 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2808 | /* Number of motionsense sub-commands. */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2809 | MOTIONSENSE_NUM_CMDS, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2810 | }; |
| 2811 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2812 | /* List of motion sensor types. */ |
| 2813 | enum motionsensor_type { |
| 2814 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2815 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2816 | MOTIONSENSE_TYPE_MAG = 2, |
| 2817 | MOTIONSENSE_TYPE_PROX = 3, |
| 2818 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2819 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2820 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2821 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2822 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2823 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2824 | }; |
| 2825 | |
| 2826 | /* List of motion sensor locations. */ |
| 2827 | enum motionsensor_location { |
| 2828 | MOTIONSENSE_LOC_BASE = 0, |
| 2829 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2830 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2831 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2832 | }; |
| 2833 | |
| 2834 | /* List of motion sensor chips. */ |
| 2835 | enum motionsensor_chip { |
| 2836 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2837 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2838 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2839 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2840 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2841 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2842 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2843 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2844 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2845 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2846 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2847 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2848 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2849 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2850 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2851 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2852 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2853 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2854 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2855 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2856 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2857 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2858 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2859 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2860 | MOTIONSENSE_CHIP_BMI260 = 24, |
| 2861 | MOTIONSENSE_CHIP_ICM426XX = 25, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2862 | MOTIONSENSE_CHIP_ICM42607 = 26, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2863 | MOTIONSENSE_CHIP_BMA422 = 27, |
| 2864 | MOTIONSENSE_CHIP_BMI323 = 28, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 2865 | MOTIONSENSE_CHIP_BMI220 = 29, |
| 2866 | MOTIONSENSE_CHIP_CM32183 = 30, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2867 | MOTIONSENSE_CHIP_MAX, |
| 2868 | }; |
| 2869 | |
| 2870 | /* List of orientation positions */ |
| 2871 | enum motionsensor_orientation { |
| 2872 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2873 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2874 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2875 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2876 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2877 | }; |
| 2878 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2879 | struct ec_response_activity_data { |
| 2880 | uint8_t activity; /* motionsensor_activity */ |
| 2881 | uint8_t state; |
| 2882 | } __ec_todo_packed; |
| 2883 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2884 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2885 | /* Flags for each sensor. */ |
| 2886 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2887 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2888 | uint8_t sensor_num; |
| 2889 | /* Each sensor is up to 3-axis. */ |
| 2890 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2891 | int16_t data[3]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2892 | /* for sensors using unsigned data */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2893 | uint16_t udata[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2894 | struct __ec_todo_packed { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2895 | uint16_t reserved; |
| 2896 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2897 | }; |
| 2898 | struct __ec_todo_unpacked { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2899 | struct ec_response_activity_data activity_data; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2900 | int16_t add_info[2]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2901 | }; |
| 2902 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2903 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2904 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2905 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2906 | struct ec_response_online_calibration_data { |
| 2907 | /** The calibration values. */ |
| 2908 | int16_t data[3]; |
| 2909 | }; |
| 2910 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2911 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2912 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2913 | /* Size of the fifo */ |
| 2914 | uint16_t size; |
| 2915 | /* Amount of space used in the fifo */ |
| 2916 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2917 | /* Timestamp recorded in us. |
| 2918 | * aka accurate timestamp when host event was triggered. |
| 2919 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2920 | uint32_t timestamp; |
| 2921 | /* Total amount of vector lost */ |
| 2922 | uint16_t total_lost; |
| 2923 | /* Lost events since the last fifo_info, per sensors */ |
| 2924 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2925 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2926 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2927 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2928 | uint32_t number_data; |
| 2929 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2930 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2931 | |
| 2932 | /* List supported activity recognition */ |
| 2933 | enum motionsensor_activity { |
| 2934 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2935 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2936 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2937 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2938 | MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2939 | }; |
| 2940 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2941 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2942 | uint8_t sensor_num; |
| 2943 | uint8_t activity; /* one of enum motionsensor_activity */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2944 | uint8_t enable; /* 1: enable, 0: disable */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2945 | uint8_t reserved; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2946 | uint16_t parameters[4]; /* activity dependent parameters */ |
| 2947 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2948 | |
| 2949 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2950 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2951 | |
| 2952 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2953 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2954 | |
| 2955 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2956 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2957 | * data contains time stamp |
| 2958 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2959 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2960 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2961 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2962 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2963 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2964 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2965 | #define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7) |
| 2966 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2967 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2968 | * Send this value for the data element to only perform a read. If you |
| 2969 | * send any other value, the EC will interpret it as data to set and will |
| 2970 | * return the actual value set. |
| 2971 | */ |
| 2972 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2973 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 2974 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2975 | |
| 2976 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2977 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2978 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2979 | |
| 2980 | /* Default Scale value, factor 1. */ |
| 2981 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2982 | |
| 2983 | #define LID_ANGLE_UNRELIABLE 500 |
| 2984 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2985 | enum motionsense_spoof_mode { |
| 2986 | /* Disable spoof mode. */ |
| 2987 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2988 | |
| 2989 | /* Enable spoof mode, but use provided component values. */ |
| 2990 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2991 | |
| 2992 | /* Enable spoof mode, but use the current sensor values. */ |
| 2993 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2994 | |
| 2995 | /* Query the current spoof mode status for the sensor. */ |
| 2996 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2997 | }; |
| 2998 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2999 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3000 | uint8_t cmd; |
| 3001 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3002 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3003 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3004 | /* |
| 3005 | * Maximal number of sensor the host is expecting. |
| 3006 | * 0 means the host is only interested in the number |
| 3007 | * of sensors controlled by the EC. |
| 3008 | */ |
| 3009 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3010 | } dump; |
| 3011 | |
| 3012 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3013 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3014 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3015 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3016 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 3017 | * kb_wake_angle: angle to wakup AP. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3018 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3019 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3020 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3021 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3022 | /* |
| 3023 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 3024 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3025 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3026 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3027 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3028 | |
| 3029 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3030 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 3031 | * Allow entering/exiting the calibration mode. |
| 3032 | */ |
| 3033 | struct __ec_todo_unpacked { |
| 3034 | uint8_t sensor_num; |
| 3035 | uint8_t enable; |
| 3036 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3037 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3038 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3039 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 3040 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3041 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3042 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3043 | uint8_t sensor_num; |
| 3044 | |
| 3045 | /* Rounding flag, true for round-up, false for down. */ |
| 3046 | uint8_t roundup; |
| 3047 | |
| 3048 | uint16_t reserved; |
| 3049 | |
| 3050 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 3051 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3052 | } ec_rate, sensor_odr, sensor_range; |
| 3053 | |
| 3054 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3055 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3056 | uint8_t sensor_num; |
| 3057 | |
| 3058 | /* |
| 3059 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 3060 | * the calibration information in the EC. |
| 3061 | * If unset, just retrieve calibration information. |
| 3062 | */ |
| 3063 | uint16_t flags; |
| 3064 | |
| 3065 | /* |
| 3066 | * Temperature at calibration, in units of 0.01 C |
| 3067 | * 0x8000: invalid / unknown. |
| 3068 | * 0x0: 0C |
| 3069 | * 0x7fff: +327.67C |
| 3070 | */ |
| 3071 | int16_t temp; |
| 3072 | |
| 3073 | /* |
| 3074 | * Offset for calibration. |
| 3075 | * Unit: |
| 3076 | * Accelerometer: 1/1024 g |
| 3077 | * Gyro: 1/1024 deg/s |
| 3078 | * Compass: 1/16 uT |
| 3079 | */ |
| 3080 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3081 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3082 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3083 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 3084 | struct __ec_todo_packed { |
| 3085 | uint8_t sensor_num; |
| 3086 | |
| 3087 | /* |
| 3088 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 3089 | * the calibration information in the EC. |
| 3090 | * If unset, just retrieve calibration information. |
| 3091 | */ |
| 3092 | uint16_t flags; |
| 3093 | |
| 3094 | /* |
| 3095 | * Temperature at calibration, in units of 0.01 C |
| 3096 | * 0x8000: invalid / unknown. |
| 3097 | * 0x0: 0C |
| 3098 | * 0x7fff: +327.67C |
| 3099 | */ |
| 3100 | int16_t temp; |
| 3101 | |
| 3102 | /* |
| 3103 | * Scale for calibration: |
| 3104 | * By default scale is 1, it is encoded on 16bits: |
| 3105 | * 1 = BIT(15) |
| 3106 | * ~2 = 0xFFFF |
| 3107 | * ~0 = 0. |
| 3108 | */ |
| 3109 | uint16_t scale[3]; |
| 3110 | } sensor_scale; |
| 3111 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3112 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3113 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3114 | |
| 3115 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3116 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3117 | /* |
| 3118 | * Number of expected vector to return. |
| 3119 | * EC may return less or 0 if none available. |
| 3120 | */ |
| 3121 | uint32_t max_data_vector; |
| 3122 | } fifo_read; |
| 3123 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3124 | /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3125 | struct ec_motion_sense_activity set_activity; |
| 3126 | |
| 3127 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3128 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3129 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3130 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 3131 | struct __ec_todo_unpacked { |
| 3132 | /* |
| 3133 | * 1: enable, 0 disable fifo, |
| 3134 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 3135 | */ |
| 3136 | int8_t enable; |
| 3137 | } fifo_int_enable; |
| 3138 | |
| 3139 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 3140 | struct __ec_todo_packed { |
| 3141 | uint8_t sensor_id; |
| 3142 | |
| 3143 | /* See enum motionsense_spoof_mode. */ |
| 3144 | uint8_t spoof_enable; |
| 3145 | |
| 3146 | /* Ignored, used for alignment. */ |
| 3147 | uint8_t reserved; |
| 3148 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 3149 | union { |
| 3150 | /* Individual component values to spoof. */ |
| 3151 | int16_t components[3]; |
| 3152 | |
| 3153 | /* Used when spoofing an activity */ |
| 3154 | struct { |
| 3155 | /* enum motionsensor_activity */ |
| 3156 | uint8_t activity_num; |
| 3157 | |
| 3158 | /* spoof activity state */ |
| 3159 | uint8_t activity_state; |
| 3160 | }; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3161 | } __ec_todo_packed; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3162 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3163 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3164 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3165 | struct __ec_todo_unpacked { |
| 3166 | /* |
| 3167 | * Lid angle threshold for switching between tablet and |
| 3168 | * clamshell mode. |
| 3169 | */ |
| 3170 | int16_t lid_angle; |
| 3171 | |
| 3172 | /* |
| 3173 | * Hysteresis degree to prevent fluctuations between |
| 3174 | * clamshell and tablet mode if lid angle keeps |
| 3175 | * changing around the threshold. Lid motion driver will |
| 3176 | * use lid_angle + hys_degree to trigger tablet mode and |
| 3177 | * lid_angle - hys_degree to trigger clamshell mode. |
| 3178 | */ |
| 3179 | int16_t hys_degree; |
| 3180 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3181 | |
| 3182 | /* |
| 3183 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 3184 | * Allow reading a single sensor's online calibration value. |
| 3185 | */ |
| 3186 | struct __ec_todo_unpacked { |
| 3187 | uint8_t sensor_num; |
| 3188 | } online_calib_read; |
| 3189 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3190 | /* |
| 3191 | * Used for MOTIONSENSE_CMD_GET_ACTIVITY. |
| 3192 | */ |
| 3193 | struct __ec_todo_unpacked { |
| 3194 | uint8_t sensor_num; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3195 | uint8_t activity; /* enum motionsensor_activity */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3196 | } get_activity; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3197 | } __ec_todo_packed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3198 | } __ec_todo_packed; |
| 3199 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3200 | enum motion_sense_cmd_info_flags { |
| 3201 | /* The sensor supports online calibration */ |
| 3202 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 3203 | }; |
| 3204 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3205 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3206 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3207 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3208 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3209 | /* Flags representing the motion sensor module. */ |
| 3210 | uint8_t module_flags; |
| 3211 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3212 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3213 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3214 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3215 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3216 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3217 | * for holding all the data. |
| 3218 | */ |
| 3219 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3220 | } dump; |
| 3221 | |
| 3222 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3223 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3224 | /* Should be element of enum motionsensor_type. */ |
| 3225 | uint8_t type; |
| 3226 | |
| 3227 | /* Should be element of enum motionsensor_location. */ |
| 3228 | uint8_t location; |
| 3229 | |
| 3230 | /* Should be element of enum motionsensor_chip. */ |
| 3231 | uint8_t chip; |
| 3232 | } info; |
| 3233 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3234 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 3235 | struct __ec_todo_unpacked { |
| 3236 | /* Should be element of enum motionsensor_type. */ |
| 3237 | uint8_t type; |
| 3238 | |
| 3239 | /* Should be element of enum motionsensor_location. */ |
| 3240 | uint8_t location; |
| 3241 | |
| 3242 | /* Should be element of enum motionsensor_chip. */ |
| 3243 | uint8_t chip; |
| 3244 | |
| 3245 | /* Minimum sensor sampling frequency */ |
| 3246 | uint32_t min_frequency; |
| 3247 | |
| 3248 | /* Maximum sensor sampling frequency */ |
| 3249 | uint32_t max_frequency; |
| 3250 | |
| 3251 | /* Max number of sensor events that could be in fifo */ |
| 3252 | uint32_t fifo_max_event_count; |
| 3253 | } info_3; |
| 3254 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3255 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 3256 | struct __ec_align4 { |
| 3257 | /* Should be element of enum motionsensor_type. */ |
| 3258 | uint8_t type; |
| 3259 | |
| 3260 | /* Should be element of enum motionsensor_location. */ |
| 3261 | uint8_t location; |
| 3262 | |
| 3263 | /* Should be element of enum motionsensor_chip. */ |
| 3264 | uint8_t chip; |
| 3265 | |
| 3266 | /* Minimum sensor sampling frequency */ |
| 3267 | uint32_t min_frequency; |
| 3268 | |
| 3269 | /* Maximum sensor sampling frequency */ |
| 3270 | uint32_t max_frequency; |
| 3271 | |
| 3272 | /* Max number of sensor events that could be in fifo */ |
| 3273 | uint32_t fifo_max_event_count; |
| 3274 | |
| 3275 | /* |
| 3276 | * Should be elements of |
| 3277 | * enum motion_sense_cmd_info_flags |
| 3278 | */ |
| 3279 | uint32_t flags; |
| 3280 | } info_4; |
| 3281 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3282 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 3283 | struct ec_response_motion_sensor_data data; |
| 3284 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3285 | /* |
| 3286 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3287 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3288 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3289 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3290 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3291 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3292 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3293 | /* Current value of the parameter queried. */ |
| 3294 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3295 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3296 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3297 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3298 | /* |
| 3299 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3300 | * PERFORM_CALIB. |
| 3301 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3302 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3303 | int16_t temp; |
| 3304 | int16_t offset[3]; |
| 3305 | } sensor_offset, perform_calib; |
| 3306 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3307 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3308 | struct __ec_todo_unpacked { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3309 | int16_t temp; |
| 3310 | uint16_t scale[3]; |
| 3311 | } sensor_scale; |
| 3312 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3313 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3314 | |
| 3315 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3316 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3317 | struct ec_response_online_calibration_data online_calib_read; |
| 3318 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3319 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3320 | uint16_t reserved; |
| 3321 | uint32_t enabled; |
| 3322 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3323 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3324 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3325 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3326 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3327 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3328 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3329 | /* |
| 3330 | * Angle between 0 and 360 degree if available, |
| 3331 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3332 | */ |
| 3333 | uint16_t value; |
| 3334 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3335 | |
| 3336 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3337 | struct __ec_todo_unpacked { |
| 3338 | /* |
| 3339 | * Lid angle threshold for switching between tablet and |
| 3340 | * clamshell mode. |
| 3341 | */ |
| 3342 | uint16_t lid_angle; |
| 3343 | |
| 3344 | /* Hysteresis degree. */ |
| 3345 | uint16_t hys_degree; |
| 3346 | } tablet_mode_threshold; |
| 3347 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3348 | /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */ |
| 3349 | struct __ec_todo_unpacked { |
| 3350 | uint8_t state; |
| 3351 | } get_activity; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3352 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3353 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3354 | |
| 3355 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3356 | /* Force lid open command */ |
| 3357 | |
| 3358 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3359 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3360 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3361 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3362 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3363 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3364 | |
| 3365 | /*****************************************************************************/ |
| 3366 | /* Configure the behavior of the power button */ |
| 3367 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3368 | |
| 3369 | enum ec_config_power_button_flags { |
| 3370 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3371 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3372 | }; |
| 3373 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3374 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3375 | /* See enum ec_config_power_button_flags */ |
| 3376 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3377 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3378 | |
| 3379 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3380 | /* USB charging control commands */ |
| 3381 | |
| 3382 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3383 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3384 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3385 | enum usb_charge_mode { |
| 3386 | /* Disable USB port. */ |
| 3387 | USB_CHARGE_MODE_DISABLED, |
| 3388 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3389 | USB_CHARGE_MODE_SDP2, |
| 3390 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3391 | USB_CHARGE_MODE_CDP, |
| 3392 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3393 | USB_CHARGE_MODE_DCP_SHORT, |
| 3394 | /* Enable USB port (for dumb ports). */ |
| 3395 | USB_CHARGE_MODE_ENABLED, |
| 3396 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3397 | USB_CHARGE_MODE_DEFAULT, |
| 3398 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3399 | USB_CHARGE_MODE_COUNT, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3400 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3401 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3402 | enum usb_suspend_charge { |
| 3403 | /* Enable charging in suspend */ |
| 3404 | USB_ALLOW_SUSPEND_CHARGE, |
| 3405 | /* Disable charging in suspend */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3406 | USB_DISALLOW_SUSPEND_CHARGE, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3407 | }; |
| 3408 | |
| 3409 | struct ec_params_usb_charge_set_mode { |
| 3410 | uint8_t usb_port_id; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3411 | uint8_t mode : 7; /* enum usb_charge_mode */ |
| 3412 | uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3413 | } __ec_align1; |
| 3414 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3415 | /*****************************************************************************/ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3416 | /* Tablet mode commands */ |
| 3417 | |
| 3418 | /* Set tablet mode */ |
| 3419 | #define EC_CMD_SET_TABLET_MODE 0x0031 |
| 3420 | |
| 3421 | enum tablet_mode_override { |
| 3422 | TABLET_MODE_DEFAULT, |
| 3423 | TABLET_MODE_FORCE_TABLET, |
| 3424 | TABLET_MODE_FORCE_CLAMSHELL, |
| 3425 | }; |
| 3426 | |
| 3427 | struct ec_params_set_tablet_mode { |
| 3428 | uint8_t tablet_mode; /* enum tablet_mode_override */ |
| 3429 | } __ec_align1; |
| 3430 | |
| 3431 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3432 | /* Persistent storage for host */ |
| 3433 | |
| 3434 | /* Maximum bytes that can be read/written in a single command */ |
| 3435 | #define EC_PSTORE_SIZE_MAX 64 |
| 3436 | |
| 3437 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3438 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3439 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3440 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3441 | /* Persistent storage size, in bytes */ |
| 3442 | uint32_t pstore_size; |
| 3443 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3444 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3445 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3446 | |
| 3447 | /* |
| 3448 | * Read persistent storage |
| 3449 | * |
| 3450 | * Response is params.size bytes of data. |
| 3451 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3452 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3453 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3454 | struct ec_params_pstore_read { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3455 | uint32_t offset; /* Byte offset to read */ |
| 3456 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3457 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3458 | |
| 3459 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3460 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3461 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3462 | struct ec_params_pstore_write { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3463 | uint32_t offset; /* Byte offset to write */ |
| 3464 | uint32_t size; /* Size to write in bytes */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3465 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3466 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3467 | |
| 3468 | /*****************************************************************************/ |
| 3469 | /* Real-time clock */ |
| 3470 | |
| 3471 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3472 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3473 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3474 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3475 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3476 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3477 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3478 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3479 | |
| 3480 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3481 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3482 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3483 | |
| 3484 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3485 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3486 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3487 | |
| 3488 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3489 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3490 | |
| 3491 | /*****************************************************************************/ |
| 3492 | /* Port80 log access */ |
| 3493 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3494 | /* Maximum entries that can be read/written in a single command */ |
| 3495 | #define EC_PORT80_SIZE_MAX 32 |
| 3496 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3497 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3498 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3499 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3500 | |
| 3501 | enum ec_port80_subcmd { |
| 3502 | EC_PORT80_GET_INFO = 0, |
| 3503 | EC_PORT80_READ_BUFFER, |
| 3504 | }; |
| 3505 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3506 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3507 | uint16_t subcmd; |
| 3508 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3509 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3510 | uint32_t offset; |
| 3511 | uint32_t num_entries; |
| 3512 | } read_buffer; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3513 | } __ec_todo_packed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3514 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3515 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3516 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3517 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3518 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3519 | uint32_t writes; |
| 3520 | uint32_t history_size; |
| 3521 | uint32_t last_boot; |
| 3522 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3523 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3524 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3525 | } data; |
| 3526 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3527 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3528 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3529 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3530 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3531 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3532 | |
| 3533 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3534 | /* Temporary secure storage for host verified boot use */ |
| 3535 | |
| 3536 | /* Number of bytes in a vstore slot */ |
| 3537 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3538 | |
| 3539 | /* Maximum number of vstore slots */ |
| 3540 | #define EC_VSTORE_SLOT_MAX 32 |
| 3541 | |
| 3542 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3543 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3544 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3545 | /* Indicates which slots are locked */ |
| 3546 | uint32_t slot_locked; |
| 3547 | /* Total number of slots available */ |
| 3548 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3549 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3550 | |
| 3551 | /* |
| 3552 | * Read temporary secure storage |
| 3553 | * |
| 3554 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3555 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3556 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3557 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3558 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3559 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3560 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3561 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3562 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3563 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3564 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3565 | |
| 3566 | /* |
| 3567 | * Write temporary secure storage and lock it. |
| 3568 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3569 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3570 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3571 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3572 | uint8_t slot; /* Slot to write to */ |
| 3573 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3574 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3575 | |
| 3576 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3577 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3578 | * reuse the command number, but the data and behavior is incompatible. |
| 3579 | * Version 0 is what originally shipped on Link. |
| 3580 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3581 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3582 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3583 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3584 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3585 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3586 | /* The version 0 structs are opaque. You have to know what they are for |
| 3587 | * the get/set commands to make any sense. |
| 3588 | */ |
| 3589 | |
| 3590 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3591 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3592 | uint8_t sensor_type; |
| 3593 | uint8_t threshold_id; |
| 3594 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3595 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3596 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3597 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3598 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3599 | uint8_t sensor_type; |
| 3600 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3601 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3602 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3603 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3604 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3605 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3606 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3607 | /* The version 1 structs are visible. */ |
| 3608 | enum ec_temp_thresholds { |
| 3609 | EC_TEMP_THRESH_WARN = 0, |
| 3610 | EC_TEMP_THRESH_HIGH, |
| 3611 | EC_TEMP_THRESH_HALT, |
| 3612 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3613 | EC_TEMP_THRESH_COUNT, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3614 | }; |
| 3615 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3616 | /* |
| 3617 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3618 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3619 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3620 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3621 | * hysteresis. |
| 3622 | * For example, |
| 3623 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3624 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3625 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3626 | * temperature <= 299 K. |
| 3627 | * |
| 3628 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3629 | * For example, |
| 3630 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3631 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3632 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3633 | * temperature <= 294 K. |
| 3634 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3635 | * Note that this structure is a sub-structure of |
| 3636 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3637 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3638 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3639 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3640 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3641 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3642 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3643 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3644 | |
| 3645 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3646 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3647 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3648 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3649 | /* This returns a struct ec_thermal_config */ |
| 3650 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3651 | /* |
| 3652 | * Version 1 - set config for one sensor. |
| 3653 | * Use read-modify-write for best results! |
| 3654 | */ |
| 3655 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3656 | uint32_t sensor_num; |
| 3657 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3658 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3659 | /* This returns no data */ |
| 3660 | |
| 3661 | /****************************************************************************/ |
| 3662 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3663 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3664 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3665 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3666 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3667 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3668 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3669 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3670 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3671 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3672 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3673 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3674 | |
| 3675 | /* |
| 3676 | * The original TMP006 calibration only needed four params, but now we need |
| 3677 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3678 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3679 | * and how many params it requires. That way we can change the EC code without |
| 3680 | * needing to update this file. We can also use a different algorithm on each |
| 3681 | * sensor. |
| 3682 | */ |
| 3683 | |
| 3684 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3685 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3686 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3687 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3688 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3689 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3690 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3691 | float s0; |
| 3692 | float b0; |
| 3693 | float b1; |
| 3694 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3695 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3696 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3697 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3698 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3699 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3700 | float s0; |
| 3701 | float b0; |
| 3702 | float b1; |
| 3703 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3704 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3705 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3706 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3707 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3708 | uint8_t algorithm; |
| 3709 | uint8_t num_params; |
| 3710 | uint8_t reserved[2]; |
| 3711 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3712 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3713 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3714 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3715 | uint8_t index; |
| 3716 | uint8_t algorithm; |
| 3717 | uint8_t num_params; |
| 3718 | uint8_t reserved; |
| 3719 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3720 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3721 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3722 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3723 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3724 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3725 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3726 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3727 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3728 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3729 | struct ec_response_tmp006_get_raw { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3730 | int32_t t; /* In 1/100 K */ |
| 3731 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3732 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3733 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3734 | /*****************************************************************************/ |
| 3735 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3736 | |
| 3737 | /* |
| 3738 | * Read key state |
| 3739 | * |
| 3740 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3741 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3742 | * |
| 3743 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3744 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3745 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3746 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3747 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3748 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3749 | /* |
| 3750 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3751 | */ |
| 3752 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3753 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3754 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3755 | uint32_t rows; |
| 3756 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3757 | /* Formerly "switches", which was 0. */ |
| 3758 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3759 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3760 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3761 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3762 | uint8_t info_type; |
| 3763 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3764 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3765 | |
| 3766 | enum ec_mkbp_info_type { |
| 3767 | /* |
| 3768 | * Info about the keyboard matrix: number of rows and columns. |
| 3769 | * |
| 3770 | * Returns struct ec_response_mkbp_info. |
| 3771 | */ |
| 3772 | EC_MKBP_INFO_KBD = 0, |
| 3773 | |
| 3774 | /* |
| 3775 | * For buttons and switches, info about which specifically are |
| 3776 | * supported. event_type must be set to one of the values in enum |
| 3777 | * ec_mkbp_event. |
| 3778 | * |
| 3779 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3780 | * bitmask indicating which buttons or switches are present. See the |
| 3781 | * bit inidices below. |
| 3782 | */ |
| 3783 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3784 | |
| 3785 | /* |
| 3786 | * Instantaneous state of buttons and switches. |
| 3787 | * |
| 3788 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3789 | * |
| 3790 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3791 | * indicating the current state of the keyboard matrix. |
| 3792 | * |
| 3793 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3794 | * event state. |
| 3795 | * |
| 3796 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3797 | * state of supported buttons. |
| 3798 | * |
| 3799 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3800 | * state of supported switches. |
| 3801 | */ |
| 3802 | EC_MKBP_INFO_CURRENT = 2, |
| 3803 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3804 | |
| 3805 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3806 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3807 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3808 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3809 | uint8_t col; |
| 3810 | uint8_t row; |
| 3811 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3812 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3813 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3814 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3815 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3816 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3817 | |
| 3818 | /* flags */ |
| 3819 | enum mkbp_config_flags { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3820 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3821 | }; |
| 3822 | |
| 3823 | enum mkbp_config_valid { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3824 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3825 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3826 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3827 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3828 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3829 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3830 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3831 | }; |
| 3832 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3833 | /* |
| 3834 | * Configuration for our key scanning algorithm. |
| 3835 | * |
| 3836 | * Note that this is used as a sub-structure of |
| 3837 | * ec_{params/response}_mkbp_get_config. |
| 3838 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3839 | struct ec_mkbp_config { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3840 | uint32_t valid_mask; /* valid fields */ |
| 3841 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3842 | uint8_t valid_flags; /* which flags are valid */ |
| 3843 | uint16_t scan_period_us; /* period between start of scans */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3844 | /* revert to interrupt mode after no activity for this long */ |
| 3845 | uint32_t poll_timeout_us; |
| 3846 | /* |
| 3847 | * minimum post-scan relax time. Once we finish a scan we check |
| 3848 | * the time until we are due to start the next one. If this time is |
| 3849 | * shorter this field, we use this instead. |
| 3850 | */ |
| 3851 | uint16_t min_post_scan_delay_us; |
| 3852 | /* delay between setting up output and waiting for it to settle */ |
| 3853 | uint16_t output_settle_us; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3854 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3855 | uint16_t debounce_up_us; /* time for debounce on key up */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3856 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3857 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3858 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3859 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3860 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3861 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3862 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3863 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3864 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3865 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3866 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3867 | |
| 3868 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3869 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3870 | |
| 3871 | enum ec_keyscan_seq_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3872 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3873 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3874 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3875 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3876 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3877 | }; |
| 3878 | |
| 3879 | enum ec_collect_flags { |
| 3880 | /* |
| 3881 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3882 | * scans may be skipped. |
| 3883 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3884 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3885 | }; |
| 3886 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3887 | struct ec_collect_item { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3888 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3889 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3890 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3891 | struct ec_params_keyscan_seq_ctrl { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3892 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3893 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3894 | struct __ec_align1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3895 | uint8_t active; /* still active */ |
| 3896 | uint8_t num_items; /* number of items */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3897 | /* Current item being presented */ |
| 3898 | uint8_t cur_item; |
| 3899 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3900 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3901 | /* |
| 3902 | * Absolute time for this scan, measured from the |
| 3903 | * start of the sequence. |
| 3904 | */ |
| 3905 | uint32_t time_us; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3906 | uint8_t scan[0]; /* keyscan data */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3907 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3908 | struct __ec_align1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3909 | uint8_t start_item; /* First item to return */ |
| 3910 | uint8_t num_items; /* Number of items to return */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3911 | } collect; |
| 3912 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3913 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3914 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3915 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3916 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3917 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3918 | uint8_t num_items; /* Number of items */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3919 | /* Data for each item */ |
| 3920 | struct ec_collect_item item[0]; |
| 3921 | } collect; |
| 3922 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3923 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3924 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3925 | /* |
| 3926 | * Get the next pending MKBP event. |
| 3927 | * |
| 3928 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3929 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3930 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3931 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3932 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3933 | |
| 3934 | /* |
| 3935 | * We use the most significant bit of the event type to indicate to the host |
| 3936 | * that the EC has more MKBP events available to provide. |
| 3937 | */ |
| 3938 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3939 | |
| 3940 | /* The mask to apply to get the raw event type */ |
| 3941 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3942 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3943 | enum ec_mkbp_event { |
| 3944 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3945 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3946 | |
| 3947 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3948 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3949 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3950 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3951 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3952 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3953 | /* The state of the non-matrixed buttons have changed. */ |
| 3954 | EC_MKBP_EVENT_BUTTON = 3, |
| 3955 | |
| 3956 | /* The state of the switches have changed. */ |
| 3957 | EC_MKBP_EVENT_SWITCH = 4, |
| 3958 | |
| 3959 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3960 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3961 | |
| 3962 | /* |
| 3963 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3964 | * corresponding to the key to be pressed. |
| 3965 | */ |
| 3966 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3967 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3968 | /* |
| 3969 | * New 64-bit host event. |
| 3970 | * The event data is 8 bytes of host event flags. |
| 3971 | */ |
| 3972 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3973 | |
| 3974 | /* Notify the AP that something happened on CEC */ |
| 3975 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3976 | |
| 3977 | /* Send an incoming CEC message to the AP */ |
| 3978 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3979 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3980 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3981 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3982 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3983 | /* New online calibration values are available. */ |
| 3984 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3985 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 3986 | /* Peripheral device charger event */ |
| 3987 | EC_MKBP_EVENT_PCHG = 12, |
| 3988 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3989 | /* Number of MKBP events */ |
| 3990 | EC_MKBP_EVENT_COUNT, |
| 3991 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3992 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3993 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 3994 | /* clang-format off */ |
| 3995 | #define EC_MKBP_EVENT_TEXT \ |
| 3996 | { \ |
| 3997 | [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \ |
| 3998 | [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \ |
| 3999 | [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \ |
| 4000 | [EC_MKBP_EVENT_BUTTON] = "BUTTON", \ |
| 4001 | [EC_MKBP_EVENT_SWITCH] = "SWITCH", \ |
| 4002 | [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \ |
| 4003 | [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \ |
| 4004 | [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \ |
| 4005 | [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \ |
| 4006 | [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \ |
| 4007 | [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \ |
| 4008 | [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \ |
| 4009 | [EC_MKBP_EVENT_PCHG] = "PCHG", \ |
| 4010 | } |
| 4011 | /* clang-format on */ |
| 4012 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4013 | union __ec_align_offset1 ec_response_get_next_data { |
| 4014 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4015 | |
| 4016 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4017 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4018 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4019 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4020 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4021 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4022 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4023 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4024 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4025 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4026 | uint32_t buttons; |
| 4027 | |
| 4028 | uint32_t switches; |
| 4029 | |
| 4030 | uint32_t fp_events; |
| 4031 | |
| 4032 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4033 | |
| 4034 | /* CEC events from enum mkbp_cec_event */ |
| 4035 | uint32_t cec_events; |
| 4036 | }; |
| 4037 | |
| 4038 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 4039 | uint8_t key_matrix[16]; |
| 4040 | |
| 4041 | /* Unaligned */ |
| 4042 | uint32_t host_event; |
| 4043 | uint64_t host_event64; |
| 4044 | |
| 4045 | struct __ec_todo_unpacked { |
| 4046 | /* For aligning the fifo_info */ |
| 4047 | uint8_t reserved[3]; |
| 4048 | struct ec_response_motion_sense_fifo_info info; |
| 4049 | } sensor_fifo; |
| 4050 | |
| 4051 | uint32_t buttons; |
| 4052 | |
| 4053 | uint32_t switches; |
| 4054 | |
| 4055 | uint32_t fp_events; |
| 4056 | |
| 4057 | uint32_t sysrq; |
| 4058 | |
| 4059 | /* CEC events from enum mkbp_cec_event */ |
| 4060 | uint32_t cec_events; |
| 4061 | |
| 4062 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4063 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4064 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4065 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4066 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4067 | uint8_t event_type; |
| 4068 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4069 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4070 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4071 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4072 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4073 | uint8_t event_type; |
| 4074 | /* Followed by event data if any */ |
| 4075 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4076 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4077 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4078 | /* Bit indices for buttons and switches.*/ |
| 4079 | /* Buttons */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4080 | #define EC_MKBP_POWER_BUTTON 0 |
| 4081 | #define EC_MKBP_VOL_UP 1 |
| 4082 | #define EC_MKBP_VOL_DOWN 2 |
| 4083 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4084 | |
| 4085 | /* Switches */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4086 | #define EC_MKBP_LID_OPEN 0 |
| 4087 | #define EC_MKBP_TABLET_MODE 1 |
| 4088 | #define EC_MKBP_BASE_ATTACHED 2 |
| 4089 | #define EC_MKBP_FRONT_PROXIMITY 3 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4090 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4091 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4092 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4093 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4094 | struct ec_response_keyboard_factory_test { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4095 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4096 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4097 | |
| 4098 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4099 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF) |
| 4100 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4101 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4102 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \ |
| 4103 | (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4104 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 4105 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4106 | #define EC_MKBP_FP_MATCH_IDX(fpe) \ |
| 4107 | (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
| 4108 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 4109 | #define EC_MKBP_FP_MATCH BIT(28) |
| 4110 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 4111 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 4112 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4113 | /* 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] | 4114 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 4115 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 4116 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 4117 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 4118 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4119 | /* 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] | 4120 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4121 | /* 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] | 4122 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 4123 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
| 4124 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
| 4125 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 4126 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 4127 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 4128 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4129 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 4130 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4131 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 4132 | enum ec_mkbp_event_mask_action { |
| 4133 | /* Retrieve the value of a wake mask. */ |
| 4134 | GET_WAKE_MASK = 0, |
| 4135 | |
| 4136 | /* Set the value of a wake mask. */ |
| 4137 | SET_WAKE_MASK, |
| 4138 | }; |
| 4139 | |
| 4140 | enum ec_mkbp_mask_type { |
| 4141 | /* |
| 4142 | * These are host events sent via MKBP. |
| 4143 | * |
| 4144 | * Some examples are: |
| 4145 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 4146 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 4147 | * |
| 4148 | * The only things that should be in this mask are: |
| 4149 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 4150 | */ |
| 4151 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 4152 | |
| 4153 | /* |
| 4154 | * These are MKBP events. Some examples are: |
| 4155 | * |
| 4156 | * EC_MKBP_EVENT_KEY_MATRIX |
| 4157 | * EC_MKBP_EVENT_SWITCH |
| 4158 | * |
| 4159 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 4160 | */ |
| 4161 | EC_MKBP_EVENT_WAKE_MASK, |
| 4162 | }; |
| 4163 | |
| 4164 | struct ec_params_mkbp_event_wake_mask { |
| 4165 | /* One of enum ec_mkbp_event_mask_action */ |
| 4166 | uint8_t action; |
| 4167 | |
| 4168 | /* |
| 4169 | * Which MKBP mask are you interested in acting upon? This is one of |
| 4170 | * ec_mkbp_mask_type. |
| 4171 | */ |
| 4172 | uint8_t mask_type; |
| 4173 | |
| 4174 | /* If setting a new wake mask, this contains the mask to set. */ |
| 4175 | uint32_t new_wake_mask; |
| 4176 | }; |
| 4177 | |
| 4178 | struct ec_response_mkbp_event_wake_mask { |
| 4179 | uint32_t wake_mask; |
| 4180 | }; |
| 4181 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4182 | /*****************************************************************************/ |
| 4183 | /* Temperature sensor commands */ |
| 4184 | |
| 4185 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4186 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4187 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4188 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4189 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4190 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4191 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4192 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4193 | char sensor_name[32]; |
| 4194 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4195 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4196 | |
| 4197 | /*****************************************************************************/ |
| 4198 | |
| 4199 | /* |
| 4200 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 4201 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 4202 | * below. |
| 4203 | */ |
| 4204 | |
| 4205 | /*****************************************************************************/ |
| 4206 | /* Host event commands */ |
| 4207 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4208 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4209 | /* |
| 4210 | * Host event mask params and response structures, shared by all of the host |
| 4211 | * event commands below. |
| 4212 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4213 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4214 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4215 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4216 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4217 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4218 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4219 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4220 | |
| 4221 | /* These all use ec_response_host_event_mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4222 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 4223 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 4224 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4225 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4226 | |
| 4227 | /* These all use ec_params_host_event_mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4228 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 4229 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 4230 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4231 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4232 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4233 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4234 | /* |
| 4235 | * Unified host event programming interface - Should be used by newer versions |
| 4236 | * of BIOS/OS to program host events and masks |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4237 | * |
| 4238 | * EC returns: |
| 4239 | * - EC_RES_INVALID_PARAM: Action or mask type is unknown. |
| 4240 | * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type. |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4241 | */ |
| 4242 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4243 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4244 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 4245 | uint8_t action; |
| 4246 | |
| 4247 | /* |
| 4248 | * Mask type that the host requested the action on - one of |
| 4249 | * enum ec_host_event_mask_type. |
| 4250 | */ |
| 4251 | uint8_t mask_type; |
| 4252 | |
| 4253 | /* Set to 0, ignore on read */ |
| 4254 | uint16_t reserved; |
| 4255 | |
| 4256 | /* Value to be used in case of set operations. */ |
| 4257 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4258 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4259 | |
| 4260 | /* |
| 4261 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 4262 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 4263 | */ |
| 4264 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4265 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4266 | /* Mask value in case of get operation */ |
| 4267 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4268 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4269 | |
| 4270 | enum ec_host_event_action { |
| 4271 | /* |
| 4272 | * params.value is ignored. Value of mask_type populated |
| 4273 | * in response.value |
| 4274 | */ |
| 4275 | EC_HOST_EVENT_GET, |
| 4276 | |
| 4277 | /* Bits in params.value are set */ |
| 4278 | EC_HOST_EVENT_SET, |
| 4279 | |
| 4280 | /* Bits in params.value are cleared */ |
| 4281 | EC_HOST_EVENT_CLEAR, |
| 4282 | }; |
| 4283 | |
| 4284 | enum ec_host_event_mask_type { |
| 4285 | |
| 4286 | /* Main host event copy */ |
| 4287 | EC_HOST_EVENT_MAIN, |
| 4288 | |
| 4289 | /* Copy B of host events */ |
| 4290 | EC_HOST_EVENT_B, |
| 4291 | |
| 4292 | /* SCI Mask */ |
| 4293 | EC_HOST_EVENT_SCI_MASK, |
| 4294 | |
| 4295 | /* SMI Mask */ |
| 4296 | EC_HOST_EVENT_SMI_MASK, |
| 4297 | |
| 4298 | /* Mask of events that should be always reported in hostevents */ |
| 4299 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 4300 | |
| 4301 | /* Active wake mask */ |
| 4302 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 4303 | |
| 4304 | /* Lazy wake mask for S0ix */ |
| 4305 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 4306 | |
| 4307 | /* Lazy wake mask for S3 */ |
| 4308 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 4309 | |
| 4310 | /* Lazy wake mask for S5 */ |
| 4311 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 4312 | }; |
| 4313 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4314 | #define EC_CMD_HOST_EVENT 0x00A4 |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4315 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4316 | /*****************************************************************************/ |
| 4317 | /* Switch commands */ |
| 4318 | |
| 4319 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4320 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4321 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4322 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4323 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4324 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4325 | |
| 4326 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4327 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4328 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4329 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4330 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4331 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4332 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4333 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4334 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4335 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4336 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4337 | /* Flags to enable now */ |
| 4338 | uint8_t now_flags; |
| 4339 | |
| 4340 | /* Which flags to copy from now_flags */ |
| 4341 | uint8_t now_mask; |
| 4342 | |
| 4343 | /* |
| 4344 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4345 | * transition. (Other flags will be disabled by the S0->S3 |
| 4346 | * transition.) |
| 4347 | */ |
| 4348 | uint8_t suspend_flags; |
| 4349 | |
| 4350 | /* Which flags to copy from suspend_flags */ |
| 4351 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4352 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4353 | |
| 4354 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4355 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4356 | /* Flags to enable now */ |
| 4357 | uint8_t now_flags; |
| 4358 | |
| 4359 | /* Flags to leave enabled in S3 */ |
| 4360 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4361 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4362 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4363 | /*****************************************************************************/ |
| 4364 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4365 | |
| 4366 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4367 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4368 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4369 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4370 | char name[32]; |
| 4371 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4372 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4373 | |
| 4374 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4375 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4376 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4377 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4378 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4379 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4380 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4381 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4382 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4383 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4384 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4385 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4386 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4387 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4388 | uint8_t subcmd; |
| 4389 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4390 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4391 | char name[32]; |
| 4392 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4393 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4394 | uint8_t index; |
| 4395 | } get_info; |
| 4396 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4397 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4398 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4399 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4400 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4401 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4402 | uint8_t val; |
| 4403 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4404 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4405 | uint8_t val; |
| 4406 | char name[32]; |
| 4407 | uint32_t flags; |
| 4408 | } get_info; |
| 4409 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4410 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4411 | |
| 4412 | enum gpio_get_subcmd { |
| 4413 | EC_GPIO_GET_BY_NAME = 0, |
| 4414 | EC_GPIO_GET_COUNT = 1, |
| 4415 | EC_GPIO_GET_INFO = 2, |
| 4416 | }; |
| 4417 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4418 | /*****************************************************************************/ |
| 4419 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4420 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4421 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4422 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4423 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4424 | * |
| 4425 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4426 | */ |
| 4427 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4428 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4429 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4430 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4431 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4432 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4433 | uint8_t read_size; /* Either 8 or 16. */ |
| 4434 | uint8_t port; |
| 4435 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4436 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4437 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4438 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4439 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4440 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4441 | |
| 4442 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4443 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4444 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4445 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4446 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4447 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4448 | uint8_t write_size; /* Either 8 or 16. */ |
| 4449 | uint8_t port; |
| 4450 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4451 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4452 | |
| 4453 | /*****************************************************************************/ |
| 4454 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4455 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4456 | /* Force charge state machine to stop charging the battery or force it to |
| 4457 | * discharge the battery. |
| 4458 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4459 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 4460 | #define EC_VER_CHARGE_CONTROL 3 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4461 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4462 | enum ec_charge_control_mode { |
| 4463 | CHARGE_CONTROL_NORMAL = 0, |
| 4464 | CHARGE_CONTROL_IDLE, |
| 4465 | CHARGE_CONTROL_DISCHARGE, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4466 | /* Add no more entry below. */ |
| 4467 | CHARGE_CONTROL_COUNT, |
| 4468 | }; |
| 4469 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4470 | #define EC_CHARGE_MODE_TEXT \ |
| 4471 | { \ |
| 4472 | [CHARGE_CONTROL_NORMAL] = "NORMAL", \ |
| 4473 | [CHARGE_CONTROL_IDLE] = "IDLE", \ |
| 4474 | [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4475 | } |
| 4476 | |
| 4477 | enum ec_charge_control_cmd { |
| 4478 | EC_CHARGE_CONTROL_CMD_SET = 0, |
| 4479 | EC_CHARGE_CONTROL_CMD_GET, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4480 | }; |
| 4481 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 4482 | enum ec_charge_control_flag { |
| 4483 | EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0), |
| 4484 | }; |
| 4485 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4486 | struct ec_params_charge_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4487 | uint32_t mode; /* enum charge_control_mode */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4488 | |
| 4489 | /* Below are the fields added in V2. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4490 | uint8_t cmd; /* enum ec_charge_control_cmd. */ |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 4491 | uint8_t flags; /* enum ec_charge_control_flag (v3+) */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4492 | /* |
| 4493 | * Lower and upper thresholds for battery sustainer. This struct isn't |
| 4494 | * named to avoid tainting foreign projects' name spaces. |
| 4495 | * |
| 4496 | * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer |
| 4497 | * will be disabled. To disable battery sustainer, set mode=NORMAL, |
| 4498 | * lower=-1, upper=-1. |
| 4499 | */ |
| 4500 | struct { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4501 | int8_t lower; /* Display SoC in percentage. */ |
| 4502 | int8_t upper; /* Display SoC in percentage. */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4503 | } sustain_soc; |
| 4504 | } __ec_align4; |
| 4505 | |
| 4506 | /* Added in v2 */ |
| 4507 | struct ec_response_charge_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4508 | uint32_t mode; /* enum charge_control_mode */ |
| 4509 | struct { /* Battery sustainer thresholds */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4510 | int8_t lower; |
| 4511 | int8_t upper; |
| 4512 | } sustain_soc; |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 4513 | uint8_t flags; /* enum ec_charge_control_flag (v3+) */ |
| 4514 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4515 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4516 | |
| 4517 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4518 | |
| 4519 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4520 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4521 | |
| 4522 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4523 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4524 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4525 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4526 | * end of the previous snapshot. |
| 4527 | * |
| 4528 | * The params are only looked at in version >= 1 of this command. Prior |
| 4529 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4530 | * |
| 4531 | * Response is null-terminated string. Empty string, if there is no more |
| 4532 | * remaining output. |
| 4533 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4534 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4535 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4536 | enum ec_console_read_subcmd { |
| 4537 | CONSOLE_READ_NEXT = 0, |
| 4538 | CONSOLE_READ_RECENT, |
| 4539 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4540 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4541 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4542 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4543 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4544 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4545 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4546 | |
| 4547 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4548 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4549 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4550 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4551 | * EC_RES_SUCCESS if the command was successful. |
| 4552 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4553 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4554 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4555 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4556 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4557 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4558 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4559 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4560 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4561 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4562 | /*****************************************************************************/ |
| 4563 | /* USB port mux control. */ |
| 4564 | |
| 4565 | /* |
| 4566 | * Switch USB mux or return to automatic switching. |
| 4567 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4568 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4569 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4570 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4571 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4572 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4573 | |
| 4574 | /*****************************************************************************/ |
| 4575 | /* LDOs / FETs control. */ |
| 4576 | |
| 4577 | enum ec_ldo_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4578 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4579 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4580 | }; |
| 4581 | |
| 4582 | /* |
| 4583 | * Switch on/off a LDO. |
| 4584 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4585 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4586 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4587 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4588 | uint8_t index; |
| 4589 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4590 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4591 | |
| 4592 | /* |
| 4593 | * Get LDO state. |
| 4594 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4595 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4596 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4597 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4598 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4599 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4600 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4601 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4602 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4603 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4604 | |
| 4605 | /*****************************************************************************/ |
| 4606 | /* Power info. */ |
| 4607 | |
| 4608 | /* |
| 4609 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4610 | * |
| 4611 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4612 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4613 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4614 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4615 | /* |
| 4616 | * v1 of EC_CMD_POWER_INFO |
| 4617 | */ |
| 4618 | enum system_power_source { |
| 4619 | /* |
| 4620 | * Haven't established which power source is used yet, |
| 4621 | * or no presence signals are available |
| 4622 | */ |
| 4623 | POWER_SOURCE_UNKNOWN = 0, |
| 4624 | /* System is running on battery alone */ |
| 4625 | POWER_SOURCE_BATTERY = 1, |
| 4626 | /* System is running on A/C alone */ |
| 4627 | POWER_SOURCE_AC = 2, |
| 4628 | /* System is running on A/C and battery */ |
| 4629 | POWER_SOURCE_AC_BATTERY = 3, |
| 4630 | }; |
| 4631 | |
| 4632 | struct ec_response_power_info_v1 { |
| 4633 | /* enum system_power_source */ |
| 4634 | uint8_t system_power_source; |
| 4635 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4636 | uint8_t battery_soc; |
| 4637 | /* AC Adapter 100% rating, Watts */ |
| 4638 | uint8_t ac_adapter_100pct; |
| 4639 | /* AC Adapter 10ms rating, Watts */ |
| 4640 | uint8_t ac_adapter_10ms; |
| 4641 | /* Battery 1C rating, derated */ |
| 4642 | uint8_t battery_1cd; |
| 4643 | /* Rest of Platform average, Watts */ |
| 4644 | uint8_t rop_avg; |
| 4645 | /* Rest of Platform peak, Watts */ |
| 4646 | uint8_t rop_peak; |
| 4647 | /* Nominal charger efficiency, % */ |
| 4648 | uint8_t nominal_charger_eff; |
| 4649 | /* Rest of Platform VR Average Efficiency, % */ |
| 4650 | uint8_t rop_avg_eff; |
| 4651 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4652 | uint8_t rop_peak_eff; |
| 4653 | /* SoC VR Efficiency at Average level, % */ |
| 4654 | uint8_t soc_avg_eff; |
| 4655 | /* SoC VR Efficiency at Peak level, % */ |
| 4656 | uint8_t soc_peak_eff; |
| 4657 | /* Intel-specific items */ |
| 4658 | struct { |
| 4659 | /* Battery's level of DBPT support: 0, 2 */ |
| 4660 | uint8_t batt_dbpt_support_level; |
| 4661 | /* |
| 4662 | * Maximum peak power from battery (10ms), Watts |
| 4663 | * If DBPT is not supported, this is 0 |
| 4664 | */ |
| 4665 | uint8_t batt_dbpt_max_peak_power; |
| 4666 | /* |
| 4667 | * Sustained peak power from battery, Watts |
| 4668 | * If DBPT is not supported, this is 0 |
| 4669 | */ |
| 4670 | uint8_t batt_dbpt_sus_peak_power; |
| 4671 | } intel; |
| 4672 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4673 | |
| 4674 | /*****************************************************************************/ |
| 4675 | /* I2C passthru command */ |
| 4676 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4677 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4678 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4679 | /* Read data; if not present, message is a write */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4680 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4681 | |
| 4682 | /* Mask for address */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4683 | #define EC_I2C_ADDR_MASK 0x3ff |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4684 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4685 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4686 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4687 | |
| 4688 | /* Any error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4689 | #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] | 4690 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4691 | struct ec_params_i2c_passthru_msg { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4692 | uint16_t addr_flags; /* I2C peripheral address and flags */ |
| 4693 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4694 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4695 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4696 | struct ec_params_i2c_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4697 | uint8_t port; /* I2C port number */ |
| 4698 | uint8_t num_msgs; /* Number of messages */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4699 | struct ec_params_i2c_passthru_msg msg[]; |
| 4700 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4701 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4702 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4703 | struct ec_response_i2c_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4704 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4705 | uint8_t num_msgs; /* Number of messages processed */ |
| 4706 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4707 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4708 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4709 | /*****************************************************************************/ |
| 4710 | /* Power button hang detect */ |
| 4711 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4712 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4713 | |
| 4714 | /* Reasons to start hang detection timer */ |
| 4715 | /* Power button pressed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4716 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4717 | |
| 4718 | /* Lid closed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4719 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4720 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4721 | /* Lid opened */ |
| 4722 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4723 | |
| 4724 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4725 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4726 | |
| 4727 | /* Reasons to cancel hang detection */ |
| 4728 | |
| 4729 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4730 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4731 | |
| 4732 | /* Any host command from AP received */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4733 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4734 | |
| 4735 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4736 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4737 | |
| 4738 | /* |
| 4739 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4740 | * timer is started. This provides the AP a way to start the hang timer |
| 4741 | * without reconfiguring any of the other hang detect settings. Note that |
| 4742 | * you must previously have configured the timeouts. |
| 4743 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4744 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4745 | |
| 4746 | /* |
| 4747 | * If this flag is set, all the other fields are ignored (including |
| 4748 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4749 | * without reconfiguring any of the other hang detect settings. |
| 4750 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4751 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4752 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4753 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4754 | /* Flags; see EC_HANG_* */ |
| 4755 | uint32_t flags; |
| 4756 | |
| 4757 | /* Timeout in msec before generating host event, if enabled */ |
| 4758 | uint16_t host_event_timeout_msec; |
| 4759 | |
| 4760 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4761 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4762 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4763 | |
| 4764 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4765 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4766 | |
| 4767 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4768 | * This is the single catch-all host command to exchange data regarding the |
| 4769 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4770 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4771 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4772 | |
| 4773 | /* Subcommands for this host command */ |
| 4774 | enum charge_state_command { |
| 4775 | CHARGE_STATE_CMD_GET_STATE, |
| 4776 | CHARGE_STATE_CMD_GET_PARAM, |
| 4777 | CHARGE_STATE_CMD_SET_PARAM, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4778 | CHARGE_STATE_NUM_CMDS, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4779 | }; |
| 4780 | |
| 4781 | /* |
| 4782 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4783 | * params, which are handled by the particular implementations. |
| 4784 | */ |
| 4785 | enum charge_state_params { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4786 | /* charger voltage limit */ |
| 4787 | CS_PARAM_CHG_VOLTAGE, |
| 4788 | |
| 4789 | /* charger current limit */ |
| 4790 | CS_PARAM_CHG_CURRENT, |
| 4791 | |
| 4792 | /* charger input current limit */ |
| 4793 | CS_PARAM_CHG_INPUT_CURRENT, |
| 4794 | |
| 4795 | /* charger-specific status */ |
| 4796 | CS_PARAM_CHG_STATUS, |
| 4797 | |
| 4798 | /* charger-specific options */ |
| 4799 | CS_PARAM_CHG_OPTION, |
| 4800 | |
| 4801 | /* |
| 4802 | * Check if power is limited due to low battery and / or a |
| 4803 | * weak external charger. READ ONLY. |
| 4804 | */ |
| 4805 | CS_PARAM_LIMIT_POWER, |
| 4806 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4807 | /* How many so far? */ |
| 4808 | CS_NUM_BASE_PARAMS, |
| 4809 | |
| 4810 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4811 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4812 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4813 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4814 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4815 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4816 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4817 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4818 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4819 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4820 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4821 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4822 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4823 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4824 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4825 | /* Other custom param ranges go here... */ |
| 4826 | }; |
| 4827 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4828 | struct ec_params_charge_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4829 | uint8_t cmd; /* enum charge_state_command */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4830 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4831 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4832 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4833 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4834 | uint32_t param; /* enum charge_state_param */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4835 | } get_param; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4836 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4837 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4838 | uint32_t param; /* param to set */ |
| 4839 | uint32_t value; /* value to set */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 4840 | } set_param; |
| 4841 | } __ec_todo_packed; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4842 | uint8_t chgnum; /* Version 1 supports chgnum */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4843 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4844 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4845 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4846 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4847 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4848 | int ac; |
| 4849 | int chg_voltage; |
| 4850 | int chg_current; |
| 4851 | int chg_input_current; |
| 4852 | int batt_state_of_charge; |
| 4853 | } get_state; |
| 4854 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4855 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4856 | uint32_t value; |
| 4857 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4858 | |
| 4859 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4860 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4861 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4862 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4863 | /* |
| 4864 | * Set maximum battery charging current. |
| 4865 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4866 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 4867 | #define EC_VER_CHARGE_CURRENT_LIMIT 1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4868 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4869 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4870 | uint32_t limit; /* in mA */ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 4871 | } __ec_align4; |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 4872 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 4873 | struct ec_params_current_limit_v1 { |
| 4874 | uint32_t limit; /* in mA */ |
Tim Van Patten | cab6060 | 2023-02-24 12:27:04 -0700 | [diff] [blame] | 4875 | /* |
| 4876 | * Battery state of charge is the minimum charge percentage at which |
| 4877 | * the battery charge current limit will apply. |
| 4878 | * When not set, the limit will apply regardless of state of charge. |
| 4879 | */ |
| 4880 | uint8_t battery_soc; /* battery state of charge, 0-100 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4881 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4882 | |
| 4883 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4884 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4885 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4886 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4887 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4888 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4889 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4890 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4891 | 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] | 4892 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4893 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4894 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4895 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4896 | /* |
| 4897 | * Set maximum voltage & current of a dedicated charge port |
| 4898 | */ |
| 4899 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4900 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4901 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4902 | uint16_t current_lim; /* in mA */ |
| 4903 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4904 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4905 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 4906 | /* |
| 4907 | * Get and set charging splashscreen variables |
| 4908 | */ |
| 4909 | #define EC_CMD_CHARGESPLASH 0x00A5 |
| 4910 | |
| 4911 | enum ec_chargesplash_cmd { |
| 4912 | /* Get the current state variables */ |
| 4913 | EC_CHARGESPLASH_GET_STATE = 0, |
| 4914 | |
| 4915 | /* Indicate initialization of the display loop */ |
| 4916 | EC_CHARGESPLASH_DISPLAY_READY, |
| 4917 | |
| 4918 | /* Manually put the EC into the requested state */ |
| 4919 | EC_CHARGESPLASH_REQUEST, |
| 4920 | |
| 4921 | /* Reset all state variables */ |
| 4922 | EC_CHARGESPLASH_RESET, |
| 4923 | |
| 4924 | /* Manually trigger a lockout */ |
| 4925 | EC_CHARGESPLASH_LOCKOUT, |
| 4926 | }; |
| 4927 | |
| 4928 | struct __ec_align1 ec_params_chargesplash { |
| 4929 | /* enum ec_chargesplash_cmd */ |
| 4930 | uint8_t cmd; |
| 4931 | }; |
| 4932 | |
| 4933 | struct __ec_align1 ec_response_chargesplash { |
| 4934 | uint8_t requested; |
| 4935 | uint8_t display_initialized; |
| 4936 | uint8_t locked_out; |
| 4937 | }; |
| 4938 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4939 | /*****************************************************************************/ |
| 4940 | /* Hibernate/Deep Sleep Commands */ |
| 4941 | |
| 4942 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4943 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4944 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4945 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4946 | /* |
| 4947 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4948 | * current settings without changing them. |
| 4949 | */ |
| 4950 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4951 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4952 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4953 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4954 | /* |
| 4955 | * The current time in seconds in which the system has been in the G3 |
| 4956 | * state. This value is reset if the EC transitions out of G3. |
| 4957 | */ |
| 4958 | uint32_t time_g3; |
| 4959 | |
| 4960 | /* |
| 4961 | * The current time remaining in seconds until the EC should hibernate. |
| 4962 | * This value is also reset if the EC transitions out of G3. |
| 4963 | */ |
| 4964 | uint32_t time_remaining; |
| 4965 | |
| 4966 | /* |
| 4967 | * The current time in seconds that the EC should wait in G3 before |
| 4968 | * hibernating. |
| 4969 | */ |
| 4970 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4971 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4972 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4973 | /* Inform the EC when entering a sleep state */ |
| 4974 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4975 | |
| 4976 | enum host_sleep_event { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4977 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4978 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4979 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4980 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4981 | /* S3 suspend with additional enabled wake sources */ |
| 4982 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4983 | }; |
| 4984 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4985 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4986 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4987 | } __ec_align1; |
| 4988 | |
| 4989 | /* |
| 4990 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4991 | * transition failures |
| 4992 | */ |
| 4993 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4994 | |
| 4995 | /* Disable timeout detection for this sleep transition */ |
| 4996 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4997 | |
| 4998 | struct ec_params_host_sleep_event_v1 { |
| 4999 | /* The type of sleep being entered or exited. */ |
| 5000 | uint8_t sleep_event; |
| 5001 | |
| 5002 | /* Padding */ |
| 5003 | uint8_t reserved; |
| 5004 | union { |
| 5005 | /* Parameters that apply for suspend messages. */ |
| 5006 | struct { |
| 5007 | /* |
| 5008 | * The timeout in milliseconds between when this message |
| 5009 | * is received and when the EC will declare sleep |
| 5010 | * transition failure if the sleep signal is not |
| 5011 | * asserted. |
| 5012 | */ |
| 5013 | uint16_t sleep_timeout_ms; |
| 5014 | } suspend_params; |
| 5015 | |
| 5016 | /* No parameters for non-suspend messages. */ |
| 5017 | }; |
| 5018 | } __ec_align2; |
| 5019 | |
| 5020 | /* A timeout occurred when this bit is set */ |
| 5021 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 5022 | |
| 5023 | /* |
| 5024 | * The mask defining which bits correspond to the number of sleep transitions, |
| 5025 | * as well as the maximum number of suspend line transitions that will be |
| 5026 | * reported back to the host. |
| 5027 | */ |
| 5028 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 5029 | |
| 5030 | struct ec_response_host_sleep_event_v1 { |
| 5031 | union { |
| 5032 | /* Response fields that apply for resume messages. */ |
| 5033 | struct { |
| 5034 | /* |
| 5035 | * The number of sleep power signal transitions that |
| 5036 | * occurred since the suspend message. The high bit |
| 5037 | * indicates a timeout occurred. |
| 5038 | */ |
| 5039 | uint32_t sleep_transitions; |
| 5040 | } resume_response; |
| 5041 | |
| 5042 | /* No response fields for non-resume messages. */ |
| 5043 | }; |
| 5044 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5045 | |
| 5046 | /*****************************************************************************/ |
| 5047 | /* Device events */ |
| 5048 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 5049 | |
| 5050 | enum ec_device_event { |
| 5051 | EC_DEVICE_EVENT_TRACKPAD, |
| 5052 | EC_DEVICE_EVENT_DSP, |
| 5053 | EC_DEVICE_EVENT_WIFI, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 5054 | EC_DEVICE_EVENT_WLC, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5055 | }; |
| 5056 | |
| 5057 | enum ec_device_event_param { |
| 5058 | /* Get and clear pending device events */ |
| 5059 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 5060 | /* Get device event mask */ |
| 5061 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 5062 | /* Set device event mask */ |
| 5063 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 5064 | }; |
| 5065 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5066 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5067 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5068 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5069 | uint32_t event_mask; |
| 5070 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5071 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5072 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5073 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5074 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5075 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5076 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5077 | /*****************************************************************************/ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 5078 | /* Get s0ix counter */ |
| 5079 | #define EC_CMD_GET_S0IX_COUNTER 0x00AB |
| 5080 | |
| 5081 | /* Flag use to reset the counter */ |
| 5082 | #define EC_S0IX_COUNTER_RESET 0x1 |
| 5083 | |
| 5084 | struct ec_params_s0ix_cnt { |
| 5085 | /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */ |
| 5086 | uint32_t flags; |
| 5087 | } __ec_align4; |
| 5088 | |
| 5089 | struct ec_response_s0ix_cnt { |
| 5090 | /* Value of the s0ix_counter */ |
| 5091 | uint32_t s0ix_counter; |
| 5092 | } __ec_align4; |
| 5093 | |
| 5094 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5095 | /* Smart battery pass-through */ |
| 5096 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 5097 | /* Get / Set 16-bit smart battery registers - OBSOLETE */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5098 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 5099 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5100 | |
| 5101 | /* Get / Set string smart battery parameters |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 5102 | * formatted as SMBUS "block". - OBSOLETE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5103 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5104 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5105 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5106 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5107 | /*****************************************************************************/ |
| 5108 | /* Battery vendor parameters |
| 5109 | * |
| 5110 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 5111 | * differ between boards or batteries. On a set operation, the response |
| 5112 | * contains the actual value set, which may be rounded or clipped from the |
| 5113 | * requested value. |
| 5114 | */ |
| 5115 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5116 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5117 | |
| 5118 | enum ec_battery_vendor_param_mode { |
| 5119 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 5120 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 5121 | }; |
| 5122 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5123 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5124 | uint32_t param; |
| 5125 | uint32_t value; |
| 5126 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5127 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5128 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5129 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5130 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5131 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5132 | |
| 5133 | /*****************************************************************************/ |
| 5134 | /* |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 5135 | * Smart Battery Firmware Update Command - OBSOLETE |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5136 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5137 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5138 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5139 | /* |
| 5140 | * Entering Verified Boot Mode Command |
| 5141 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 5142 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5143 | * |
| 5144 | * EC no longer needs to know what mode vboot has entered, |
| 5145 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5146 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5147 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5148 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5149 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5150 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5151 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5152 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5153 | #define VBOOT_MODE_NORMAL 0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5154 | #define VBOOT_MODE_DEVELOPER 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5155 | #define VBOOT_MODE_RECOVERY 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5156 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5157 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5158 | /* |
| 5159 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 5160 | * certain addresses (board-specific). |
| 5161 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5162 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5163 | |
| 5164 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5165 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 5166 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 5167 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5168 | }; |
| 5169 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5170 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5171 | uint8_t subcmd; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5172 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5173 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5174 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5175 | struct ec_response_i2c_passthru_protect { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5176 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5177 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5178 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5179 | /*****************************************************************************/ |
| 5180 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5181 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5182 | * |
| 5183 | * These commands are for sending and receiving message via HDMI CEC |
| 5184 | */ |
| 5185 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5186 | #define EC_CEC_MAX_PORTS 16 |
| 5187 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5188 | #define MAX_CEC_MSG_LEN 16 |
| 5189 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5190 | /* |
| 5191 | * Helper macros for packing/unpacking cec_events. |
| 5192 | * bits[27:0] : bitmask of events from enum mkbp_cec_event |
| 5193 | * bits[31:28]: port number |
| 5194 | */ |
| 5195 | #define EC_MKBP_EVENT_CEC_PACK(events, port) \ |
| 5196 | (((events)&GENMASK(27, 0)) | (((port)&0xf) << 28)) |
| 5197 | #define EC_MKBP_EVENT_CEC_GET_EVENTS(event) ((event)&GENMASK(27, 0)) |
| 5198 | #define EC_MKBP_EVENT_CEC_GET_PORT(event) (((event) >> 28) & 0xf) |
| 5199 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5200 | /* CEC message from the AP to be written on the CEC bus */ |
| 5201 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 5202 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5203 | /** |
| 5204 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 5205 | * @msg: message content to write to the CEC bus |
| 5206 | */ |
| 5207 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5208 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5209 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5210 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5211 | /** |
| 5212 | * struct ec_params_cec_write_v1 - Message to write to the CEC bus |
| 5213 | * @port: CEC port to write the message on |
| 5214 | * @msg_len: length of msg in bytes |
| 5215 | * @msg: message content to write to the CEC bus |
| 5216 | */ |
| 5217 | struct ec_params_cec_write_v1 { |
| 5218 | uint8_t port; |
| 5219 | uint8_t msg_len; |
| 5220 | uint8_t msg[MAX_CEC_MSG_LEN]; |
| 5221 | } __ec_align1; |
| 5222 | |
| 5223 | /* CEC message read from a CEC bus reported back to the AP */ |
| 5224 | #define EC_CMD_CEC_READ_MSG 0x00B9 |
| 5225 | |
| 5226 | /** |
| 5227 | * struct ec_params_cec_read - Read a message from the CEC bus |
| 5228 | * @port: CEC port to read a message on |
| 5229 | */ |
| 5230 | struct ec_params_cec_read { |
| 5231 | uint8_t port; |
| 5232 | } __ec_align1; |
| 5233 | |
| 5234 | /** |
| 5235 | * struct ec_response_cec_read - Message read from the CEC bus |
| 5236 | * @msg_len: length of msg in bytes |
| 5237 | * @msg: message content read from the CEC bus |
| 5238 | */ |
| 5239 | struct ec_response_cec_read { |
| 5240 | uint8_t msg_len; |
| 5241 | uint8_t msg[MAX_CEC_MSG_LEN]; |
| 5242 | } __ec_align1; |
| 5243 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5244 | /* Set various CEC parameters */ |
| 5245 | #define EC_CMD_CEC_SET 0x00BA |
| 5246 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5247 | /** |
| 5248 | * struct ec_params_cec_set - CEC parameters set |
| 5249 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5250 | * @port: CEC port to set the parameter on |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5251 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 5252 | * or 1 to enable CEC functionality, in case cmd is |
| 5253 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 5254 | * address between 0 and 15 or 0xff to unregister |
| 5255 | */ |
| 5256 | struct ec_params_cec_set { |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5257 | uint8_t cmd : 4; /* enum cec_command */ |
| 5258 | uint8_t port : 4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5259 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5260 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5261 | |
| 5262 | /* Read various CEC parameters */ |
| 5263 | #define EC_CMD_CEC_GET 0x00BB |
| 5264 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5265 | /** |
| 5266 | * struct ec_params_cec_get - CEC parameters get |
| 5267 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5268 | * @port: CEC port to get the parameter on |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5269 | */ |
| 5270 | struct ec_params_cec_get { |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5271 | uint8_t cmd : 4; /* enum cec_command */ |
| 5272 | uint8_t port : 4; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5273 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5274 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5275 | /** |
| 5276 | * struct ec_response_cec_get - CEC parameters get response |
| 5277 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 5278 | * disabled or 1 if CEC functionality is enabled, |
| 5279 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 5280 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 5281 | */ |
| 5282 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5283 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5284 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5285 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5286 | /* Get the number of CEC ports */ |
| 5287 | #define EC_CMD_CEC_PORT_COUNT 0x00C1 |
| 5288 | |
| 5289 | /** |
| 5290 | * struct ec_response_cec_port_count - CEC port count response |
| 5291 | * @port_count: number of CEC ports |
| 5292 | */ |
| 5293 | struct ec_response_cec_port_count { |
| 5294 | uint8_t port_count; |
| 5295 | } __ec_align1; |
| 5296 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5297 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5298 | enum cec_command { |
| 5299 | /* CEC reading, writing and events enable */ |
| 5300 | CEC_CMD_ENABLE, |
| 5301 | /* CEC logical address */ |
| 5302 | CEC_CMD_LOGICAL_ADDRESS, |
| 5303 | }; |
| 5304 | |
| 5305 | /* Events from CEC to AP */ |
| 5306 | enum mkbp_cec_event { |
| 5307 | /* Outgoing message was acknowledged by a follower */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5308 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5309 | /* Outgoing message was not acknowledged */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5310 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5311 | /* Incoming message can be read out by AP */ |
| 5312 | EC_MKBP_CEC_HAVE_DATA = BIT(2), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5313 | }; |
| 5314 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5315 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5316 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5317 | /* Commands for audio codec. */ |
| 5318 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5319 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5320 | enum ec_codec_subcmd { |
| 5321 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 5322 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 5323 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 5324 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5325 | }; |
| 5326 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5327 | enum ec_codec_cap { |
| 5328 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 5329 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 5330 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5331 | }; |
| 5332 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5333 | enum ec_codec_shm_id { |
| 5334 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 5335 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 5336 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5337 | }; |
| 5338 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5339 | enum ec_codec_shm_type { |
| 5340 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 5341 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5342 | }; |
| 5343 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5344 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 5345 | uint8_t shm_id; |
| 5346 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5347 | }; |
| 5348 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5349 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 5350 | uint64_t phys_addr; |
| 5351 | uint32_t len; |
| 5352 | uint8_t shm_id; |
| 5353 | uint8_t reserved[3]; |
| 5354 | }; |
| 5355 | |
| 5356 | struct __ec_align4 ec_param_ec_codec { |
| 5357 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 5358 | uint8_t reserved[3]; |
| 5359 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5360 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5361 | struct ec_param_ec_codec_get_shm_addr get_shm_addr_param; |
| 5362 | 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] | 5363 | }; |
| 5364 | }; |
| 5365 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5366 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 5367 | uint32_t capabilities; |
| 5368 | }; |
| 5369 | |
| 5370 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 5371 | uint64_t phys_addr; |
| 5372 | uint32_t len; |
| 5373 | uint8_t type; |
| 5374 | uint8_t reserved[3]; |
| 5375 | }; |
| 5376 | |
| 5377 | /*****************************************************************************/ |
| 5378 | |
| 5379 | /* Commands for DMIC on audio codec. */ |
| 5380 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 5381 | |
| 5382 | enum ec_codec_dmic_subcmd { |
| 5383 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 5384 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 5385 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 5386 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 5387 | }; |
| 5388 | |
| 5389 | enum ec_codec_dmic_channel { |
| 5390 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 5391 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 5392 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 5393 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 5394 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 5395 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 5396 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 5397 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 5398 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 5399 | }; |
| 5400 | |
| 5401 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 5402 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5403 | uint8_t gain; |
| 5404 | uint8_t reserved[2]; |
| 5405 | }; |
| 5406 | |
| 5407 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 5408 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5409 | uint8_t reserved[3]; |
| 5410 | }; |
| 5411 | |
| 5412 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 5413 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 5414 | uint8_t reserved[3]; |
| 5415 | |
| 5416 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5417 | struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param; |
| 5418 | 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] | 5419 | }; |
| 5420 | }; |
| 5421 | |
| 5422 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5423 | uint8_t max_gain; |
| 5424 | }; |
| 5425 | |
| 5426 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5427 | uint8_t gain; |
| 5428 | }; |
| 5429 | |
| 5430 | /*****************************************************************************/ |
| 5431 | |
| 5432 | /* Commands for I2S RX on audio codec. */ |
| 5433 | |
| 5434 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5435 | |
| 5436 | enum ec_codec_i2s_rx_subcmd { |
| 5437 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5438 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5439 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5440 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5441 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5442 | EC_CODEC_I2S_RX_RESET = 0x5, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5443 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5444 | }; |
| 5445 | |
| 5446 | enum ec_codec_i2s_rx_sample_depth { |
| 5447 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5448 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5449 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5450 | }; |
| 5451 | |
| 5452 | enum ec_codec_i2s_rx_daifmt { |
| 5453 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5454 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5455 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5456 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5457 | }; |
| 5458 | |
| 5459 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5460 | uint8_t depth; |
| 5461 | uint8_t reserved[3]; |
| 5462 | }; |
| 5463 | |
| 5464 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5465 | uint8_t left; |
| 5466 | uint8_t right; |
| 5467 | uint8_t reserved[2]; |
| 5468 | }; |
| 5469 | |
| 5470 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5471 | uint8_t daifmt; |
| 5472 | uint8_t reserved[3]; |
| 5473 | }; |
| 5474 | |
| 5475 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5476 | uint32_t bclk; |
| 5477 | }; |
| 5478 | |
| 5479 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5480 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5481 | uint8_t reserved[3]; |
| 5482 | |
| 5483 | union { |
| 5484 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5485 | set_sample_depth_param; |
| 5486 | struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param; |
| 5487 | struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5488 | }; |
| 5489 | }; |
| 5490 | |
| 5491 | /*****************************************************************************/ |
| 5492 | /* Commands for WoV on audio codec. */ |
| 5493 | |
| 5494 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5495 | |
| 5496 | enum ec_codec_wov_subcmd { |
| 5497 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5498 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5499 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5500 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5501 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5502 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5503 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5504 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5505 | }; |
| 5506 | |
| 5507 | /* |
| 5508 | * @hash is SHA256 of the whole language model. |
| 5509 | * @total_len indicates the length of whole language model. |
| 5510 | * @offset is the cursor from the beginning of the model. |
| 5511 | * @buf is the packet buffer. |
| 5512 | * @len denotes how many bytes in the buf. |
| 5513 | */ |
| 5514 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5515 | uint8_t hash[32]; |
| 5516 | uint32_t total_len; |
| 5517 | uint32_t offset; |
| 5518 | uint8_t buf[128]; |
| 5519 | uint32_t len; |
| 5520 | }; |
| 5521 | |
| 5522 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5523 | uint8_t hash[32]; |
| 5524 | uint32_t total_len; |
| 5525 | }; |
| 5526 | |
| 5527 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5528 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5529 | uint8_t reserved[3]; |
| 5530 | |
| 5531 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5532 | struct ec_param_ec_codec_wov_set_lang set_lang_param; |
| 5533 | 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] | 5534 | }; |
| 5535 | }; |
| 5536 | |
| 5537 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5538 | uint8_t hash[32]; |
| 5539 | }; |
| 5540 | |
| 5541 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5542 | uint8_t buf[128]; |
| 5543 | uint32_t len; |
| 5544 | }; |
| 5545 | |
| 5546 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5547 | uint32_t offset; |
| 5548 | uint32_t len; |
| 5549 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5550 | |
| 5551 | /*****************************************************************************/ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5552 | /* Commands for PoE PSE controller */ |
| 5553 | |
| 5554 | #define EC_CMD_PSE 0x00C0 |
| 5555 | |
| 5556 | enum ec_pse_subcmd { |
| 5557 | EC_PSE_STATUS = 0x0, |
| 5558 | EC_PSE_ENABLE = 0x1, |
| 5559 | EC_PSE_DISABLE = 0x2, |
| 5560 | EC_PSE_SUBCMD_COUNT, |
| 5561 | }; |
| 5562 | |
| 5563 | struct __ec_align1 ec_params_pse { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5564 | uint8_t cmd; /* enum ec_pse_subcmd */ |
| 5565 | uint8_t port; /* PSE port */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5566 | }; |
| 5567 | |
| 5568 | enum ec_pse_status { |
| 5569 | EC_PSE_STATUS_DISABLED = 0x0, |
| 5570 | EC_PSE_STATUS_ENABLED = 0x1, |
| 5571 | EC_PSE_STATUS_POWERED = 0x2, |
| 5572 | }; |
| 5573 | |
| 5574 | struct __ec_align1 ec_response_pse_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5575 | uint8_t status; /* enum ec_pse_status */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5576 | }; |
| 5577 | |
| 5578 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5579 | /* System commands */ |
| 5580 | |
| 5581 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5582 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5583 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5584 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5585 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5586 | |
| 5587 | /* Command */ |
| 5588 | enum ec_reboot_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5589 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
| 5590 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
| 5591 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5592 | /* (command 3 was jump to RW-B) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5593 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
| 5594 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
| 5595 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5596 | /* |
| 5597 | * DEPRECATED: Hibernate EC and clears AP_IDLE flag. |
| 5598 | * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead. |
| 5599 | */ |
| 5600 | EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5601 | EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */ |
| 5602 | EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5603 | }; |
| 5604 | |
| 5605 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5606 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5607 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5608 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
| 5609 | #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] | 5610 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5611 | struct ec_params_reboot_ec { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5612 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5613 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5614 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5615 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5616 | /* |
| 5617 | * Get information on last EC panic. |
| 5618 | * |
| 5619 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5620 | * for details. |
| 5621 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5622 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5623 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 5624 | struct ec_params_get_panic_info_v1 { |
| 5625 | /* Do not modify PANIC_DATA_FLAG_OLD_HOSTCMD when reading panic info */ |
| 5626 | uint8_t preserve_old_hostcmd_flag; |
| 5627 | } __ec_align1; |
| 5628 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5629 | /*****************************************************************************/ |
| 5630 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5631 | * Special commands |
| 5632 | * |
| 5633 | * These do not follow the normal rules for commands. See each command for |
| 5634 | * details. |
| 5635 | */ |
| 5636 | |
| 5637 | /* |
| 5638 | * Reboot NOW |
| 5639 | * |
| 5640 | * This command will work even when the EC LPC interface is busy, because the |
| 5641 | * reboot command is processed at interrupt level. Note that when the EC |
| 5642 | * reboots, the host will reboot too, so there is no response to this command. |
| 5643 | * |
| 5644 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5645 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5646 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5647 | |
| 5648 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5649 | * Resend last response (not supported on LPC). |
| 5650 | * |
| 5651 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5652 | * there was no previous command, or the previous command's response was too |
| 5653 | * big to save. |
| 5654 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5655 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5656 | |
| 5657 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5658 | * This header byte on a command indicate version 0. Any header byte less |
| 5659 | * than this means that we are talking to an old EC which doesn't support |
| 5660 | * versioning. In that case, we assume version 0. |
| 5661 | * |
| 5662 | * Header bytes greater than this indicate a later version. For example, |
| 5663 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5664 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5665 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5666 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5667 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5668 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 5669 | /* |
| 5670 | * Memory Dump Commands |
| 5671 | * |
| 5672 | * Since the HOSTCMD response size is limited, depending on the |
| 5673 | * protocol, retrieving a memory dump is split into 3 commands. |
| 5674 | * |
| 5675 | * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries, |
| 5676 | * and the total dump size. |
| 5677 | * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given |
| 5678 | * memory dump entry index. |
| 5679 | * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given |
| 5680 | * address. The address and size must be within the bounds of the given |
| 5681 | * memory dump entry index. Each response is limited to the max response size |
| 5682 | * of the host protocol, so this may need to be called repeatedly to retrieve |
| 5683 | * the entire memory dump entry. |
| 5684 | * |
| 5685 | * Memory entries may overlap and may be out of order. |
| 5686 | * The host should check for overlaps to optimize transfer rate. |
| 5687 | */ |
| 5688 | #define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD |
| 5689 | struct ec_response_memory_dump_get_metadata { |
| 5690 | uint16_t memory_dump_entry_count; |
| 5691 | uint32_t memory_dump_total_size; |
| 5692 | } __ec_align4; |
| 5693 | |
| 5694 | #define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE |
| 5695 | struct ec_params_memory_dump_get_entry_info { |
| 5696 | uint16_t memory_dump_entry_index; |
| 5697 | } __ec_align4; |
| 5698 | |
| 5699 | struct ec_response_memory_dump_get_entry_info { |
| 5700 | uint32_t address; |
| 5701 | uint32_t size; |
| 5702 | } __ec_align4; |
| 5703 | |
| 5704 | #define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF |
| 5705 | |
| 5706 | struct ec_params_memory_dump_read_memory { |
| 5707 | uint16_t memory_dump_entry_index; |
| 5708 | uint32_t address; |
| 5709 | uint32_t size; |
| 5710 | } __ec_align4; |
| 5711 | |
| 5712 | /* |
| 5713 | * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into |
| 5714 | * host_cmd_handler_args.response and host_cmd_handler_args.response_size. |
| 5715 | */ |
| 5716 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5717 | /*****************************************************************************/ |
| 5718 | /* |
| 5719 | * PD commands |
| 5720 | * |
| 5721 | * These commands are for PD MCU communication. |
| 5722 | */ |
| 5723 | |
| 5724 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5725 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5726 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5727 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5728 | enum pd_charge_state { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5729 | /* Don't change charge state */ |
| 5730 | PD_CHARGE_NO_CHANGE = 0, |
| 5731 | |
| 5732 | /* No charging allowed */ |
| 5733 | PD_CHARGE_NONE, |
| 5734 | |
| 5735 | /* 5V charging only */ |
| 5736 | PD_CHARGE_5V, |
| 5737 | |
| 5738 | /* Charge at max voltage */ |
| 5739 | PD_CHARGE_MAX, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5740 | }; |
| 5741 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5742 | /* Status of EC being sent to PD */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5743 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5744 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5745 | struct ec_params_pd_status { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5746 | /* EC status */ |
| 5747 | uint8_t status; |
| 5748 | |
| 5749 | /* battery state of charge */ |
| 5750 | int8_t batt_soc; |
| 5751 | |
| 5752 | /* charging state (from enum pd_charge_state) */ |
| 5753 | uint8_t charge_state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5754 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5755 | |
| 5756 | /* Status of PD being sent back to EC */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5757 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5758 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5759 | #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] | 5760 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5761 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5762 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5763 | #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */ |
| 5764 | #define PD_STATUS_EC_INT_ACTIVE \ |
| 5765 | (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] | 5766 | struct ec_response_pd_status { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5767 | /* input current limit */ |
| 5768 | uint32_t curr_lim_ma; |
| 5769 | |
| 5770 | /* PD MCU status */ |
| 5771 | uint16_t status; |
| 5772 | |
| 5773 | /* active charging port */ |
| 5774 | int8_t active_charge_port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5775 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5776 | |
| 5777 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5778 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5779 | |
| 5780 | /* PD MCU host event status bits */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5781 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5782 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5783 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5784 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5785 | #define PD_EVENT_TYPEC BIT(4) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5786 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5787 | struct ec_response_host_event_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5788 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5789 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5790 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5791 | /* |
| 5792 | * Set USB type-C port role and muxes |
| 5793 | * |
| 5794 | * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands. |
| 5795 | * |
| 5796 | * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL |
| 5797 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5798 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5799 | |
| 5800 | enum usb_pd_control_role { |
| 5801 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5802 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5803 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5804 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5805 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5806 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5807 | USB_PD_CTRL_ROLE_COUNT, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5808 | }; |
| 5809 | |
| 5810 | enum usb_pd_control_mux { |
| 5811 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5812 | USB_PD_CTRL_MUX_NONE = 1, |
| 5813 | USB_PD_CTRL_MUX_USB = 2, |
| 5814 | USB_PD_CTRL_MUX_DP = 3, |
| 5815 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5816 | USB_PD_CTRL_MUX_AUTO = 5, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5817 | USB_PD_CTRL_MUX_COUNT, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5818 | }; |
| 5819 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5820 | enum usb_pd_control_swap { |
| 5821 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5822 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5823 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5824 | USB_PD_CTRL_SWAP_VCONN = 3, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5825 | USB_PD_CTRL_SWAP_COUNT, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5826 | }; |
| 5827 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5828 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5829 | uint8_t port; |
| 5830 | uint8_t role; |
| 5831 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5832 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5833 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5834 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5835 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5836 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5837 | #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] | 5838 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5839 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5840 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5841 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5842 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5843 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5844 | #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] | 5845 | /* Partner unconstrained power */ |
| 5846 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5847 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5848 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5849 | uint8_t enabled; |
| 5850 | uint8_t role; |
| 5851 | uint8_t polarity; |
| 5852 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5853 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5854 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5855 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5856 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5857 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5858 | uint8_t polarity; |
| 5859 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5860 | } __ec_align1; |
| 5861 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5862 | /* Possible port partner connections based on CC line states */ |
| 5863 | enum pd_cc_states { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5864 | PD_CC_NONE = 0, /* No port partner attached */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5865 | |
| 5866 | /* From DFP perspective */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5867 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
| 5868 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5869 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5870 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5871 | |
| 5872 | /* From UFP perspective */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5873 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
| 5874 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5875 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5876 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5877 | /* Active/Passive Cable */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5878 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5879 | /* Optical/Non-optical cable */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5880 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5881 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5882 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5883 | /* Active Link Uni-Direction */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5884 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 5885 | /* Retimer/Redriver cable */ |
| 5886 | #define USB_PD_CTRL_RETIMER_CABLE BIT(4) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5887 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5888 | struct ec_response_usb_pd_control_v2 { |
| 5889 | uint8_t enabled; |
| 5890 | uint8_t role; |
| 5891 | uint8_t polarity; |
| 5892 | char state[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5893 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5894 | uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ |
| 5895 | uint8_t reserved; /* Reserved for future use */ |
| 5896 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
| 5897 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
| 5898 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5899 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5900 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5901 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5902 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5903 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5904 | #define EC_USB_PD_MAX_PORTS 8 |
| 5905 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5906 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5907 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5908 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5909 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5910 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5911 | |
| 5912 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5913 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5914 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5915 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5916 | |
| 5917 | enum usb_chg_type { |
| 5918 | USB_CHG_TYPE_NONE, |
| 5919 | USB_CHG_TYPE_PD, |
| 5920 | USB_CHG_TYPE_C, |
| 5921 | USB_CHG_TYPE_PROPRIETARY, |
| 5922 | USB_CHG_TYPE_BC12_DCP, |
| 5923 | USB_CHG_TYPE_BC12_CDP, |
| 5924 | USB_CHG_TYPE_BC12_SDP, |
| 5925 | USB_CHG_TYPE_OTHER, |
| 5926 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5927 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5928 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5929 | }; |
| 5930 | enum usb_power_roles { |
| 5931 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5932 | USB_PD_PORT_POWER_SOURCE, |
| 5933 | USB_PD_PORT_POWER_SINK, |
| 5934 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5935 | }; |
| 5936 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5937 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5938 | uint16_t voltage_max; |
| 5939 | uint16_t voltage_now; |
| 5940 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5941 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5942 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5943 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5944 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5945 | uint8_t role; |
| 5946 | uint8_t type; |
| 5947 | uint8_t dualrole; |
| 5948 | uint8_t reserved1; |
| 5949 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5950 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5951 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5952 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5953 | /* |
| 5954 | * This command will return the number of USB PD charge port + the number |
| 5955 | * of dedicated port present. |
| 5956 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5957 | */ |
| 5958 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5959 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5960 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5961 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5962 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 5963 | /* |
| 5964 | * This command enable/disable dynamic PDO selection. |
| 5965 | */ |
| 5966 | #define EC_CMD_USB_PD_DPS_CONTROL 0x0106 |
| 5967 | |
| 5968 | struct ec_params_usb_pd_dps_control { |
| 5969 | uint8_t enable; |
| 5970 | } __ec_align1; |
| 5971 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5972 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5973 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5974 | |
| 5975 | enum usb_pd_fw_update_cmds { |
| 5976 | USB_PD_FW_REBOOT, |
| 5977 | USB_PD_FW_FLASH_ERASE, |
| 5978 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5979 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5980 | }; |
| 5981 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5982 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5983 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5984 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5985 | uint8_t port; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 5986 | |
| 5987 | /* Size to write in bytes */ |
| 5988 | uint32_t size; |
| 5989 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5990 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5991 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5992 | |
| 5993 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5994 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5995 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5996 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5997 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5998 | uint16_t dev_id; |
| 5999 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6000 | |
| 6001 | /* |
| 6002 | * Reserved for alignment of current_image |
| 6003 | * TODO(rspangler) but it's not aligned! |
| 6004 | * Should have been reserved[2]. |
| 6005 | */ |
| 6006 | uint8_t reserved; |
| 6007 | |
| 6008 | /* One of ec_image */ |
| 6009 | uint32_t current_image; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6010 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 6011 | |
| 6012 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6013 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 6014 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6015 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 6016 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6017 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 6018 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6019 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6020 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6021 | struct ec_params_usb_pd_discovery_entry { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6022 | uint16_t vid; /* USB-IF VID */ |
| 6023 | uint16_t pid; /* USB-IF PID */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6024 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6025 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6026 | |
| 6027 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6028 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6029 | |
| 6030 | /* Negative port parameters have special meaning */ |
| 6031 | enum usb_pd_override_ports { |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 6032 | /* |
| 6033 | * DONT_CHARGE is for all ports. Thus it's persistent across plug-in |
| 6034 | * or plug-out. |
| 6035 | */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6036 | OVERRIDE_DONT_CHARGE = -2, |
| 6037 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6038 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6039 | }; |
| 6040 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6041 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6042 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6043 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6044 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6045 | /* |
| 6046 | * Read (and delete) one entry of PD event log. |
| 6047 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 6048 | * future non-PD logs that use the same internal EC event_log. |
| 6049 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6050 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6051 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6052 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6053 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6054 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 6055 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 6056 | uint16_t data; /* type-defined data payload */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6057 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6058 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6059 | |
| 6060 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 6061 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 6062 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6063 | #define PD_LOG_SIZE_MASK 0x1f |
| 6064 | #define PD_LOG_PORT_MASK 0xe0 |
| 6065 | #define PD_LOG_PORT_SHIFT 5 |
| 6066 | #define PD_LOG_PORT_SIZE(port, size) \ |
| 6067 | (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK)) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6068 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6069 | #define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6070 | |
| 6071 | /* PD event log : entry types */ |
| 6072 | /* PD MCU events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6073 | #define PD_EVENT_MCU_BASE 0x00 |
| 6074 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0) |
| 6075 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6076 | /* Reserved for custom board event */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6077 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6078 | /* PD generic accessory events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6079 | #define PD_EVENT_ACC_BASE 0x20 |
| 6080 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0) |
| 6081 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6082 | /* PD power supply events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6083 | #define PD_EVENT_PS_BASE 0x40 |
| 6084 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6085 | /* PD video dongles events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6086 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 6087 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0) |
| 6088 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6089 | /* Returned in the "type" field, when there is no entry available */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6090 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6091 | |
| 6092 | /* |
| 6093 | * PD_EVENT_MCU_CHARGE event definition : |
| 6094 | * the payload is "struct usb_chg_measures" |
| 6095 | * the data field contains the port state flags as defined below : |
| 6096 | */ |
| 6097 | /* Port partner is a dual role device */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6098 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6099 | /* Port is the pending override port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6100 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6101 | /* Port is the override port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6102 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6103 | /* Charger type */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6104 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
| 6105 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6106 | /* Power delivery role */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6107 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6108 | |
| 6109 | /* |
| 6110 | * PD_EVENT_PS_FAULT data field flags definition : |
| 6111 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6112 | #define PS_FAULT_OCP 1 |
| 6113 | #define PS_FAULT_FAST_OCP 2 |
| 6114 | #define PS_FAULT_OVP 3 |
| 6115 | #define PS_FAULT_DISCH 4 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6116 | |
| 6117 | /* |
| 6118 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 6119 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6120 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6121 | uint8_t major; |
| 6122 | uint8_t minor; |
| 6123 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6124 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6125 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6126 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6127 | uint8_t family[2]; |
| 6128 | uint8_t chipid[2]; |
| 6129 | struct mcdp_version irom; |
| 6130 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6131 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6132 | |
| 6133 | /* struct mcdp_info field decoding */ |
| 6134 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 6135 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 6136 | |
| 6137 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6138 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6139 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6140 | uint16_t svid_idx; /* SVID index to get */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6141 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6142 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6143 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 6144 | #define VDO_MAX_SIZE 7 |
| 6145 | /* Max number of VDM data objects without VDM header */ |
| 6146 | #define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1) |
| 6147 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6148 | struct ec_params_usb_pd_get_mode_response { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6149 | uint16_t svid; /* SVID */ |
| 6150 | uint16_t opos; /* Object Position */ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 6151 | uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6152 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6153 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6154 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6155 | |
| 6156 | enum pd_mode_cmd { |
| 6157 | PD_EXIT_MODE = 0, |
| 6158 | PD_ENTER_MODE = 1, |
| 6159 | /* Not a command. Do NOT remove. */ |
| 6160 | PD_MODE_CMD_COUNT, |
| 6161 | }; |
| 6162 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6163 | struct ec_params_usb_pd_set_mode_request { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6164 | uint32_t cmd; /* enum pd_mode_cmd */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6165 | uint16_t svid; /* SVID to set */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6166 | uint8_t opos; /* Object Position */ |
| 6167 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6168 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6169 | |
| 6170 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6171 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6172 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6173 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6174 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 6175 | 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] | 6176 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6177 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6178 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6179 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6180 | |
| 6181 | enum ec_pd_control_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6182 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 6183 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 6184 | PD_RESET, /* Force reset the PD chip */ |
| 6185 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 6186 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6187 | }; |
| 6188 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6189 | struct ec_params_pd_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6190 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6191 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6192 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6193 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6194 | /* Get info about USB-C SS muxes */ |
| 6195 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 6196 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6197 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6198 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6199 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6200 | |
| 6201 | /* Flags representing mux state */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6202 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 6203 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 6204 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 6205 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 6206 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 6207 | #define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */ |
| 6208 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 6209 | #define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */ |
| 6210 | #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] | 6211 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6212 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6213 | |
| 6214 | /* USB-C Dock connected */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6215 | #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] | 6216 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6217 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6218 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6219 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6220 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6221 | #define EC_CMD_PD_CHIP_INFO 0x011B |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6222 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6223 | struct ec_params_pd_chip_info { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6224 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6225 | /* |
| 6226 | * Fetch the live chip info or hard-coded + cached chip info |
| 6227 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 6228 | * 1: live chip value for VID/PID/FW Version |
| 6229 | */ |
| 6230 | uint8_t live; |
| 6231 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6232 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6233 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6234 | uint16_t vendor_id; |
| 6235 | uint16_t product_id; |
| 6236 | uint16_t device_id; |
| 6237 | union { |
| 6238 | uint8_t fw_version_string[8]; |
| 6239 | uint64_t fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6240 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6241 | } __ec_align2; |
| 6242 | |
| 6243 | struct ec_response_pd_chip_info_v1 { |
| 6244 | uint16_t vendor_id; |
| 6245 | uint16_t product_id; |
| 6246 | uint16_t device_id; |
| 6247 | union { |
| 6248 | uint8_t fw_version_string[8]; |
| 6249 | uint64_t fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6250 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6251 | union { |
| 6252 | uint8_t min_req_fw_version_string[8]; |
| 6253 | uint64_t min_req_fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6254 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6255 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6256 | |
| 6257 | /* Run RW signature verification and get status */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6258 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6259 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6260 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6261 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6262 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6263 | |
| 6264 | /* For controlling RWSIG task */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6265 | #define EC_CMD_RWSIG_ACTION 0x011D |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6266 | |
| 6267 | enum rwsig_action { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6268 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 6269 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6270 | }; |
| 6271 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6272 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6273 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6274 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6275 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6276 | /* Run verification on a slot */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6277 | #define EC_CMD_EFS_VERIFY 0x011E |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6278 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6279 | struct ec_params_efs_verify { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6280 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6281 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6282 | |
| 6283 | /* |
| 6284 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 6285 | * type. Integers return a uint32. Strings return a string, using the response |
| 6286 | * size to determine how big it is. |
| 6287 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6288 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6289 | /* |
| 6290 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 6291 | * hardware write-protect enabled. |
| 6292 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6293 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6294 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6295 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6296 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6297 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 6298 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 6299 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6300 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
| 6301 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
| 6302 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
| 6303 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6304 | /* Second Source Factory Cache */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6305 | CBI_TAG_SSFC = 8, /* uint32_t bit field */ |
| 6306 | CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6307 | CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */ |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 6308 | |
| 6309 | /* |
| 6310 | * A uint32_t field reserved for controlling common features at runtime. |
| 6311 | * It shouldn't be used at board-level. See union ec_common_control for |
| 6312 | * the bit definitions. |
| 6313 | */ |
| 6314 | CBI_TAG_COMMON_CONTROL = 11, |
| 6315 | |
| 6316 | /* struct board_batt_params */ |
| 6317 | CBI_TAG_BATTERY_CONFIG = 12, |
| 6318 | /* CBI_TAG_BATTERY_CONFIG_1 ~ 15 will use 13 ~ 27. */ |
| 6319 | |
| 6320 | /* Last entry */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6321 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6322 | }; |
| 6323 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 6324 | union ec_common_control { |
| 6325 | struct { |
| 6326 | uint32_t bcic_enabled : 1; |
| 6327 | }; |
| 6328 | uint32_t raw_value; |
| 6329 | }; |
| 6330 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6331 | /* |
| 6332 | * Flags to control read operation |
| 6333 | * |
| 6334 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 6335 | * write was successful without reboot. |
| 6336 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6337 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6338 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6339 | struct ec_params_get_cbi { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6340 | uint32_t tag; /* enum cbi_data_tag */ |
| 6341 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6342 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6343 | |
| 6344 | /* |
| 6345 | * Flags to control write behavior. |
| 6346 | * |
| 6347 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 6348 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6349 | * 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] | 6350 | * will be initialized to zero first. |
| 6351 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6352 | #define CBI_SET_NO_SYNC BIT(0) |
| 6353 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6354 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6355 | struct ec_params_set_cbi { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6356 | uint32_t tag; /* enum cbi_data_tag */ |
| 6357 | uint32_t flag; /* CBI_SET_* */ |
| 6358 | uint32_t size; /* Data size */ |
| 6359 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6360 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6361 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6362 | /* |
| 6363 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 6364 | */ |
| 6365 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 6366 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6367 | /* EC reset causes */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6368 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 6369 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 6370 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 6371 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 6372 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 6373 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 6374 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 6375 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 6376 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 6377 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 6378 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 6379 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 6380 | #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] | 6381 | /* Some reset flags preserved from previous boot */ |
| 6382 | #define EC_RESET_FLAG_PRESERVED BIT(13) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6383 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 6384 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 6385 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 6386 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6387 | /* AP experienced a watchdog reset */ |
| 6388 | #define EC_RESET_FLAG_AP_WATCHDOG BIT(18) |
| 6389 | /* Do not select RW in EFS. This enables PD in RO for Chromebox. */ |
| 6390 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6391 | #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */ |
| 6392 | #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */ |
| 6393 | #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] | 6394 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6395 | /* |
| 6396 | * Reason codes used by the AP after a shutdown to figure out why it was reset |
| 6397 | * by the EC. These are sent in EC commands. Therefore, to maintain protocol |
| 6398 | * compatibility: |
| 6399 | * - New entries must be inserted prior to the _COUNT field |
| 6400 | * - If an existing entry is no longer in service, it must be replaced with a |
| 6401 | * RESERVED entry instead. |
| 6402 | * - The semantic meaning of an entry should not change. |
| 6403 | * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons. |
| 6404 | */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6405 | enum chipset_shutdown_reason { |
| 6406 | /* |
| 6407 | * Beginning of reset reasons. |
| 6408 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6409 | CHIPSET_RESET_BEGIN = 0, |
| 6410 | CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN, |
| 6411 | /* Custom reason defined by a board.c or baseboard.c file */ |
| 6412 | CHIPSET_RESET_BOARD_CUSTOM, |
| 6413 | /* Believe that the AP has hung */ |
| 6414 | CHIPSET_RESET_HANG_REBOOT, |
| 6415 | /* Reset by EC console command */ |
| 6416 | CHIPSET_RESET_CONSOLE_CMD, |
| 6417 | /* Reset by EC host command */ |
| 6418 | CHIPSET_RESET_HOST_CMD, |
| 6419 | /* Keyboard module reset key combination */ |
| 6420 | CHIPSET_RESET_KB_SYSRESET, |
| 6421 | /* Keyboard module warm reboot */ |
| 6422 | CHIPSET_RESET_KB_WARM_REBOOT, |
| 6423 | /* Debug module warm reboot */ |
| 6424 | CHIPSET_RESET_DBG_WARM_REBOOT, |
| 6425 | /* I cannot self-terminate. You must lower me into the steel. */ |
| 6426 | CHIPSET_RESET_AP_REQ, |
| 6427 | /* Reset as side-effect of startup sequence */ |
| 6428 | CHIPSET_RESET_INIT, |
| 6429 | /* EC detected an AP watchdog event. */ |
| 6430 | CHIPSET_RESET_AP_WATCHDOG, |
| 6431 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6432 | CHIPSET_RESET_COUNT, /* End of reset reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6433 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6434 | /* |
| 6435 | * Beginning of shutdown reasons. |
| 6436 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6437 | CHIPSET_SHUTDOWN_BEGIN = BIT(15), |
| 6438 | CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN, |
| 6439 | /* Forcing a shutdown as part of EC initialization */ |
| 6440 | CHIPSET_SHUTDOWN_INIT, |
| 6441 | /* Custom reason on a per-board basis. */ |
| 6442 | CHIPSET_SHUTDOWN_BOARD_CUSTOM, |
| 6443 | /* This is a reason to inhibit startup, not cause shut down. */ |
| 6444 | CHIPSET_SHUTDOWN_BATTERY_INHIBIT, |
| 6445 | /* A power_wait_signal is being asserted */ |
| 6446 | CHIPSET_SHUTDOWN_WAIT, |
| 6447 | /* Critical battery level. */ |
| 6448 | CHIPSET_SHUTDOWN_BATTERY_CRIT, |
| 6449 | /* Because you told me to. */ |
| 6450 | CHIPSET_SHUTDOWN_CONSOLE_CMD, |
| 6451 | /* Forcing a shutdown to effect entry to G3. */ |
| 6452 | CHIPSET_SHUTDOWN_G3, |
| 6453 | /* Force shutdown due to over-temperature. */ |
| 6454 | CHIPSET_SHUTDOWN_THERMAL, |
| 6455 | /* Force a chipset shutdown from the power button through EC */ |
| 6456 | CHIPSET_SHUTDOWN_BUTTON, |
| 6457 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6458 | CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6459 | }; |
| 6460 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6461 | struct ec_response_uptime_info { |
| 6462 | /* |
| 6463 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 6464 | * typically do not restart the EC's time_since_boot epoch. |
| 6465 | * |
| 6466 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 6467 | * sense of time, in both phase and frequency. This timebase is similar |
| 6468 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 6469 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6470 | uint32_t time_since_ec_boot_ms; |
| 6471 | |
| 6472 | /* |
| 6473 | * Number of times the AP was reset by the EC since the last EC boot. |
| 6474 | * Note that the AP may be held in reset by the EC during the initial |
| 6475 | * boot sequence, such that the very first AP boot may count as more |
| 6476 | * than one here. |
| 6477 | */ |
| 6478 | uint32_t ap_resets_since_ec_boot; |
| 6479 | |
| 6480 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6481 | * The set of flags which describe the EC's most recent reset. |
| 6482 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6483 | */ |
| 6484 | uint32_t ec_reset_flags; |
| 6485 | |
| 6486 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 6487 | struct ap_reset_log_entry { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6488 | /* See enum chipset_{reset,shutdown}_reason for details. */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6489 | uint16_t reset_cause; |
| 6490 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6491 | /* Reserved for protocol growth. */ |
| 6492 | uint16_t reserved; |
| 6493 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6494 | /* |
| 6495 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6496 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 6497 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6498 | */ |
| 6499 | uint32_t reset_time_ms; |
| 6500 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6501 | } __ec_align4; |
| 6502 | |
| 6503 | /* |
| 6504 | * Add entropy to the device secret (stored in the rollback region). |
| 6505 | * |
| 6506 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 6507 | * flash), so the commands are asynchronous. |
| 6508 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6509 | #define EC_CMD_ADD_ENTROPY 0x0122 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6510 | |
| 6511 | enum add_entropy_action { |
| 6512 | /* Add entropy to the current secret. */ |
| 6513 | ADD_ENTROPY_ASYNC = 0, |
| 6514 | /* |
| 6515 | * Add entropy, and also make sure that the previous secret is erased. |
| 6516 | * (this can be implemented by adding entropy multiple times until |
| 6517 | * all rolback blocks have been overwritten). |
| 6518 | */ |
| 6519 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 6520 | /* Read back result from the previous operation. */ |
| 6521 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6522 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6523 | |
| 6524 | struct ec_params_rollback_add_entropy { |
| 6525 | uint8_t action; |
| 6526 | } __ec_align1; |
| 6527 | |
| 6528 | /* |
| 6529 | * Perform a single read of a given ADC channel. |
| 6530 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6531 | #define EC_CMD_ADC_READ 0x0123 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6532 | |
| 6533 | struct ec_params_adc_read { |
| 6534 | uint8_t adc_channel; |
| 6535 | } __ec_align1; |
| 6536 | |
| 6537 | struct ec_response_adc_read { |
| 6538 | int32_t adc_value; |
| 6539 | } __ec_align4; |
| 6540 | |
| 6541 | /* |
| 6542 | * Read back rollback info |
| 6543 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6544 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6545 | |
| 6546 | struct ec_response_rollback_info { |
| 6547 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 6548 | int32_t rollback_min_version; |
| 6549 | int32_t rw_rollback_version; |
| 6550 | } __ec_align4; |
| 6551 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6552 | /* Issue AP reset */ |
| 6553 | #define EC_CMD_AP_RESET 0x0125 |
| 6554 | |
| 6555 | /*****************************************************************************/ |
| 6556 | /* Locate peripheral chips |
| 6557 | * |
| 6558 | * Return values: |
| 6559 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 6560 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 6561 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 6562 | */ |
| 6563 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 6564 | |
| 6565 | enum ec_chip_type { |
| 6566 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 6567 | EC_CHIP_TYPE_TCPC = 1, |
| 6568 | EC_CHIP_TYPE_COUNT, |
| 6569 | EC_CHIP_TYPE_MAX = 0xFF, |
| 6570 | }; |
| 6571 | |
| 6572 | enum ec_bus_type { |
| 6573 | EC_BUS_TYPE_I2C = 0, |
| 6574 | EC_BUS_TYPE_EMBEDDED = 1, |
| 6575 | EC_BUS_TYPE_COUNT, |
| 6576 | EC_BUS_TYPE_MAX = 0xFF, |
| 6577 | }; |
| 6578 | |
| 6579 | struct ec_i2c_info { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6580 | uint16_t port; /* Physical port for device */ |
| 6581 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6582 | }; |
| 6583 | |
| 6584 | struct ec_params_locate_chip { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6585 | uint8_t type; /* enum ec_chip_type */ |
| 6586 | uint8_t index; /* Specifies one instance of chip type */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6587 | /* Used for type specific parameters in future */ |
| 6588 | union { |
| 6589 | uint16_t reserved; |
| 6590 | }; |
| 6591 | } __ec_align2; |
| 6592 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6593 | struct ec_response_locate_chip { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6594 | uint8_t bus_type; /* enum ec_bus_type */ |
| 6595 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6596 | union { |
| 6597 | struct ec_i2c_info i2c_info; |
| 6598 | }; |
| 6599 | } __ec_align2; |
| 6600 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6601 | /* |
| 6602 | * Reboot AP on G3 |
| 6603 | * |
| 6604 | * This command is used for validation purpose, where the AP needs to be |
| 6605 | * 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] | 6606 | * wake events. |
| 6607 | * - With command version 0: |
| 6608 | * AP reboots immediately from G3 |
| 6609 | * command usage: ectool reboot_ap_on_g3 && shutdown -h now |
| 6610 | * - With command version 1: |
| 6611 | * AP reboots after the user specified delay |
| 6612 | * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6613 | */ |
| 6614 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 6615 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6616 | struct ec_params_reboot_ap_on_g3_v1 { |
| 6617 | /* configurable delay in seconds in G3 state */ |
| 6618 | uint32_t reboot_ap_at_g3_delay; |
| 6619 | } __ec_align4; |
| 6620 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6621 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6622 | /* Get PD port capabilities |
| 6623 | * |
| 6624 | * Returns the following static *capabilities* of the given port: |
| 6625 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 6626 | * future CrOS devices would ever be only a source, so the options are |
| 6627 | * sink or dual. |
| 6628 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 6629 | * believe any CrOS device would support Try.SNK, so this would be source |
| 6630 | * or none). |
| 6631 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 6632 | * for CrOS devices. |
| 6633 | */ |
| 6634 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 6635 | |
| 6636 | enum ec_pd_power_role_caps { |
| 6637 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 6638 | EC_PD_POWER_ROLE_SINK = 1, |
| 6639 | EC_PD_POWER_ROLE_DUAL = 2, |
| 6640 | }; |
| 6641 | |
| 6642 | enum ec_pd_try_power_role_caps { |
| 6643 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6644 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6645 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6646 | }; |
| 6647 | |
| 6648 | enum ec_pd_data_role_caps { |
| 6649 | EC_PD_DATA_ROLE_DFP = 0, |
| 6650 | EC_PD_DATA_ROLE_UFP = 1, |
| 6651 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6652 | }; |
| 6653 | |
| 6654 | /* From: power_manager/power_supply_properties.proto */ |
| 6655 | enum ec_pd_port_location { |
| 6656 | /* The location of the port is unknown, or there's only one port. */ |
| 6657 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6658 | |
| 6659 | /* |
| 6660 | * Various positions on the device. The first word describes the side of |
| 6661 | * the device where the port is located while the second clarifies the |
| 6662 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6663 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6664 | * device. |
| 6665 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6666 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6667 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6668 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6669 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6670 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6671 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6672 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6673 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6674 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6675 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6676 | }; |
| 6677 | |
| 6678 | struct ec_params_get_pd_port_caps { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6679 | uint8_t port; /* Which port to interrogate */ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6680 | } __ec_align1; |
| 6681 | |
| 6682 | struct ec_response_get_pd_port_caps { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6683 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6684 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6685 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6686 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6687 | } __ec_align1; |
| 6688 | |
| 6689 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6690 | /* |
| 6691 | * Button press simulation |
| 6692 | * |
| 6693 | * This command is used to simulate a button press. |
| 6694 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6695 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6696 | * |
| 6697 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6698 | */ |
| 6699 | #define EC_CMD_BUTTON 0x0129 |
| 6700 | |
| 6701 | struct ec_params_button { |
| 6702 | /* Button mask aligned to enum keyboard_button_type */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6703 | uint32_t btn_mask; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6704 | |
| 6705 | /* Duration in milliseconds button needs to be pressed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6706 | uint32_t press_ms; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6707 | } __ec_align1; |
| 6708 | |
| 6709 | enum keyboard_button_type { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6710 | KEYBOARD_BUTTON_POWER = 0, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6711 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6712 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6713 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6714 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6715 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6716 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6717 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6718 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6719 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6720 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6721 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6722 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6723 | KEYBOARD_BUTTON_COUNT, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6724 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6725 | |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6726 | /*****************************************************************************/ |
| 6727 | /* |
| 6728 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6729 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6730 | * Additionally, capability to send function codes for the same keys is |
| 6731 | * optional and acceptable. |
| 6732 | * |
| 6733 | * Note: If the top row can generate both function and action codes by |
| 6734 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6735 | * "function" or "action" codes by default. In both cases, the response |
| 6736 | * for this command will look the same. |
| 6737 | */ |
| 6738 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6739 | |
| 6740 | /* Possible values for the top row keys */ |
| 6741 | enum action_key { |
| 6742 | TK_ABSENT = 0, |
| 6743 | TK_BACK = 1, |
| 6744 | TK_FORWARD = 2, |
| 6745 | TK_REFRESH = 3, |
| 6746 | TK_FULLSCREEN = 4, |
| 6747 | TK_OVERVIEW = 5, |
| 6748 | TK_BRIGHTNESS_DOWN = 6, |
| 6749 | TK_BRIGHTNESS_UP = 7, |
| 6750 | TK_VOL_MUTE = 8, |
| 6751 | TK_VOL_DOWN = 9, |
| 6752 | TK_VOL_UP = 10, |
| 6753 | TK_SNAPSHOT = 11, |
| 6754 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6755 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6756 | TK_KBD_BKLIGHT_UP = 14, |
| 6757 | TK_PLAY_PAUSE = 15, |
| 6758 | TK_NEXT_TRACK = 16, |
| 6759 | TK_PREV_TRACK = 17, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 6760 | TK_KBD_BKLIGHT_TOGGLE = 18, |
| 6761 | TK_MICMUTE = 19, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6762 | TK_MENU = 20, |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6763 | }; |
| 6764 | |
| 6765 | /* |
| 6766 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6767 | * If this needs to change, please create a new version of the command. |
| 6768 | */ |
| 6769 | #define MAX_TOP_ROW_KEYS 15 |
| 6770 | #define MIN_TOP_ROW_KEYS 10 |
| 6771 | |
| 6772 | /* |
| 6773 | * Is the keyboard capable of sending function keys *in addition to* |
| 6774 | * action keys. This is possible for e.g. if the keyboard has a |
| 6775 | * dedicated Fn key. |
| 6776 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6777 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6778 | /* |
| 6779 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6780 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6781 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6782 | /* |
| 6783 | * Whether the keyboard has a screenlock key. |
| 6784 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6785 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6786 | |
| 6787 | struct ec_response_keybd_config { |
| 6788 | /* |
| 6789 | * Number of top row keys, excluding Esc and Screenlock. |
| 6790 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6791 | * (i.e. does not expose any tables to the kernel). |
| 6792 | */ |
| 6793 | uint8_t num_top_row_keys; |
| 6794 | |
| 6795 | /* |
| 6796 | * The action keys in the top row, in order from left to right. |
| 6797 | * The values are filled from enum action_key. Esc and Screenlock |
| 6798 | * keys are not considered part of top row keys. |
| 6799 | */ |
| 6800 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6801 | |
| 6802 | /* Capability flags */ |
| 6803 | uint8_t capabilities; |
| 6804 | |
| 6805 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6806 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6807 | /* |
| 6808 | * Configure smart discharge |
| 6809 | */ |
| 6810 | #define EC_CMD_SMART_DISCHARGE 0x012B |
| 6811 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6812 | #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6813 | |
| 6814 | /* Discharge rates when the system is in cutoff or hibernation. */ |
| 6815 | struct discharge_rate { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6816 | uint16_t cutoff; /* Discharge rate (uA) in cutoff */ |
| 6817 | uint16_t hibern; /* Discharge rate (uA) in hibernation */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6818 | }; |
| 6819 | |
| 6820 | struct smart_discharge_zone { |
| 6821 | /* When the capacity (mAh) goes below this, EC cuts off the battery. */ |
| 6822 | int cutoff; |
| 6823 | /* When the capacity (mAh) is below this, EC stays up. */ |
| 6824 | int stayup; |
| 6825 | }; |
| 6826 | |
| 6827 | struct ec_params_smart_discharge { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6828 | uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6829 | /* |
| 6830 | * Desired hours for the battery to survive before reaching 0%. Set to |
| 6831 | * zero to disable smart discharging. That is, the system hibernates as |
| 6832 | * soon as the G3 idle timer expires. |
| 6833 | */ |
| 6834 | uint16_t hours_to_zero; |
| 6835 | /* Set both to zero to keep the current rates. */ |
| 6836 | struct discharge_rate drate; |
| 6837 | }; |
| 6838 | |
| 6839 | struct ec_response_smart_discharge { |
| 6840 | uint16_t hours_to_zero; |
| 6841 | struct discharge_rate drate; |
| 6842 | struct smart_discharge_zone dzone; |
| 6843 | }; |
| 6844 | |
| 6845 | /*****************************************************************************/ |
| 6846 | /* Voltage regulator controls */ |
| 6847 | |
| 6848 | /* |
| 6849 | * Get basic info of voltage regulator for given index. |
| 6850 | * |
| 6851 | * Returns the regulator name and supported voltage list in mV. |
| 6852 | */ |
| 6853 | #define EC_CMD_REGULATOR_GET_INFO 0x012C |
| 6854 | |
| 6855 | /* Maximum length of regulator name */ |
| 6856 | #define EC_REGULATOR_NAME_MAX_LEN 16 |
| 6857 | |
| 6858 | /* Maximum length of the supported voltage list. */ |
| 6859 | #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 |
| 6860 | |
| 6861 | struct ec_params_regulator_get_info { |
| 6862 | uint32_t index; |
| 6863 | } __ec_align4; |
| 6864 | |
| 6865 | struct ec_response_regulator_get_info { |
| 6866 | char name[EC_REGULATOR_NAME_MAX_LEN]; |
| 6867 | uint16_t num_voltages; |
| 6868 | uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; |
| 6869 | } __ec_align2; |
| 6870 | |
| 6871 | /* |
| 6872 | * Configure the regulator as enabled / disabled. |
| 6873 | */ |
| 6874 | #define EC_CMD_REGULATOR_ENABLE 0x012D |
| 6875 | |
| 6876 | struct ec_params_regulator_enable { |
| 6877 | uint32_t index; |
| 6878 | uint8_t enable; |
| 6879 | } __ec_align4; |
| 6880 | |
| 6881 | /* |
| 6882 | * Query if the regulator is enabled. |
| 6883 | * |
| 6884 | * Returns 1 if the regulator is enabled, 0 if not. |
| 6885 | */ |
| 6886 | #define EC_CMD_REGULATOR_IS_ENABLED 0x012E |
| 6887 | |
| 6888 | struct ec_params_regulator_is_enabled { |
| 6889 | uint32_t index; |
| 6890 | } __ec_align4; |
| 6891 | |
| 6892 | struct ec_response_regulator_is_enabled { |
| 6893 | uint8_t enabled; |
| 6894 | } __ec_align1; |
| 6895 | |
| 6896 | /* |
| 6897 | * Set voltage for the voltage regulator within the range specified. |
| 6898 | * |
| 6899 | * The driver should select the voltage in range closest to min_mv. |
| 6900 | * |
| 6901 | * Also note that this might be called before the regulator is enabled, and the |
| 6902 | * setting should be in effect after the regulator is enabled. |
| 6903 | */ |
| 6904 | #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F |
| 6905 | |
| 6906 | struct ec_params_regulator_set_voltage { |
| 6907 | uint32_t index; |
| 6908 | uint32_t min_mv; |
| 6909 | uint32_t max_mv; |
| 6910 | } __ec_align4; |
| 6911 | |
| 6912 | /* |
| 6913 | * Get the currently configured voltage for the voltage regulator. |
| 6914 | * |
| 6915 | * Note that this might be called before the regulator is enabled, and this |
| 6916 | * should return the configured output voltage if the regulator is enabled. |
| 6917 | */ |
| 6918 | #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 |
| 6919 | |
| 6920 | struct ec_params_regulator_get_voltage { |
| 6921 | uint32_t index; |
| 6922 | } __ec_align4; |
| 6923 | |
| 6924 | struct ec_response_regulator_get_voltage { |
| 6925 | uint32_t voltage_mv; |
| 6926 | } __ec_align4; |
| 6927 | |
| 6928 | /* |
| 6929 | * Gather all discovery information for the given port and partner type. |
| 6930 | * |
| 6931 | * Note that if discovery has not yet completed, only the currently completed |
| 6932 | * responses will be filled in. If the discovery data structures are changed |
| 6933 | * in the process of the command running, BUSY will be returned. |
| 6934 | * |
| 6935 | * VDO field sizes are set to the maximum possible number of VDOs a VDM may |
| 6936 | * contain, while the number of SVIDs here is selected to fit within the PROTO2 |
| 6937 | * maximum parameter size. |
| 6938 | */ |
| 6939 | #define EC_CMD_TYPEC_DISCOVERY 0x0131 |
| 6940 | |
| 6941 | enum typec_partner_type { |
| 6942 | TYPEC_PARTNER_SOP = 0, |
| 6943 | TYPEC_PARTNER_SOP_PRIME = 1, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6944 | TYPEC_PARTNER_SOP_PRIME_PRIME = 2, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6945 | }; |
| 6946 | |
| 6947 | struct ec_params_typec_discovery { |
| 6948 | uint8_t port; |
| 6949 | uint8_t partner_type; /* enum typec_partner_type */ |
| 6950 | } __ec_align1; |
| 6951 | |
| 6952 | struct svid_mode_info { |
| 6953 | uint16_t svid; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6954 | uint16_t mode_count; /* Number of modes partner sent */ |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 6955 | uint32_t mode_vdo[VDO_MAX_OBJECTS]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6956 | }; |
| 6957 | |
| 6958 | struct ec_response_typec_discovery { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6959 | uint8_t identity_count; /* Number of identity VDOs partner sent */ |
| 6960 | uint8_t svid_count; /* Number of SVIDs partner sent */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6961 | uint16_t reserved; |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 6962 | uint32_t discovery_vdo[VDO_MAX_OBJECTS]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6963 | struct svid_mode_info svids[0]; |
| 6964 | } __ec_align1; |
| 6965 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6966 | /* USB Type-C commands for AP-controlled device policy. */ |
| 6967 | #define EC_CMD_TYPEC_CONTROL 0x0132 |
| 6968 | |
| 6969 | enum typec_control_command { |
| 6970 | TYPEC_CONTROL_COMMAND_EXIT_MODES, |
| 6971 | TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6972 | TYPEC_CONTROL_COMMAND_ENTER_MODE, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6973 | TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6974 | TYPEC_CONTROL_COMMAND_USB_MUX_SET, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6975 | TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE, |
| 6976 | TYPEC_CONTROL_COMMAND_SEND_VDM_REQ, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6977 | }; |
| 6978 | |
| 6979 | /* Modes (USB or alternate) that a type-C port may enter. */ |
| 6980 | enum typec_mode { |
| 6981 | TYPEC_MODE_DP, |
| 6982 | TYPEC_MODE_TBT, |
| 6983 | TYPEC_MODE_USB4, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6984 | }; |
| 6985 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6986 | /* Replies the AP may specify to the TBT EnterMode command as a UFP */ |
| 6987 | enum typec_tbt_ufp_reply { |
| 6988 | TYPEC_TBT_UFP_REPLY_NAK, |
| 6989 | TYPEC_TBT_UFP_REPLY_ACK, |
| 6990 | }; |
| 6991 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6992 | #define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF |
| 6993 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6994 | struct typec_usb_mux_set { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 6995 | /* Index of the mux to set in the chain */ |
| 6996 | uint8_t mux_index; |
| 6997 | |
| 6998 | /* USB_PD_MUX_*-encoded USB mux state to set */ |
| 6999 | uint8_t mux_flags; |
| 7000 | } __ec_align1; |
| 7001 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7002 | struct typec_vdm_req { |
| 7003 | /* VDM data, including VDM header */ |
| 7004 | uint32_t vdm_data[VDO_MAX_SIZE]; |
| 7005 | /* Number of 32-bit fields filled in */ |
| 7006 | uint8_t vdm_data_objects; |
| 7007 | /* Partner to address - see enum typec_partner_type */ |
| 7008 | uint8_t partner_type; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7009 | } __ec_align1; |
| 7010 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7011 | struct ec_params_typec_control { |
| 7012 | uint8_t port; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7013 | uint8_t command; /* enum typec_control_command */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7014 | uint16_t reserved; |
| 7015 | |
| 7016 | /* |
| 7017 | * This section will be interpreted based on |command|. Define a |
| 7018 | * placeholder structure to avoid having to increase the size and bump |
| 7019 | * the command version when adding new sub-commands. |
| 7020 | */ |
| 7021 | union { |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7022 | /* Used for CLEAR_EVENTS */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7023 | uint32_t clear_events_mask; |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7024 | /* Used for ENTER_MODE - enum typec_mode */ |
| 7025 | uint8_t mode_to_enter; |
| 7026 | /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */ |
| 7027 | uint8_t tbt_ufp_reply; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7028 | /* Used for USB_MUX_SET */ |
| 7029 | struct typec_usb_mux_set mux_params; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7030 | /* Used for BIST_SHARE_MODE */ |
| 7031 | uint8_t bist_share_mode; |
| 7032 | /* Used for VMD_REQ */ |
| 7033 | struct typec_vdm_req vdm_req_params; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7034 | uint8_t placeholder[128]; |
| 7035 | }; |
| 7036 | } __ec_align1; |
| 7037 | |
| 7038 | /* |
| 7039 | * Gather all status information for a port. |
| 7040 | * |
| 7041 | * Note: this covers many of the return fields from the deprecated |
| 7042 | * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the |
| 7043 | * discovery data. The "enum pd_cc_states" is defined with the deprecated |
| 7044 | * EC_CMD_USB_PD_CONTROL command. |
| 7045 | * |
| 7046 | * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7047 | */ |
| 7048 | #define EC_CMD_TYPEC_STATUS 0x0133 |
| 7049 | |
| 7050 | /* |
| 7051 | * Power role. |
| 7052 | * |
| 7053 | * Note this is also used for PD header creation, and values align to those in |
| 7054 | * the Power Delivery Specification Revision 3.0 (See |
| 7055 | * 6.2.1.1.4 Port Power Role). |
| 7056 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7057 | enum pd_power_role { |
| 7058 | PD_ROLE_SINK = 0, |
| 7059 | PD_ROLE_SOURCE = 1, |
| 7060 | }; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7061 | |
| 7062 | /* |
| 7063 | * Data role. |
| 7064 | * |
| 7065 | * Note this is also used for PD header creation, and the first two values |
| 7066 | * align to those in the Power Delivery Specification Revision 3.0 (See |
| 7067 | * 6.2.1.1.6 Port Data Role). |
| 7068 | */ |
| 7069 | enum pd_data_role { |
| 7070 | PD_ROLE_UFP = 0, |
| 7071 | PD_ROLE_DFP = 1, |
| 7072 | PD_ROLE_DISCONNECTED = 2, |
| 7073 | }; |
| 7074 | |
| 7075 | enum pd_vconn_role { |
| 7076 | PD_ROLE_VCONN_OFF = 0, |
| 7077 | PD_ROLE_VCONN_SRC = 1, |
| 7078 | }; |
| 7079 | |
| 7080 | /* |
| 7081 | * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, |
| 7082 | * regardless of whether a debug accessory is connected. |
| 7083 | */ |
| 7084 | enum tcpc_cc_polarity { |
| 7085 | /* |
| 7086 | * _CCx: is used to indicate the polarity while not connected to |
| 7087 | * a Debug Accessory. Only one CC line will assert a resistor and |
| 7088 | * the other will be open. |
| 7089 | */ |
| 7090 | POLARITY_CC1 = 0, |
| 7091 | POLARITY_CC2 = 1, |
| 7092 | |
| 7093 | /* |
| 7094 | * _CCx_DTS is used to indicate the polarity while connected to a |
| 7095 | * SRC Debug Accessory. Assert resistors on both lines. |
| 7096 | */ |
| 7097 | POLARITY_CC1_DTS = 2, |
| 7098 | POLARITY_CC2_DTS = 3, |
| 7099 | |
| 7100 | /* |
| 7101 | * The current TCPC code relies on these specific POLARITY values. |
| 7102 | * Adding in a check to verify if the list grows for any reason |
| 7103 | * that this will give a hint that other places need to be |
| 7104 | * adjusted. |
| 7105 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7106 | POLARITY_COUNT, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7107 | }; |
| 7108 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7109 | #define MODE_DP_PIN_A BIT(0) |
| 7110 | #define MODE_DP_PIN_B BIT(1) |
| 7111 | #define MODE_DP_PIN_C BIT(2) |
| 7112 | #define MODE_DP_PIN_D BIT(3) |
| 7113 | #define MODE_DP_PIN_E BIT(4) |
| 7114 | #define MODE_DP_PIN_F BIT(5) |
| 7115 | #define MODE_DP_PIN_ALL GENMASK(5, 0) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7116 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7117 | #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) |
| 7118 | #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) |
| 7119 | #define PD_STATUS_EVENT_HARD_RESET BIT(2) |
| 7120 | #define PD_STATUS_EVENT_DISCONNECTED BIT(3) |
| 7121 | #define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4) |
| 7122 | #define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5) |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7123 | #define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6) |
| 7124 | #define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7) |
| 7125 | #define PD_STATUS_EVENT_VDM_ATTENTION BIT(8) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7126 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7127 | /* |
| 7128 | * Encode and decode for BCD revision response |
| 7129 | * |
| 7130 | * Note: the major revision set is written assuming that the value given is the |
| 7131 | * Specification Revision from the PD header, which currently only maps to PD |
| 7132 | * 1.0-3.0 with the major revision being one greater than the binary value. |
| 7133 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7134 | #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12) |
| 7135 | #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF) |
| 7136 | #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7137 | |
| 7138 | /* |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7139 | * Encode revision from partner RMDO |
| 7140 | * |
| 7141 | * Unlike the specification revision given in the PD header, specification and |
| 7142 | * version information returned in the revision message data object (RMDO) is |
| 7143 | * not offset. |
| 7144 | */ |
| 7145 | #define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12) |
| 7146 | #define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8) |
| 7147 | #define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4) |
| 7148 | #define PD_STATUS_RMDO_VER_SET_MINOR(r) (r) |
| 7149 | |
| 7150 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7151 | * Decode helpers for Source and Sink Capability PDOs |
| 7152 | * |
| 7153 | * Note: The Power Delivery Specification should be considered the ultimate |
| 7154 | * source of truth on the decoding of these PDOs |
| 7155 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7156 | #define PDO_TYPE_FIXED (0 << 30) |
| 7157 | #define PDO_TYPE_BATTERY (1 << 30) |
| 7158 | #define PDO_TYPE_VARIABLE (2 << 30) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7159 | #define PDO_TYPE_AUGMENTED (3 << 30) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7160 | #define PDO_TYPE_MASK (3 << 30) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7161 | |
| 7162 | /* |
| 7163 | * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0 |
| 7164 | * |
| 7165 | * <31:30> : Fixed Supply |
| 7166 | * <29> : Dual-Role Power |
| 7167 | * <28> : SNK/SRC dependent |
| 7168 | * <27> : Unconstrained Power |
| 7169 | * <26> : USB Communications Capable |
| 7170 | * <25> : Dual-Role Data |
| 7171 | * <24:20> : SNK/SRC dependent |
| 7172 | * <19:10> : Voltage in 50mV Units |
| 7173 | * <9:0> : Maximum Current in 10mA units |
| 7174 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7175 | #define PDO_FIXED_DUAL_ROLE BIT(29) |
| 7176 | #define PDO_FIXED_UNCONSTRAINED BIT(27) |
| 7177 | #define PDO_FIXED_COMM_CAP BIT(26) |
| 7178 | #define PDO_FIXED_DATA_SWAP BIT(25) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7179 | #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7180 | #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7181 | #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7182 | |
| 7183 | /* |
| 7184 | * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0 |
| 7185 | * |
| 7186 | * <31:30> : Battery |
| 7187 | * <29:20> : Maximum Voltage in 50mV units |
| 7188 | * <19:10> : Minimum Voltage in 50mV units |
| 7189 | * <9:0> : Maximum Allowable Power in 250mW units |
| 7190 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7191 | #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 7192 | #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7193 | #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7194 | |
| 7195 | /* |
| 7196 | * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0 |
| 7197 | * |
| 7198 | * <31:30> : Variable Supply (non-Battery) |
| 7199 | * <29:20> : Maximum Voltage in 50mV units |
| 7200 | * <19:10> : Minimum Voltage in 50mV units |
| 7201 | * <9:0> : Operational Current in 10mA units |
| 7202 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7203 | #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 7204 | #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7205 | #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7206 | |
| 7207 | /* |
| 7208 | * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0 |
| 7209 | * |
| 7210 | * Note this type is reserved in PD 2.0, and only one type of APDO is |
| 7211 | * supported as of the cited version. |
| 7212 | * |
| 7213 | * <31:30> : Augmented Power Data Object |
| 7214 | * <29:28> : Programmable Power Supply |
| 7215 | * <27> : PPS Power Limited |
| 7216 | * <26:25> : Reserved |
| 7217 | * <24:17> : Maximum Voltage in 100mV increments |
| 7218 | * <16> : Reserved |
| 7219 | * <15:8> : Minimum Voltage in 100mV increments |
| 7220 | * <7> : Reserved |
| 7221 | * <6:0> : Maximum Current in 50mA increments |
| 7222 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7223 | #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100) |
| 7224 | #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100) |
| 7225 | #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7226 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7227 | struct ec_params_typec_status { |
| 7228 | uint8_t port; |
| 7229 | } __ec_align1; |
| 7230 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 7231 | /* |
| 7232 | * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1. |
| 7233 | * If you need to support old ECs who speak only v0, use |
| 7234 | * ec_response_typec_status_v0 instead. They're binary-compatible. |
| 7235 | */ |
| 7236 | struct ec_response_typec_status /* DEPRECATED */ { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7237 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 7238 | uint8_t dev_connected; /* Device connected - bool */ |
| 7239 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 7240 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7241 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7242 | uint8_t power_role; /* enum pd_power_role */ |
| 7243 | uint8_t data_role; /* enum pd_data_role */ |
| 7244 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 7245 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7246 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7247 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 7248 | uint8_t cc_state; /* enum pd_cc_states */ |
| 7249 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 7250 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7251 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7252 | char tc_state[32]; /* TC state name */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7253 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7254 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7255 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7256 | /* |
| 7257 | * BCD PD revisions for partners |
| 7258 | * |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7259 | * The format has the PD major revision in the upper nibble, and the PD |
| 7260 | * minor revision in the next nibble. The following two nibbles hold the |
| 7261 | * major and minor specification version. If a partner does not support |
| 7262 | * the Revision message, only the major revision will be given. |
| 7263 | * 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] | 7264 | * |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7265 | * 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] | 7266 | */ |
| 7267 | uint16_t sop_revision; |
| 7268 | uint16_t sop_prime_revision; |
| 7269 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7270 | 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] | 7271 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7272 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7273 | } __ec_align1; |
| 7274 | |
Caveh Jalali | 839ada1 | 2022-10-31 23:16:48 -0700 | [diff] [blame] | 7275 | struct cros_ec_typec_status { |
| 7276 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 7277 | uint8_t dev_connected; /* Device connected - bool */ |
| 7278 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 7279 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
| 7280 | |
| 7281 | uint8_t power_role; /* enum pd_power_role */ |
| 7282 | uint8_t data_role; /* enum pd_data_role */ |
| 7283 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 7284 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
| 7285 | |
| 7286 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 7287 | uint8_t cc_state; /* enum pd_cc_states */ |
| 7288 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 7289 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
| 7290 | |
| 7291 | char tc_state[32]; /* TC state name */ |
| 7292 | |
| 7293 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
| 7294 | |
| 7295 | /* |
| 7296 | * BCD PD revisions for partners |
| 7297 | * |
| 7298 | * The format has the PD major revision in the upper nibble, and the PD |
| 7299 | * minor revision in the next nibble. The following two nibbles hold the |
| 7300 | * major and minor specification version. If a partner does not support |
| 7301 | * the Revision message, only the major revision will be given. |
| 7302 | * ex. PD Revision 3.2 Version 1.9 would map to 0x3219 |
| 7303 | * |
| 7304 | * PD revision/version will be 0 if no PD device is connected. |
| 7305 | */ |
| 7306 | uint16_t sop_revision; |
| 7307 | uint16_t sop_prime_revision; |
| 7308 | } __ec_align1; |
| 7309 | |
| 7310 | struct ec_response_typec_status_v0 { |
| 7311 | struct cros_ec_typec_status typec_status; |
| 7312 | uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 7313 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
| 7314 | } __ec_align1; |
| 7315 | |
| 7316 | struct ec_response_typec_status_v1 { |
| 7317 | struct cros_ec_typec_status typec_status; |
| 7318 | uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */ |
| 7319 | uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */ |
| 7320 | } __ec_align1; |
| 7321 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7322 | /** |
| 7323 | * Get the number of peripheral charge ports |
| 7324 | */ |
| 7325 | #define EC_CMD_PCHG_COUNT 0x0134 |
| 7326 | |
| 7327 | #define EC_PCHG_MAX_PORTS 8 |
| 7328 | |
| 7329 | struct ec_response_pchg_count { |
| 7330 | uint8_t port_count; |
| 7331 | } __ec_align1; |
| 7332 | |
| 7333 | /** |
| 7334 | * Get the status of a peripheral charge port |
| 7335 | */ |
| 7336 | #define EC_CMD_PCHG 0x0135 |
| 7337 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7338 | /* For v1 and v2 */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7339 | struct ec_params_pchg { |
| 7340 | uint8_t port; |
| 7341 | } __ec_align1; |
| 7342 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7343 | struct ec_params_pchg_v3 { |
| 7344 | uint8_t port; |
| 7345 | /* Below are new in v3. */ |
| 7346 | uint8_t reserved1; |
| 7347 | uint8_t reserved2; |
| 7348 | uint8_t reserved3; |
| 7349 | /* Errors acked by the host (thus to be cleared) */ |
| 7350 | uint32_t error; |
| 7351 | } __ec_align1; |
| 7352 | |
| 7353 | /* For v1 */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7354 | struct ec_response_pchg { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7355 | uint32_t error; /* enum pchg_error */ |
| 7356 | uint8_t state; /* enum pchg_state state */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7357 | uint8_t battery_percentage; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7358 | uint8_t unused0; |
| 7359 | uint8_t unused1; |
| 7360 | /* Fields added in version 1 */ |
| 7361 | uint32_t fw_version; |
| 7362 | uint32_t dropped_event_count; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7363 | } __ec_align4; |
| 7364 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7365 | /* For v2 and v3 */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7366 | struct ec_response_pchg_v2 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7367 | uint32_t error; /* enum pchg_error */ |
| 7368 | uint8_t state; /* enum pchg_state state */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7369 | uint8_t battery_percentage; |
| 7370 | uint8_t unused0; |
| 7371 | uint8_t unused1; |
| 7372 | /* Fields added in version 1 */ |
| 7373 | uint32_t fw_version; |
| 7374 | uint32_t dropped_event_count; |
| 7375 | /* Fields added in version 2 */ |
| 7376 | uint32_t dropped_host_event_count; |
| 7377 | } __ec_align4; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7378 | |
| 7379 | enum pchg_state { |
| 7380 | /* Charger is reset and not initialized. */ |
| 7381 | PCHG_STATE_RESET = 0, |
| 7382 | /* Charger is initialized or disabled. */ |
| 7383 | PCHG_STATE_INITIALIZED, |
| 7384 | /* Charger is enabled and ready to detect a device. */ |
| 7385 | PCHG_STATE_ENABLED, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7386 | /* Device is in proximity. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7387 | PCHG_STATE_DETECTED, |
| 7388 | /* Device is being charged. */ |
| 7389 | PCHG_STATE_CHARGING, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7390 | /* Device is fully charged. It implies DETECTED (& not charging). */ |
| 7391 | PCHG_STATE_FULL, |
| 7392 | /* In download (a.k.a. firmware update) mode */ |
| 7393 | PCHG_STATE_DOWNLOAD, |
| 7394 | /* In download mode. Ready for receiving data. */ |
| 7395 | PCHG_STATE_DOWNLOADING, |
| 7396 | /* Device is ready for data communication. */ |
| 7397 | PCHG_STATE_CONNECTED, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7398 | /* Charger is in Built-In Self Test mode. */ |
| 7399 | PCHG_STATE_BIST, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7400 | /* Put no more entry below */ |
| 7401 | PCHG_STATE_COUNT, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7402 | }; |
| 7403 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7404 | /* clang-format off */ |
| 7405 | #define EC_PCHG_STATE_TEXT \ |
| 7406 | { \ |
| 7407 | [PCHG_STATE_RESET] = "RESET", \ |
| 7408 | [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ |
| 7409 | [PCHG_STATE_ENABLED] = "ENABLED", \ |
| 7410 | [PCHG_STATE_DETECTED] = "DETECTED", \ |
| 7411 | [PCHG_STATE_CHARGING] = "CHARGING", \ |
| 7412 | [PCHG_STATE_FULL] = "FULL", \ |
| 7413 | [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \ |
| 7414 | [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \ |
| 7415 | [PCHG_STATE_CONNECTED] = "CONNECTED", \ |
| 7416 | [PCHG_STATE_BIST] = "BIST", \ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7417 | } |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7418 | /* clang-format on */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7419 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7420 | /** |
| 7421 | * Update firmware of peripheral chip |
| 7422 | */ |
| 7423 | #define EC_CMD_PCHG_UPDATE 0x0136 |
| 7424 | |
| 7425 | /* Port number is encoded in bit[28:31]. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7426 | #define EC_MKBP_PCHG_PORT_SHIFT 28 |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7427 | /* Utility macros for converting MKBP event <-> port number. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7428 | #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf) |
| 7429 | #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] | 7430 | /* Utility macro for extracting event bits. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7431 | #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] | 7432 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7433 | #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0) |
| 7434 | #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1) |
| 7435 | #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2) |
| 7436 | #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3) |
| 7437 | #define EC_MKBP_PCHG_DEVICE_EVENT BIT(4) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7438 | |
| 7439 | enum ec_pchg_update_cmd { |
| 7440 | /* Reset chip to normal mode. */ |
| 7441 | EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0, |
| 7442 | /* Reset and put a chip in update (a.k.a. download) mode. */ |
| 7443 | EC_PCHG_UPDATE_CMD_OPEN, |
| 7444 | /* Write a block of data containing FW image. */ |
| 7445 | EC_PCHG_UPDATE_CMD_WRITE, |
| 7446 | /* Close update session. */ |
| 7447 | EC_PCHG_UPDATE_CMD_CLOSE, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7448 | /* Reset chip (without mode change). */ |
| 7449 | EC_PCHG_UPDATE_CMD_RESET, |
| 7450 | /* Enable pass-through mode. */ |
| 7451 | EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7452 | /* End of commands */ |
| 7453 | EC_PCHG_UPDATE_CMD_COUNT, |
| 7454 | }; |
| 7455 | |
| 7456 | struct ec_params_pchg_update { |
| 7457 | /* PCHG port number */ |
| 7458 | uint8_t port; |
| 7459 | /* enum ec_pchg_update_cmd */ |
| 7460 | uint8_t cmd; |
| 7461 | /* Padding */ |
| 7462 | uint8_t reserved0; |
| 7463 | uint8_t reserved1; |
| 7464 | /* Version of new firmware */ |
| 7465 | uint32_t version; |
| 7466 | /* CRC32 of new firmware */ |
| 7467 | uint32_t crc32; |
| 7468 | /* Address in chip memory where <data> is written to */ |
| 7469 | uint32_t addr; |
| 7470 | /* Size of <data> */ |
| 7471 | uint32_t size; |
| 7472 | /* Partial data of new firmware */ |
| 7473 | uint8_t data[]; |
| 7474 | } __ec_align4; |
| 7475 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7476 | BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT < |
| 7477 | BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8)); |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7478 | |
| 7479 | struct ec_response_pchg_update { |
| 7480 | /* Block size */ |
| 7481 | uint32_t block_size; |
| 7482 | } __ec_align4; |
| 7483 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7484 | #define EC_CMD_DISPLAY_SOC 0x0137 |
| 7485 | |
| 7486 | struct ec_response_display_soc { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7487 | /* Display charge in 10ths of a % (1000=100.0%) */ |
| 7488 | int16_t display_soc; |
| 7489 | /* Full factor in 10ths of a % (1000=100.0%) */ |
| 7490 | int16_t full_factor; |
| 7491 | /* Shutdown SoC in 10ths of a % (1000=100.0%) */ |
| 7492 | int16_t shutdown_soc; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7493 | } __ec_align2; |
| 7494 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7495 | #define EC_CMD_SET_BASE_STATE 0x0138 |
| 7496 | |
| 7497 | struct ec_params_set_base_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7498 | uint8_t cmd; /* enum ec_set_base_state_cmd */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7499 | } __ec_align1; |
| 7500 | |
| 7501 | enum ec_set_base_state_cmd { |
| 7502 | EC_SET_BASE_STATE_DETACH = 0, |
| 7503 | EC_SET_BASE_STATE_ATTACH, |
| 7504 | EC_SET_BASE_STATE_RESET, |
| 7505 | }; |
| 7506 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7507 | #define EC_CMD_I2C_CONTROL 0x0139 |
| 7508 | |
| 7509 | /* Subcommands for I2C control */ |
| 7510 | |
| 7511 | enum ec_i2c_control_command { |
| 7512 | EC_I2C_CONTROL_GET_SPEED, |
| 7513 | EC_I2C_CONTROL_SET_SPEED, |
| 7514 | }; |
| 7515 | |
| 7516 | #define EC_I2C_CONTROL_SPEED_UNKNOWN 0 |
| 7517 | |
| 7518 | struct ec_params_i2c_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7519 | uint8_t port; /* I2C port number */ |
| 7520 | uint8_t cmd; /* enum ec_i2c_control_command */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7521 | union { |
| 7522 | uint16_t speed_khz; |
| 7523 | } cmd_params; |
| 7524 | } __ec_align_size1; |
| 7525 | |
| 7526 | struct ec_response_i2c_control { |
| 7527 | union { |
| 7528 | uint16_t speed_khz; |
| 7529 | } cmd_response; |
| 7530 | } __ec_align_size1; |
| 7531 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7532 | #define EC_CMD_RGBKBD_SET_COLOR 0x013A |
| 7533 | #define EC_CMD_RGBKBD 0x013B |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7534 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7535 | #define EC_RGBKBD_MAX_KEY_COUNT 128 |
| 7536 | #define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF |
| 7537 | #define EC_RGBKBD_MAX_SCALE 0xFF |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7538 | |
| 7539 | enum rgbkbd_state { |
| 7540 | /* RGB keyboard is reset and not initialized. */ |
| 7541 | RGBKBD_STATE_RESET = 0, |
| 7542 | /* RGB keyboard is initialized but not enabled. */ |
| 7543 | RGBKBD_STATE_INITIALIZED, |
| 7544 | /* RGB keyboard is disabled. */ |
| 7545 | RGBKBD_STATE_DISABLED, |
| 7546 | /* RGB keyboard is enabled and ready to receive a command. */ |
| 7547 | RGBKBD_STATE_ENABLED, |
| 7548 | |
| 7549 | /* Put no more entry below */ |
| 7550 | RGBKBD_STATE_COUNT, |
| 7551 | }; |
| 7552 | |
| 7553 | enum ec_rgbkbd_subcmd { |
| 7554 | EC_RGBKBD_SUBCMD_CLEAR = 1, |
| 7555 | EC_RGBKBD_SUBCMD_DEMO = 2, |
| 7556 | EC_RGBKBD_SUBCMD_SET_SCALE = 3, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7557 | EC_RGBKBD_SUBCMD_GET_CONFIG = 4, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7558 | EC_RGBKBD_SUBCMD_COUNT |
| 7559 | }; |
| 7560 | |
| 7561 | enum ec_rgbkbd_demo { |
| 7562 | EC_RGBKBD_DEMO_OFF = 0, |
| 7563 | EC_RGBKBD_DEMO_FLOW = 1, |
| 7564 | EC_RGBKBD_DEMO_DOT = 2, |
| 7565 | EC_RGBKBD_DEMO_COUNT, |
| 7566 | }; |
| 7567 | |
| 7568 | BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255); |
| 7569 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7570 | enum ec_rgbkbd_type { |
| 7571 | EC_RGBKBD_TYPE_UNKNOWN = 0, |
| 7572 | EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */ |
| 7573 | EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */ |
| 7574 | EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */ |
| 7575 | EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */ |
| 7576 | EC_RGBKBD_TYPE_COUNT, |
| 7577 | }; |
| 7578 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7579 | struct ec_rgbkbd_set_scale { |
| 7580 | uint8_t key; |
| 7581 | struct rgb_s scale; |
| 7582 | }; |
| 7583 | |
| 7584 | struct ec_params_rgbkbd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7585 | uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7586 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7587 | struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */ |
| 7588 | uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7589 | struct ec_rgbkbd_set_scale set_scale; |
| 7590 | }; |
| 7591 | } __ec_align1; |
| 7592 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7593 | struct ec_response_rgbkbd { |
| 7594 | /* |
| 7595 | * RGBKBD type supported by the device. |
| 7596 | */ |
| 7597 | |
| 7598 | uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */ |
| 7599 | } __ec_align1; |
| 7600 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7601 | struct ec_params_rgbkbd_set_color { |
| 7602 | /* Specifies the starting key ID whose color is being changed. */ |
| 7603 | uint8_t start_key; |
| 7604 | /* Specifies # of elements in <color>. */ |
| 7605 | uint8_t length; |
| 7606 | /* RGB color data array of length up to MAX_KEY_COUNT. */ |
| 7607 | struct rgb_s color[]; |
| 7608 | } __ec_align1; |
| 7609 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 7610 | /* |
| 7611 | * Gather the response to the most recent VDM REQ from the AP, as well |
| 7612 | * as popping the oldest VDM:Attention from the DPM queue |
| 7613 | */ |
| 7614 | #define EC_CMD_TYPEC_VDM_RESPONSE 0x013C |
| 7615 | |
| 7616 | struct ec_params_typec_vdm_response { |
| 7617 | uint8_t port; |
| 7618 | } __ec_align1; |
| 7619 | |
| 7620 | struct ec_response_typec_vdm_response { |
| 7621 | /* Number of 32-bit fields filled in */ |
| 7622 | uint8_t vdm_data_objects; |
| 7623 | /* Partner to address - see enum typec_partner_type */ |
| 7624 | uint8_t partner_type; |
| 7625 | /* enum ec_status describing VDM response */ |
| 7626 | uint16_t vdm_response_err; |
| 7627 | /* VDM data, including VDM header */ |
| 7628 | uint32_t vdm_response[VDO_MAX_SIZE]; |
| 7629 | /* Number of 32-bit Attention fields filled in */ |
| 7630 | uint8_t vdm_attention_objects; |
| 7631 | /* Number of remaining messages to consume */ |
| 7632 | uint8_t vdm_attention_left; |
| 7633 | /* Reserved */ |
| 7634 | uint16_t reserved1; |
| 7635 | /* VDM:Attention contents */ |
| 7636 | uint32_t vdm_attention[2]; |
| 7637 | } __ec_align1; |
| 7638 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 7639 | /* |
| 7640 | * Get an active battery config from the EC. |
| 7641 | */ |
| 7642 | #define EC_CMD_BATTERY_CONFIG 0x013D |
| 7643 | |
| 7644 | /* Version of struct batt_conf_header and its internals. */ |
| 7645 | #define EC_BATTERY_CONFIG_STRUCT_VERSION 0x00 |
| 7646 | |
| 7647 | /* Number of writes needed to invoke battery cutoff command */ |
| 7648 | #define SHIP_MODE_WRITES 2 |
| 7649 | |
| 7650 | struct ship_mode_info { |
| 7651 | uint8_t reg_addr; |
| 7652 | uint8_t reserved; |
| 7653 | uint16_t reg_data[SHIP_MODE_WRITES]; |
| 7654 | } __packed __aligned(2); |
| 7655 | |
| 7656 | struct sleep_mode_info { |
| 7657 | uint8_t reg_addr; |
| 7658 | uint8_t reserved; |
| 7659 | uint16_t reg_data; |
| 7660 | } __packed __aligned(2); |
| 7661 | |
| 7662 | struct fet_info { |
| 7663 | uint8_t reg_addr; |
| 7664 | uint8_t reserved; |
| 7665 | uint16_t reg_mask; |
| 7666 | uint16_t disconnect_val; |
| 7667 | uint16_t cfet_mask; /* CHG FET status mask */ |
| 7668 | uint16_t cfet_off_val; |
| 7669 | } __packed __aligned(2); |
| 7670 | |
| 7671 | enum fuel_gauge_flags { |
| 7672 | /* |
| 7673 | * Write Block Support. If enabled, we use a i2c write block command |
| 7674 | * instead of a 16-bit write. The effective difference is the i2c |
| 7675 | * transaction will prefix the length (2). |
| 7676 | */ |
| 7677 | FUEL_GAUGE_FLAG_WRITE_BLOCK = BIT(0), |
| 7678 | /* Sleep command support. fuel_gauge_info.sleep_mode must be defined. */ |
| 7679 | FUEL_GAUGE_FLAG_SLEEP_MODE = BIT(1), |
| 7680 | /* |
| 7681 | * Manufacturer access command support. If enabled, FET status is read |
| 7682 | * from the OperationStatus (0x54) register using the |
| 7683 | * ManufacturerBlockAccess (0x44). |
| 7684 | */ |
| 7685 | FUEL_GAUGE_FLAG_MFGACC = BIT(2), |
| 7686 | /* |
| 7687 | * SMB block protocol support in manufacturer access command. If |
| 7688 | * enabled, FET status is read from the OperationStatus (0x54) register |
| 7689 | * using the ManufacturerBlockAccess (0x44). |
| 7690 | */ |
| 7691 | FUEL_GAUGE_FLAG_MFGACC_SMB_BLOCK = BIT(3), |
| 7692 | }; |
| 7693 | |
| 7694 | struct fuel_gauge_info { |
| 7695 | uint32_t flags; |
| 7696 | uint32_t board_flags; |
| 7697 | struct ship_mode_info ship_mode; |
| 7698 | struct sleep_mode_info sleep_mode; |
| 7699 | struct fet_info fet; |
| 7700 | } __packed __aligned(4); |
| 7701 | |
| 7702 | /* Battery constants */ |
| 7703 | struct battery_info { |
| 7704 | /* Operation voltage in mV */ |
| 7705 | uint16_t voltage_max; |
| 7706 | uint16_t voltage_normal; |
| 7707 | uint16_t voltage_min; |
| 7708 | /* (TODO(chromium:756700): add desired_charging_current */ |
| 7709 | /** |
| 7710 | * Pre-charge to fast charge threshold in mV, |
| 7711 | * default to voltage_min if not specified. |
| 7712 | * This option is only available on isl923x and rt946x. |
| 7713 | */ |
| 7714 | uint16_t precharge_voltage; |
| 7715 | /* Pre-charge current in mA */ |
| 7716 | uint16_t precharge_current; |
| 7717 | /* Working temperature ranges in degrees C */ |
| 7718 | int8_t start_charging_min_c; |
| 7719 | int8_t start_charging_max_c; |
| 7720 | int8_t charging_min_c; |
| 7721 | int8_t charging_max_c; |
| 7722 | int8_t discharging_min_c; |
| 7723 | int8_t discharging_max_c; |
| 7724 | /* Used only if CONFIG_BATTERY_VENDOR_PARAM is defined. */ |
| 7725 | uint8_t vendor_param_start; |
| 7726 | uint8_t reserved; |
| 7727 | } __packed __aligned(2); |
| 7728 | |
| 7729 | /** |
| 7730 | * The 'config' of a battery. |
| 7731 | */ |
| 7732 | struct board_batt_params { |
| 7733 | struct fuel_gauge_info fuel_gauge; |
| 7734 | struct battery_info batt_info; |
| 7735 | } __packed __aligned(4); |
| 7736 | |
| 7737 | #define SBS_MAX_STRING_SIZE 32 |
| 7738 | |
| 7739 | /** |
| 7740 | * Header describing a battery config stored in CBI. Only struct_version has |
| 7741 | * size and position independent of struct_version. The rest varies as |
| 7742 | * struct_version changes. |
| 7743 | * |
| 7744 | * Version 0 |
| 7745 | * Layout: |
| 7746 | * +-------------+ |
| 7747 | * | header | |
| 7748 | * +-------------+ |
| 7749 | * | | ^ |
| 7750 | * | manuf_name | | manuf_name_size |
| 7751 | * | | v |
| 7752 | * +-------------+ |
| 7753 | * | device_name | ^ |
| 7754 | * | | | device_name_size |
| 7755 | * | | v |
| 7756 | * +-------------+ |
| 7757 | * | config | ^ |
| 7758 | * | | | |
| 7759 | * | | | cbi data size |
| 7760 | * | | | - (header_size+manuf_name_size+device_name_size) |
| 7761 | * | | | |
| 7762 | * | | v |
| 7763 | * +-------------+ |
| 7764 | * Note: |
| 7765 | * - manuf_name and device_name are not null-terminated. |
| 7766 | * - The config isn't aligned. It should be copied to struct board_batt_params |
| 7767 | * before its contents are accessed. |
| 7768 | */ |
| 7769 | struct batt_conf_header { |
| 7770 | /* Version independent field. It's always here as a uint8_t. */ |
| 7771 | uint8_t struct_version; |
| 7772 | /* Version 0 members */ |
| 7773 | uint8_t manuf_name_size; |
| 7774 | uint8_t device_name_size; |
| 7775 | uint8_t reserved; |
| 7776 | /* manuf_name, device_name, board_batt_params follow after this. */ |
| 7777 | } __packed; |
| 7778 | |
| 7779 | #define BATT_CONF_MAX_SIZE \ |
| 7780 | (sizeof(struct batt_conf_header) + SBS_MAX_STRING_SIZE * 2 + \ |
| 7781 | sizeof(struct board_batt_params)) |
| 7782 | |
| 7783 | /* |
| 7784 | * Record the current AP firmware state. This is used to help testing, such as |
| 7785 | * with FAFT (Fully-Automated Firmware Test), which likes to know which firmware |
| 7786 | * screen is currently displayed. |
| 7787 | */ |
| 7788 | |
| 7789 | #define EC_CMD_AP_FW_STATE 0x013E |
| 7790 | |
| 7791 | struct ec_params_ap_fw_state { |
| 7792 | /* |
| 7793 | * Value which indicates the state. This is not decoded by the EC, so |
| 7794 | * its meaning is entirely outside this code base. |
| 7795 | */ |
| 7796 | uint32_t state; |
| 7797 | } __ec_align1; |
| 7798 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 7799 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7800 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7801 | |
| 7802 | /*****************************************************************************/ |
| 7803 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7804 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7805 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7806 | #define EC_CMD_CR51_BASE 0x0300 |
| 7807 | #define EC_CMD_CR51_LAST 0x03FF |
| 7808 | |
| 7809 | /*****************************************************************************/ |
| 7810 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 7811 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 7812 | /* |
| 7813 | * Fingerprint SPI sensor passthru command |
| 7814 | * |
| 7815 | * This command was used for prototyping and it's now deprecated. |
| 7816 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7817 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 7818 | |
| 7819 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 7820 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7821 | struct ec_params_fp_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7822 | uint16_t len; /* Number of bytes to write then read */ |
| 7823 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 7824 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7825 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7826 | |
| 7827 | /* Configure the Fingerprint MCU behavior */ |
| 7828 | #define EC_CMD_FP_MODE 0x0402 |
| 7829 | |
| 7830 | /* Put the sensor in its lowest power mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7831 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7832 | /* Wait to see a finger on the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7833 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7834 | /* Poll until the finger has left the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7835 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7836 | /* Capture the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7837 | #define FP_MODE_CAPTURE BIT(3) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7838 | /* Finger enrollment session on-going */ |
| 7839 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 7840 | /* Enroll the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7841 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7842 | /* Try to match the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7843 | #define FP_MODE_MATCH BIT(6) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7844 | /* Reset and re-initialize the sensor. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7845 | #define FP_MODE_RESET_SENSOR BIT(7) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 7846 | /* Sensor maintenance for dead pixels. */ |
| 7847 | #define FP_MODE_SENSOR_MAINTENANCE BIT(8) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7848 | /* special value: don't change anything just read back current mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7849 | #define FP_MODE_DONT_CHANGE BIT(31) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7850 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7851 | #define FP_VALID_MODES \ |
| 7852 | (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \ |
| 7853 | FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \ |
| 7854 | FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \ |
| 7855 | FP_MODE_DONT_CHANGE) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7856 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7857 | /* Capture types defined in bits [30..28] */ |
| 7858 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7859 | #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] | 7860 | /** |
| 7861 | * enum fp_capture_type - Specifies the "mode" when capturing images. |
| 7862 | * |
| 7863 | * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality |
| 7864 | * image (produces 'frame_size' bytes) |
| 7865 | * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x |
| 7866 | * bpp bits) |
| 7867 | * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard) |
| 7868 | * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard) |
| 7869 | * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast |
| 7870 | * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test |
| 7871 | * @FP_CAPTURE_TYPE_MAX: End of enum |
| 7872 | * |
| 7873 | * @note This enum must remain ordered, if you add new values you must ensure |
| 7874 | * that FP_CAPTURE_TYPE_MAX is still the last one. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7875 | */ |
| 7876 | enum fp_capture_type { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7877 | FP_CAPTURE_VENDOR_FORMAT = 0, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7878 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7879 | FP_CAPTURE_PATTERN0 = 2, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7880 | FP_CAPTURE_PATTERN1 = 3, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7881 | FP_CAPTURE_QUALITY_TEST = 4, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7882 | FP_CAPTURE_RESET_TEST = 5, |
| 7883 | FP_CAPTURE_TYPE_MAX, |
| 7884 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7885 | /* Extracts the capture type from the sensor 'mode' word */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7886 | #define FP_CAPTURE_TYPE(mode) \ |
| 7887 | (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7888 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7889 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7890 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7891 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7892 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7893 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7894 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7895 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7896 | |
| 7897 | /* Retrieve Fingerprint sensor information */ |
| 7898 | #define EC_CMD_FP_INFO 0x0403 |
| 7899 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7900 | /* Number of dead pixels detected on the last maintenance */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7901 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7902 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 7903 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7904 | /* No interrupt from the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7905 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7906 | /* SPI communication error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7907 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7908 | /* Invalid sensor Hardware ID */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7909 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7910 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7911 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7912 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7913 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7914 | /* Sensor identification */ |
| 7915 | uint32_t vendor_id; |
| 7916 | uint32_t product_id; |
| 7917 | uint32_t model_id; |
| 7918 | uint32_t version; |
| 7919 | /* Image frame characteristics */ |
| 7920 | uint32_t frame_size; |
| 7921 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7922 | uint16_t width; |
| 7923 | uint16_t height; |
| 7924 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7925 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7926 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7927 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7928 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7929 | /* Sensor identification */ |
| 7930 | uint32_t vendor_id; |
| 7931 | uint32_t product_id; |
| 7932 | uint32_t model_id; |
| 7933 | uint32_t version; |
| 7934 | /* Image frame characteristics */ |
| 7935 | uint32_t frame_size; |
| 7936 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7937 | uint16_t width; |
| 7938 | uint16_t height; |
| 7939 | uint16_t bpp; |
| 7940 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 7941 | /* Template/finger current information */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7942 | uint32_t template_size; /* max template size in bytes */ |
| 7943 | uint16_t template_max; /* maximum number of fingers/templates */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7944 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 7945 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7946 | uint32_t template_version; /* version of the template format */ |
| 7947 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7948 | |
| 7949 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7950 | #define EC_CMD_FP_FRAME 0x0404 |
| 7951 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7952 | /* constants defining the 'offset' field which also contains the frame index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7953 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7954 | /* Frame buffer where the captured image is stored */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7955 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7956 | /* First frame buffer holding a template */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7957 | #define FP_FRAME_INDEX_TEMPLATE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7958 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7959 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7960 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7961 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7962 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7963 | |
| 7964 | /* Constants for encryption parameters */ |
| 7965 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 7966 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 7967 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7968 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7969 | #define FP_CONTEXT_TPM_BYTES 32 |
| 7970 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7971 | /* Constants for positive match parameters. */ |
| 7972 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 7973 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7974 | struct ec_fp_template_encryption_metadata { |
| 7975 | /* |
| 7976 | * Version of the structure format (N=3). |
| 7977 | */ |
| 7978 | uint16_t struct_version; |
| 7979 | /* Reserved bytes, set to 0. */ |
| 7980 | uint16_t reserved; |
| 7981 | /* |
| 7982 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 7983 | * a different one is used for every message. |
| 7984 | */ |
| 7985 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7986 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7987 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 7988 | }; |
| 7989 | |
| 7990 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7991 | /* |
| 7992 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 7993 | * in the high nibble, and the real offset within the frame in |
| 7994 | * FP_FRAME_OFFSET_MASK. |
| 7995 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7996 | uint32_t offset; |
| 7997 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7998 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7999 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8000 | /* Load a template into the MCU */ |
| 8001 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 8002 | |
| 8003 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 8004 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 8005 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8006 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8007 | uint32_t offset; |
| 8008 | uint32_t size; |
| 8009 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8010 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8011 | |
| 8012 | /* Clear the current fingerprint user context and set a new one */ |
| 8013 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 8014 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8015 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8016 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8017 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8018 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 8019 | enum fp_context_action { |
| 8020 | FP_CONTEXT_ASYNC = 0, |
| 8021 | FP_CONTEXT_GET_RESULT = 1, |
| 8022 | }; |
| 8023 | |
| 8024 | /* Version 1 of the command is "asynchronous". */ |
| 8025 | struct ec_params_fp_context_v1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8026 | uint8_t action; /**< enum fp_context_action */ |
| 8027 | uint8_t reserved[3]; /**< padding for alignment */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 8028 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 8029 | } __ec_align4; |
| 8030 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8031 | #define EC_CMD_FP_STATS 0x0407 |
| 8032 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8033 | #define FPSTATS_CAPTURE_INV BIT(0) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8034 | #define FPSTATS_MATCHING_INV BIT(1) |
| 8035 | |
| 8036 | struct ec_response_fp_stats { |
| 8037 | uint32_t capture_time_us; |
| 8038 | uint32_t matching_time_us; |
| 8039 | uint32_t overall_time_us; |
| 8040 | struct { |
| 8041 | uint32_t lo; |
| 8042 | uint32_t hi; |
| 8043 | } overall_t0; |
| 8044 | uint8_t timestamps_invalid; |
| 8045 | int8_t template_matched; |
| 8046 | } __ec_align2; |
| 8047 | |
| 8048 | #define EC_CMD_FP_SEED 0x0408 |
| 8049 | struct ec_params_fp_seed { |
| 8050 | /* |
| 8051 | * Version of the structure format (N=3). |
| 8052 | */ |
| 8053 | uint16_t struct_version; |
| 8054 | /* Reserved bytes, set to 0. */ |
| 8055 | uint16_t reserved; |
| 8056 | /* Seed from the TPM. */ |
| 8057 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 8058 | } __ec_align4; |
| 8059 | |
| 8060 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 8061 | |
| 8062 | /* FP TPM seed has been set or not */ |
| 8063 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 8064 | /* FP using nonce context or not */ |
| 8065 | #define FP_CONTEXT_STATUS_NONCE_CONTEXT_SET BIT(1) |
| 8066 | /* FP match had been processed or not */ |
| 8067 | #define FP_CONTEXT_STATUS_MATCH_PROCESSED_SET BIT(2) |
| 8068 | /* FP auth_nonce had been set or not*/ |
| 8069 | #define FP_CONTEXT_AUTH_NONCE_SET BIT(3) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8070 | |
| 8071 | struct ec_response_fp_encryption_status { |
| 8072 | /* Used bits in encryption engine status */ |
| 8073 | uint32_t valid_flags; |
| 8074 | /* Encryption engine status */ |
| 8075 | uint32_t status; |
| 8076 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8077 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 8078 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 8079 | struct ec_params_fp_read_match_secret { |
| 8080 | uint16_t fgr; |
| 8081 | } __ec_align4; |
| 8082 | |
| 8083 | /* The positive match secret has the length of the SHA256 digest. */ |
| 8084 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 8085 | struct ec_response_fp_read_match_secret { |
| 8086 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 8087 | } __ec_align4; |
| 8088 | |
Simon Glass | d3870a2 | 2023-11-09 08:43:30 -0700 | [diff] [blame^] | 8089 | #define FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN 32 |
| 8090 | |
| 8091 | struct fp_elliptic_curve_public_key { |
| 8092 | uint8_t x[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN]; |
| 8093 | uint8_t y[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN]; |
| 8094 | } __ec_align4; |
| 8095 | |
| 8096 | #define FP_AES_KEY_ENC_METADATA_VERSION 1 |
| 8097 | #define FP_AES_KEY_NONCE_BYTES 12 |
| 8098 | #define FP_AES_KEY_ENCRYPTION_SALT_BYTES 16 |
| 8099 | #define FP_AES_KEY_TAG_BYTES 16 |
| 8100 | |
| 8101 | struct fp_auth_command_encryption_metadata { |
| 8102 | /* Version of the structure format */ |
| 8103 | uint16_t struct_version; |
| 8104 | /* Reserved bytes, set to 0. */ |
| 8105 | uint16_t reserved; |
| 8106 | /* |
| 8107 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 8108 | * a different one is used for every message. |
| 8109 | */ |
| 8110 | uint8_t nonce[FP_AES_KEY_NONCE_BYTES]; |
| 8111 | uint8_t encryption_salt[FP_AES_KEY_ENCRYPTION_SALT_BYTES]; |
| 8112 | uint8_t tag[FP_AES_KEY_TAG_BYTES]; |
| 8113 | } __ec_align4; |
| 8114 | |
| 8115 | #define FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN 32 |
| 8116 | #define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16 |
| 8117 | |
| 8118 | struct fp_encrypted_private_key { |
| 8119 | struct fp_auth_command_encryption_metadata info; |
| 8120 | uint8_t data[FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN]; |
| 8121 | } __ec_align4; |
| 8122 | |
| 8123 | #define EC_CMD_FP_ESTABLISH_PAIRING_KEY_KEYGEN 0x0410 |
| 8124 | |
| 8125 | struct ec_response_fp_establish_pairing_key_keygen { |
| 8126 | struct fp_elliptic_curve_public_key pubkey; |
| 8127 | struct fp_encrypted_private_key encrypted_private_key; |
| 8128 | } __ec_align4; |
| 8129 | |
| 8130 | #define FP_PAIRING_KEY_LEN 32 |
| 8131 | |
| 8132 | struct ec_fp_encrypted_pairing_key { |
| 8133 | struct fp_auth_command_encryption_metadata info; |
| 8134 | uint8_t data[FP_PAIRING_KEY_LEN]; |
| 8135 | } __ec_align4; |
| 8136 | |
| 8137 | #define EC_CMD_FP_ESTABLISH_PAIRING_KEY_WRAP 0x0411 |
| 8138 | |
| 8139 | struct ec_params_fp_establish_pairing_key_wrap { |
| 8140 | struct fp_elliptic_curve_public_key peers_pubkey; |
| 8141 | struct fp_encrypted_private_key encrypted_private_key; |
| 8142 | } __ec_align4; |
| 8143 | |
| 8144 | struct ec_response_fp_establish_pairing_key_wrap { |
| 8145 | struct ec_fp_encrypted_pairing_key encrypted_pairing_key; |
| 8146 | } __ec_align4; |
| 8147 | |
| 8148 | #define EC_CMD_FP_LOAD_PAIRING_KEY 0x0412 |
| 8149 | |
| 8150 | typedef struct ec_response_fp_establish_pairing_key_wrap |
| 8151 | ec_params_fp_load_pairing_key; |
| 8152 | |
| 8153 | #define FP_CK_AUTH_NONCE_LEN 32 |
| 8154 | |
| 8155 | #define EC_CMD_FP_GENERATE_NONCE 0x0413 |
| 8156 | struct ec_response_fp_generate_nonce { |
| 8157 | uint8_t nonce[FP_CK_AUTH_NONCE_LEN]; |
| 8158 | } __ec_align4; |
| 8159 | |
| 8160 | #define FP_CONTEXT_USERID_LEN 32 |
| 8161 | #define FP_CONTEXT_USERID_IV_LEN 16 |
| 8162 | #define FP_CONTEXT_KEY_LEN 32 |
| 8163 | |
| 8164 | #define EC_CMD_FP_NONCE_CONTEXT 0x0414 |
| 8165 | struct ec_params_fp_nonce_context { |
| 8166 | uint8_t gsc_nonce[FP_CK_AUTH_NONCE_LEN]; |
| 8167 | uint8_t enc_user_id[FP_CONTEXT_USERID_LEN]; |
| 8168 | uint8_t enc_user_id_iv[FP_CONTEXT_USERID_IV_LEN]; |
| 8169 | } __ec_align4; |
| 8170 | |
| 8171 | #define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16 |
| 8172 | |
| 8173 | #define EC_CMD_FP_READ_MATCH_SECRET_WITH_PUBKEY 0x0415 |
| 8174 | |
| 8175 | struct ec_params_fp_read_match_secret_with_pubkey { |
| 8176 | uint16_t fgr; |
| 8177 | uint16_t reserved; |
| 8178 | struct fp_elliptic_curve_public_key pubkey; |
| 8179 | } __ec_align4; |
| 8180 | |
| 8181 | struct ec_response_fp_read_match_secret_with_pubkey { |
| 8182 | struct fp_elliptic_curve_public_key pubkey; |
| 8183 | uint8_t iv[FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN]; |
| 8184 | uint8_t enc_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 8185 | } __ec_align4; |
| 8186 | |
| 8187 | /* Preload encrypted template into the MCU buffer */ |
| 8188 | #define EC_CMD_FP_PRELOAD_TEMPLATE 0x0416 |
| 8189 | |
| 8190 | struct ec_params_fp_preload_template { |
| 8191 | uint32_t offset; |
| 8192 | uint32_t size; |
| 8193 | uint16_t fgr; |
| 8194 | uint8_t reserved[2]; |
| 8195 | uint8_t data[]; |
| 8196 | } __ec_align4; |
| 8197 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8198 | /*****************************************************************************/ |
| 8199 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 8200 | |
| 8201 | /* Perform touchpad self test */ |
| 8202 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 8203 | |
| 8204 | /* Get number of frame types, and the size of each type */ |
| 8205 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 8206 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8207 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8208 | uint32_t n_frames; |
| 8209 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8210 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8211 | |
| 8212 | /* Create a snapshot of current frame readings */ |
| 8213 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 8214 | |
| 8215 | /* Read the frame */ |
| 8216 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 8217 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8218 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8219 | uint32_t frame_index; |
| 8220 | uint32_t offset; |
| 8221 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8222 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 8223 | |
| 8224 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8225 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 8226 | |
| 8227 | #define EC_COMM_TEXT_MAX 8 |
| 8228 | |
| 8229 | /* |
| 8230 | * Get battery static information, i.e. information that never changes, or |
| 8231 | * very infrequently. |
| 8232 | */ |
| 8233 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 8234 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8235 | /** |
| 8236 | * struct ec_params_battery_static_info - Battery static info parameters |
| 8237 | * @index: Battery index. |
| 8238 | */ |
| 8239 | struct ec_params_battery_static_info { |
| 8240 | uint8_t index; |
| 8241 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8242 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8243 | /** |
| 8244 | * struct ec_response_battery_static_info - Battery static info response |
| 8245 | * @design_capacity: Battery Design Capacity (mAh) |
| 8246 | * @design_voltage: Battery Design Voltage (mV) |
| 8247 | * @manufacturer: Battery Manufacturer String |
| 8248 | * @model: Battery Model Number String |
| 8249 | * @serial: Battery Serial Number String |
| 8250 | * @type: Battery Type String |
| 8251 | * @cycle_count: Battery Cycle Count |
| 8252 | */ |
| 8253 | struct ec_response_battery_static_info { |
| 8254 | uint16_t design_capacity; |
| 8255 | uint16_t design_voltage; |
| 8256 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 8257 | char model[EC_COMM_TEXT_MAX]; |
| 8258 | char serial[EC_COMM_TEXT_MAX]; |
| 8259 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8260 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8261 | uint32_t cycle_count; |
| 8262 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8263 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 8264 | /** |
| 8265 | * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info |
| 8266 | * Equivalent to struct ec_response_battery_static_info, but with longer |
| 8267 | * strings. |
| 8268 | * @design_capacity: battery design capacity (in mAh) |
| 8269 | * @design_voltage: battery design voltage (in mV) |
| 8270 | * @cycle_count: battery cycle count |
| 8271 | * @manufacturer_ext: battery manufacturer string |
| 8272 | * @model_ext: battery model string |
| 8273 | * @serial_ext: battery serial number string |
| 8274 | * @type_ext: battery type string |
| 8275 | */ |
| 8276 | struct ec_response_battery_static_info_v1 { |
| 8277 | uint16_t design_capacity; |
| 8278 | uint16_t design_voltage; |
| 8279 | uint32_t cycle_count; |
| 8280 | char manufacturer_ext[12]; |
| 8281 | char model_ext[12]; |
| 8282 | char serial_ext[12]; |
| 8283 | char type_ext[12]; |
| 8284 | } __ec_align4; |
| 8285 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 8286 | /** |
| 8287 | * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info |
| 8288 | * |
| 8289 | * Equivalent to struct ec_response_battery_static_info, but with strings |
| 8290 | * further lengthened (relative to v1) to accommodate the maximum string length |
| 8291 | * permitted by the Smart Battery Data Specification revision 1.1 and fields |
| 8292 | * renamed to better match that specification. |
| 8293 | * |
| 8294 | * @design_capacity: battery design capacity (in mAh) |
| 8295 | * @design_voltage: battery design voltage (in mV) |
| 8296 | * @cycle_count: battery cycle count |
| 8297 | * @manufacturer: battery manufacturer string |
| 8298 | * @device_name: battery model string |
| 8299 | * @serial: battery serial number string |
| 8300 | * @chemistry: battery type string |
| 8301 | */ |
| 8302 | struct ec_response_battery_static_info_v2 { |
| 8303 | uint16_t design_capacity; |
| 8304 | uint16_t design_voltage; |
| 8305 | uint32_t cycle_count; |
| 8306 | char manufacturer[32]; |
| 8307 | char device_name[32]; |
| 8308 | char serial[32]; |
| 8309 | char chemistry[32]; |
| 8310 | } __ec_align4; |
| 8311 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8312 | /* |
| 8313 | * Get battery dynamic information, i.e. information that is likely to change |
| 8314 | * every time it is read. |
| 8315 | */ |
| 8316 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 8317 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8318 | /** |
| 8319 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 8320 | * @index: Battery index. |
| 8321 | */ |
| 8322 | struct ec_params_battery_dynamic_info { |
| 8323 | uint8_t index; |
| 8324 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8325 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8326 | /** |
| 8327 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 8328 | * @actual_voltage: Battery voltage (mV) |
| 8329 | * @actual_current: Battery current (mA); negative=discharging |
| 8330 | * @remaining_capacity: Remaining capacity (mAh) |
| 8331 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 8332 | * @flags: Flags, see EC_BATT_FLAG_* |
| 8333 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 8334 | * @desired_current: Charging current desired by battery (mA) |
| 8335 | */ |
| 8336 | struct ec_response_battery_dynamic_info { |
| 8337 | int16_t actual_voltage; |
| 8338 | int16_t actual_current; |
| 8339 | int16_t remaining_capacity; |
| 8340 | int16_t full_capacity; |
| 8341 | int16_t flags; |
| 8342 | int16_t desired_voltage; |
| 8343 | int16_t desired_current; |
| 8344 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8345 | |
| 8346 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 8347 | * Control charger chip. Used to control charger chip on the peripheral. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8348 | */ |
| 8349 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 8350 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8351 | /** |
| 8352 | * struct ec_params_charger_control - Charger control parameters |
| 8353 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 8354 | * max_current and (possibly) charge battery, negative to request current |
| 8355 | * from base (OTG). |
| 8356 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 8357 | * >= 0. |
| 8358 | * @allow_charging: Allow base battery charging (only makes sense if |
| 8359 | * max_current > 0). |
| 8360 | */ |
| 8361 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8362 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8363 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8364 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8365 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8366 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 8367 | /* Get ACK from the USB-C SS muxes */ |
| 8368 | #define EC_CMD_USB_PD_MUX_ACK 0x0603 |
| 8369 | |
| 8370 | struct ec_params_usb_pd_mux_ack { |
| 8371 | uint8_t port; /* USB-C port number */ |
| 8372 | } __ec_align1; |
| 8373 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame] | 8374 | /* Get boot time */ |
| 8375 | #define EC_CMD_GET_BOOT_TIME 0x0604 |
| 8376 | |
| 8377 | enum boot_time_param { |
| 8378 | ARAIL = 0, |
| 8379 | RSMRST, |
| 8380 | ESPIRST, |
| 8381 | PLTRST_LOW, |
| 8382 | PLTRST_HIGH, |
| 8383 | EC_CUR_TIME, |
| 8384 | RESET_CNT, |
| 8385 | }; |
| 8386 | |
| 8387 | struct ec_response_get_boot_time { |
| 8388 | uint64_t timestamp[RESET_CNT]; |
| 8389 | uint16_t cnt; |
| 8390 | } __ec_align4; |
| 8391 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 8392 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 8393 | /* |
| 8394 | * Reserve a range of host commands for board-specific, experimental, or |
| 8395 | * special purpose features. These can be (re)used without updating this file. |
| 8396 | * |
| 8397 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 8398 | * their EC commands for easier development, testing, debugging, and support. |
| 8399 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8400 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 8401 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 8402 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 8403 | * In your experimental code, you may want to do something like this: |
| 8404 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8405 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 8406 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 8407 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 8408 | * |
| 8409 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 8410 | * EC_VER_MASK(0); |
| 8411 | * |
| 8412 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 8413 | * EC_VER_MASK(0); |
| 8414 | * |
| 8415 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 8416 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 8417 | */ |
| 8418 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 8419 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 8420 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8421 | /* |
| 8422 | * Given the private host command offset, calculate the true private host |
| 8423 | * command value. |
| 8424 | */ |
| 8425 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 8426 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 8427 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 8428 | /*****************************************************************************/ |
| 8429 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 8430 | * Passthru commands |
| 8431 | * |
| 8432 | * Some platforms have sub-processors chained to each other. For example. |
| 8433 | * |
| 8434 | * AP <--> EC <--> PD MCU |
| 8435 | * |
| 8436 | * The top 2 bits of the command number are used to indicate which device the |
| 8437 | * command is intended for. Device 0 is always the device receiving the |
| 8438 | * command; other device mapping is board-specific. |
| 8439 | * |
| 8440 | * When a device receives a command to be passed to a sub-processor, it passes |
| 8441 | * it on with the device number set back to 0. This allows the sub-processor |
| 8442 | * to remain blissfully unaware of whether the command originated on the next |
| 8443 | * device up the chain, or was passed through from the AP. |
| 8444 | * |
| 8445 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 8446 | * AP sends command 0x4002 to the EC |
| 8447 | * EC sends command 0x0002 to the PD MCU |
| 8448 | * EC forwards PD MCU response back to the AP |
| 8449 | */ |
| 8450 | |
| 8451 | /* Offset and max command number for sub-device n */ |
| 8452 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 8453 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 8454 | |
| 8455 | /*****************************************************************************/ |
| 8456 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 8457 | * Deprecated constants. These constants have been renamed for clarity. The |
| 8458 | * meaning and size has not changed. Programs that use the old names should |
| 8459 | * switch to the new names soon, as the old names may not be carried forward |
| 8460 | * forever. |
| 8461 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8462 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 8463 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 8464 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 8465 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8466 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 8467 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 8468 | #ifdef __cplusplus |
| 8469 | } |
| 8470 | #endif |
| 8471 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 8472 | #endif /* __CROS_EC_EC_COMMANDS_H */ |