Patrick Georgi | 593124d | 2020-05-10 19:44:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2 | |
| 3 | /* Host communication command constants for Chrome EC */ |
| 4 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5 | #ifndef __CROS_EC_EC_COMMANDS_H |
| 6 | #define __CROS_EC_EC_COMMANDS_H |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 7 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 8 | #if !defined(__ACPI__) && !defined(__KERNEL__) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | #endif |
| 11 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 12 | #ifdef CHROMIUM_EC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 13 | /* |
| 14 | * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository. |
| 15 | * It is used to not include macros that may cause conflicts in foreign |
| 16 | * projects (refer to crbug.com/984623). |
| 17 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 18 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 19 | /* |
| 20 | * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This |
| 21 | * generates more efficient code for accessing request/response structures on |
| 22 | * ARM Cortex-M if the structures are guaranteed 32-bit aligned. |
| 23 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 24 | #include "common.h" |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 25 | #include "compile_time_macros.h" |
| 26 | |
| 27 | #else |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 28 | /* If BUILD_ASSERT isn't already defined, make it a no-op */ |
| 29 | #ifndef BUILD_ASSERT |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 30 | #define BUILD_ASSERT(_cond) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 31 | #endif /* !BUILD_ASSERT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 32 | #endif /* CHROMIUM_EC */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 33 | |
| 34 | #ifdef __KERNEL__ |
| 35 | #include <linux/limits.h> |
| 36 | #else |
| 37 | /* |
| 38 | * Defines macros that may be needed but are for sure defined by the linux |
| 39 | * kernel. This section is removed when cros_ec_commands.h is generated (by |
| 40 | * util/make_linux_ec_commands_h.sh). |
| 41 | * cros_ec_commands.h looks more integrated to the kernel. |
| 42 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 43 | |
| 44 | #ifndef BIT |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 45 | #define BIT(nr) (1UL << (nr)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 46 | #endif |
| 47 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 48 | #ifndef BIT_ULL |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 49 | #define BIT_ULL(nr) (1ULL << (nr)) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 50 | #endif |
| 51 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 52 | /* |
| 53 | * When building Zephyr, this file ends up being included before Zephyr's |
| 54 | * include/sys/util.h so causes a warning there. We don't want to add an #ifdef |
| 55 | * in that file since it won't be accepted upstream. So work around it here. |
| 56 | */ |
| 57 | #ifndef CONFIG_ZEPHYR |
| 58 | #ifndef GENMASK |
| 59 | #define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1)) |
| 60 | #endif |
| 61 | |
| 62 | #ifndef GENMASK_ULL |
| 63 | #define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1)) |
| 64 | #endif |
| 65 | #endif |
| 66 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 67 | #endif /* __KERNEL__ */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 68 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 69 | #ifdef __cplusplus |
| 70 | extern "C" { |
| 71 | #endif |
| 72 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 73 | /** |
| 74 | * Constant for creation of flexible array members that work in both C and |
| 75 | * C++. Flexible array members were added in C99 and are not part of the C++ |
| 76 | * standard. However, clang++ supports them for C++. |
| 77 | * When compiling with gcc, flexible array members are not allowed to appear |
| 78 | * in an otherwise empty struct, so we use the GCC zero-length array |
| 79 | * extension that works with both clang/gcc/g++. |
| 80 | */ |
| 81 | #if defined(__cplusplus) && defined(__clang__) |
| 82 | #define FLEXIBLE_ARRAY_MEMBER_SIZE |
| 83 | #else |
| 84 | #define FLEXIBLE_ARRAY_MEMBER_SIZE 0 |
| 85 | #endif |
| 86 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 87 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 88 | * Current version of this protocol |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 89 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 90 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 91 | * determined in other ways. Remove this once the kernel code no longer |
| 92 | * depends on it. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 93 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 94 | #define EC_PROTO_VERSION 0x00000002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 95 | |
| 96 | /* Command version mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 97 | #define EC_VER_MASK(version) BIT(version) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 98 | |
| 99 | /* I/O addresses for ACPI commands */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 100 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 101 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 102 | |
| 103 | /* I/O addresses for host command */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 104 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 105 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 106 | |
| 107 | /* I/O addresses for host command args and params */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 108 | /* Protocol version 2 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 109 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 110 | /* For version 2 params; size is EC_PROTO2_MAX_PARAM_SIZE */ |
| 111 | #define EC_LPC_ADDR_HOST_PARAM 0x804 |
| 112 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 113 | /* Protocol version 3 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 114 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 115 | #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] | 116 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 117 | /* |
| 118 | * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 119 | * 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] | 120 | * |
| 121 | * Other BIOSes report only the I/O port region spanned by the Microchip |
| 122 | * 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] | 123 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 124 | #define EC_HOST_CMD_REGION0 0x800 |
| 125 | #define EC_HOST_CMD_REGION1 0x880 |
| 126 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 127 | #define EC_HOST_CMD_MEC_REGION_SIZE 0x8 |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 128 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 129 | /* EC command register bit functions */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 130 | #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ |
| 131 | #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */ |
| 132 | #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */ |
| 133 | #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */ |
| 134 | #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */ |
| 135 | #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */ |
| 136 | #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 137 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 138 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 139 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 140 | #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] | 141 | |
| 142 | /* The offset address of each type of data in mapped memory. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 143 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 144 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 145 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 146 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
| 147 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 148 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 149 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 150 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 151 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
| 152 | #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] | 153 | /* Unused 0x28 - 0x2f */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 154 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 155 | /* Unused 0x31 - 0x33 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 156 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 157 | /* Battery values are all 32 bits, unless otherwise noted. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 158 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 159 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 160 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
| 161 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */ |
| 162 | #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */ |
| 163 | #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 164 | /* Unused 0x4f */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 165 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 166 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 167 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 168 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 169 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 170 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 171 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 172 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 173 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
| 174 | #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] | 175 | /* Unused 0x84 - 0x8f */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 176 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 177 | /* Unused 0x91 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 178 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 179 | /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ |
| 180 | /* 0x94 - 0x99: 1st Accelerometer */ |
| 181 | /* 0x9a - 0x9f: 2nd Accelerometer */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 182 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 183 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 184 | #define EC_MEMMAP_GPU 0xa6 /* GPU-specific, 8 bits */ |
| 185 | |
| 186 | /* |
| 187 | * Bit fields for EC_MEMMAP_GPU |
| 188 | * 0:2: D-Notify level (0:D1, ... 4:D5) |
| 189 | * 3: Over temperature |
| 190 | */ |
| 191 | #define EC_MEMMAP_GPU_D_NOTIFY_MASK GENMASK(2, 0) |
| 192 | #define EC_MEMMAP_GPU_OVERT_BIT BIT(3) |
| 193 | |
| 194 | /* Power Participant related components */ |
| 195 | #define EC_MEMMAP_PWR_SRC 0xa7 /* Power source (8-bit) */ |
| 196 | /* Unused 0xa8 - 0xdf */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 197 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 198 | /* |
| 199 | * ACPI is unable to access memory mapped data at or above this offset due to |
| 200 | * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe |
| 201 | * which might be needed by ACPI. |
| 202 | */ |
| 203 | #define EC_MEMMAP_NO_ACPI 0xe0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 204 | |
| 205 | /* Define the format of the accelerometer mapped memory status byte. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 206 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
| 207 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) |
| 208 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 209 | |
| 210 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 211 | #define EC_TEMP_SENSOR_ENTRIES 16 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 212 | /* |
| 213 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 214 | * |
| 215 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 216 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 217 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 218 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 219 | /* Max temp sensor entries for host commands */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 220 | #define EC_MAX_TEMP_SENSOR_ENTRIES \ |
| 221 | (EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 222 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 223 | /* Special values for mapped temperature sensors */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 224 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 225 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 226 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 227 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 228 | /* |
| 229 | * The offset of temperature value stored in mapped memory. This allows |
| 230 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 231 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 232 | #define EC_TEMP_SENSOR_OFFSET 200 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 233 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 234 | /* |
| 235 | * Number of ALS readings at EC_MEMMAP_ALS |
| 236 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 237 | #define EC_ALS_ENTRIES 2 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 238 | |
| 239 | /* |
| 240 | * The default value a temperature sensor will return when it is present but |
| 241 | * has not been read this boot. This is a reasonable number to avoid |
| 242 | * triggering alarms on the host. |
| 243 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 244 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 245 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 246 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 247 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 248 | |
| 249 | /* Report 0 for fan stalled so userspace applications can take |
| 250 | * an appropriate action based on this value to control the fan. |
| 251 | */ |
| 252 | #define EC_FAN_SPEED_STALLED 0x0 /* Fan stalled */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 253 | |
| 254 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 255 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 256 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 257 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 258 | #define EC_BATT_FLAG_CHARGING 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 259 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 260 | /* Set if some of the static/dynamic data is invalid (or outdated). */ |
| 261 | #define EC_BATT_FLAG_INVALID_DATA 0x20 |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 262 | #define EC_BATT_FLAG_CUT_OFF 0x40 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 263 | |
| 264 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 265 | #define EC_SWITCH_LID_OPEN 0x01 |
| 266 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 267 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 268 | /* Was recovery requested via keyboard; now unused. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 269 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 270 | /* Recovery requested via dedicated signal (from servo board) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 271 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 272 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 273 | #define EC_SWITCH_IGNORE0 0x20 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 274 | |
| 275 | /* Host command interface flags */ |
| 276 | /* Host command interface supports LPC args (LPC interface only) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 277 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 278 | /* Host command interface supports version 3 protocol */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 279 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 280 | |
| 281 | /* Wireless switch flags */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 282 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 283 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 284 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 285 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 286 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 287 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 288 | /*****************************************************************************/ |
| 289 | /* |
| 290 | * ACPI commands |
| 291 | * |
| 292 | * These are valid ONLY on the ACPI command/data port. |
| 293 | */ |
| 294 | |
| 295 | /* |
| 296 | * ACPI Read Embedded Controller |
| 297 | * |
| 298 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 299 | * |
| 300 | * Use the following sequence: |
| 301 | * |
| 302 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 303 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 304 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 305 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 306 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 307 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 308 | #define EC_CMD_ACPI_READ 0x0080 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * ACPI Write Embedded Controller |
| 312 | * |
| 313 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 314 | * |
| 315 | * Use the following sequence: |
| 316 | * |
| 317 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 318 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 319 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 320 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 321 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 322 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 323 | #define EC_CMD_ACPI_WRITE 0x0081 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | * ACPI Burst Enable Embedded Controller |
| 327 | * |
| 328 | * This enables burst mode on the EC to allow the host to issue several |
| 329 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 330 | * data are locked out to ensure data consistency. |
| 331 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 332 | #define EC_CMD_ACPI_BURST_ENABLE 0x0082 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 333 | |
| 334 | /* |
| 335 | * ACPI Burst Disable Embedded Controller |
| 336 | * |
| 337 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 338 | * multi-byte data. |
| 339 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 340 | #define EC_CMD_ACPI_BURST_DISABLE 0x0083 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 341 | |
| 342 | /* |
| 343 | * ACPI Query Embedded Controller |
| 344 | * |
| 345 | * This clears the lowest-order bit in the currently pending host events, and |
| 346 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 347 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 348 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 349 | #define EC_CMD_ACPI_QUERY_EVENT 0x0084 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 350 | |
| 351 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 352 | |
| 353 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 354 | #define EC_ACPI_MEM_VERSION 0x00 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 355 | /* |
| 356 | * Test location; writing value here updates test compliment byte to (0xff - |
| 357 | * value). |
| 358 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 359 | #define EC_ACPI_MEM_TEST 0x01 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 360 | /* Test compliment; writes here are ignored. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 361 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 362 | |
| 363 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 364 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 365 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 366 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 370 | * independent thresholds attached to them. The current value of the ID |
| 371 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 372 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 373 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 374 | * |
| 375 | * The spec does not mandate any way to read back the threshold settings |
| 376 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 377 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 378 | * returns one sensor ID that has crossed one of its threshold (in either |
| 379 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 380 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 381 | * the unread event count for that sensor. |
| 382 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 383 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 384 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 385 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 386 | /* |
| 387 | * Here are the bits for the COMMIT register: |
| 388 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 389 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 390 | * Each write to the commit register affects one threshold. |
| 391 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 392 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) |
| 393 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 394 | /* |
| 395 | * Example: |
| 396 | * |
| 397 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 398 | * write 2 to [0x05] -- select temp sensor 2 |
| 399 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 400 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 401 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 402 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 403 | * |
| 404 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 405 | * write 2 to [0x05] -- select temp sensor 2 |
| 406 | * write 0x1 to [0x07] -- disable threshold 1 |
| 407 | */ |
| 408 | |
| 409 | /* DPTF battery charging current limit */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 410 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 411 | |
| 412 | /* Charging limit is specified in 64 mA steps */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 413 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 414 | /* Value to disable DPTF battery charging limit */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 415 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 416 | |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 417 | /* |
| 418 | * Report device orientation |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 419 | * Bits Definition |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 420 | * 4 Off Body/On Body status: 0 = Off Body. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 421 | * 3:1 Device DPTF Profile Number (DDPN) |
| 422 | * 0 = Reserved for backward compatibility (indicates no valid |
| 423 | * profile number. Host should fall back to using TBMD). |
| 424 | * 1..7 = DPTF Profile number to indicate to host which table needs |
| 425 | * to be loaded. |
| 426 | * 0 Tablet Mode Device Indicator (TBMD) |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 427 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 428 | #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 429 | #define EC_ACPI_MEM_TBMD_SHIFT 0 |
| 430 | #define EC_ACPI_MEM_TBMD_MASK 0x1 |
| 431 | #define EC_ACPI_MEM_DDPN_SHIFT 1 |
| 432 | #define EC_ACPI_MEM_DDPN_MASK 0x7 |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 433 | #define EC_ACPI_MEM_STTB_SHIFT 4 |
| 434 | #define EC_ACPI_MEM_STTB_MASK 0x1 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 435 | |
| 436 | /* |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 437 | * Report device features. Uses the same format as the host command, except: |
| 438 | * |
| 439 | * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set |
| 440 | * of features", which is of limited interest when the system is already |
| 441 | * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since |
| 442 | * these are supported, it defaults to 0. |
| 443 | * This allows detecting the presence of this field since older versions of |
| 444 | * the EC codebase would simply return 0xff to that unknown address. Check |
| 445 | * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits |
| 446 | * are valid. |
| 447 | */ |
| 448 | #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a |
| 449 | #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b |
| 450 | #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c |
| 451 | #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d |
| 452 | #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e |
| 453 | #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f |
| 454 | #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 |
| 455 | #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 |
| 456 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 457 | #define EC_ACPI_MEM_BATTERY_INDEX 0x12 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 458 | |
| 459 | /* |
| 460 | * USB Port Power. Each bit indicates whether the corresponding USB ports' power |
| 461 | * is enabled (1) or disabled (0). |
| 462 | * bit 0 USB port ID 0 |
| 463 | * ... |
| 464 | * bit 7 USB port ID 7 |
| 465 | */ |
| 466 | #define EC_ACPI_MEM_USB_PORT_POWER 0x13 |
| 467 | |
| 468 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 469 | * USB Retimer firmware update. |
| 470 | * Read: |
| 471 | * Result of last operation AP requested |
| 472 | * Write: |
| 473 | * bits[3:0]: USB-C port number |
| 474 | * bits[7:4]: Operation requested by AP |
| 475 | * |
| 476 | * NDA (no device attached) case: |
| 477 | * To update retimer firmware, AP needs set up TBT Alt mode. |
| 478 | * AP requests operations in this sequence: |
| 479 | * 1. Get port information about which ports support retimer firmware update. |
| 480 | * In the query result, each bit represents one port. |
| 481 | * 2. Get current MUX mode, it's NDA. |
| 482 | * 3. Suspend specified PD port's task. |
| 483 | * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode -> |
| 484 | * update firmware -> disconnect MUX -> resume PD task. |
| 485 | * |
| 486 | * DA (device attached) cases: |
| 487 | * Retimer firmware update is not supported in DA cases. |
| 488 | * 1. Get port information about which ports support retimer firmware update |
| 489 | * 2. Get current MUX mode, it's DA. |
| 490 | * 3. AP continues. No more retimer firmware update activities. |
| 491 | * |
| 492 | */ |
| 493 | #define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14 |
| 494 | |
| 495 | #define USB_RETIMER_FW_UPDATE_OP_SHIFT 4 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 496 | #define USB_RETIMER_FW_UPDATE_ERR 0xfe |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 497 | #define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 498 | /* Mask to clear unused MUX bits in retimer firmware update */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 499 | #define USB_RETIMER_FW_UPDATE_MUX_MASK \ |
| 500 | (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED | \ |
| 501 | USB_PD_MUX_SAFE_MODE | USB_PD_MUX_TBT_COMPAT_ENABLED | \ |
| 502 | USB_PD_MUX_USB4_ENABLED) |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 503 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 504 | /* Retimer firmware update operations */ |
| 505 | #define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */ |
| 506 | #define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 507 | #define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */ |
| 508 | #define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */ |
| 509 | #define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */ |
| 510 | #define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */ |
| 511 | #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] | 512 | #define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */ |
| 513 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 514 | #define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x)&0x0f) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 515 | #define EC_ACPI_MEM_USB_RETIMER_OP(x) \ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 516 | (((x)&0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 517 | |
| 518 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 519 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 520 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 521 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 522 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 523 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 524 | |
| 525 | /* Current version of ACPI memory address space */ |
| 526 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 527 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 528 | /* |
| 529 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 530 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 531 | * handle actual C code so keep it separate. |
| 532 | */ |
| 533 | #ifndef __ACPI__ |
| 534 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 535 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 536 | /* |
| 537 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 538 | * checking prefers __packed over __attribute__((packed)). |
| 539 | */ |
| 540 | #ifndef __packed |
| 541 | #define __packed __attribute__((packed)) |
| 542 | #endif |
| 543 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 544 | #ifndef __aligned |
| 545 | #define __aligned(x) __attribute__((aligned(x))) |
| 546 | #endif |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 547 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * Attributes for EC request and response packets. Just defining __packed |
| 551 | * results in inefficient assembly code on ARM, if the structure is actually |
| 552 | * 32-bit aligned, as it should be for all buffers. |
| 553 | * |
| 554 | * Be very careful when adding these to existing structures. They will round |
| 555 | * up the structure size to the specified boundary. |
| 556 | * |
| 557 | * Also be very careful to make that if a structure is included in some other |
| 558 | * parent structure that the alignment will still be true given the packing of |
| 559 | * the parent structure. This is particularly important if the sub-structure |
| 560 | * 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] | 561 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 562 | * |
| 563 | * Also be very careful using __packed - particularly when nesting non-packed |
| 564 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 565 | * always use one of these attributes. |
| 566 | * |
| 567 | * Once everything is annotated properly, the following search strings should |
| 568 | * not return ANY matches in this file other than right here: |
| 569 | * |
| 570 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 571 | * |
| 572 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 573 | * members of other structs/unions (and their original declarations should be |
| 574 | * annotated). |
| 575 | */ |
| 576 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 577 | |
| 578 | /* |
| 579 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 580 | * byte boundary. |
| 581 | */ |
| 582 | #define __ec_align1 __packed |
| 583 | #define __ec_align2 __packed __aligned(2) |
| 584 | #define __ec_align4 __packed __aligned(4) |
| 585 | |
| 586 | /* |
| 587 | * Packed structure which must be under-aligned, because its size is not a |
| 588 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 589 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 590 | * |
| 591 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 592 | * its members, but use the __packed version for sizeof(). |
| 593 | */ |
| 594 | #define __ec_align_size1 __packed |
| 595 | |
| 596 | /* |
| 597 | * Packed structure which must be under-aligned, because its offset inside a |
| 598 | * parent structure is not a 4-byte multiple. |
| 599 | */ |
| 600 | #define __ec_align_offset1 __packed |
| 601 | #define __ec_align_offset2 __packed __aligned(2) |
| 602 | |
| 603 | /* |
| 604 | * Structures which are complicated enough that I'm skipping them on the first |
| 605 | * pass. They are effectively unchanged from their previous definitions. |
| 606 | * |
| 607 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 608 | * to work out the size and offset of each member and add explicit padding to |
| 609 | * maintain those. |
| 610 | */ |
| 611 | #define __ec_todo_packed __packed |
| 612 | #define __ec_todo_unpacked |
| 613 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 614 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 615 | |
| 616 | /* |
| 617 | * Packed structures make no assumption about alignment, so they do inefficient |
| 618 | * byte-wise reads. |
| 619 | */ |
| 620 | #define __ec_align1 __packed |
| 621 | #define __ec_align2 __packed |
| 622 | #define __ec_align4 __packed |
| 623 | #define __ec_align_size1 __packed |
| 624 | #define __ec_align_offset1 __packed |
| 625 | #define __ec_align_offset2 __packed |
| 626 | #define __ec_todo_packed __packed |
| 627 | #define __ec_todo_unpacked |
| 628 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 629 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 630 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 631 | /* LPC command status byte masks */ |
| 632 | /* 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] | 633 | #define EC_LPC_STATUS_TO_HOST 0x01 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 634 | /* 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] | 635 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 636 | /* EC is processing a command */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 637 | #define EC_LPC_STATUS_PROCESSING 0x04 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 638 | /* Last write to EC was a command, not data */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 639 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 640 | /* EC is in burst mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 641 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 642 | /* SCI event is pending (requesting SCI query) */ |
| 643 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 644 | /* SMI event is pending (requesting SMI query) */ |
| 645 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 646 | /* (reserved) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 647 | #define EC_LPC_STATUS_RESERVED 0x80 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 648 | |
| 649 | /* |
| 650 | * EC is busy. This covers both the EC processing a command, and the host has |
| 651 | * written a new command but the EC hasn't picked it up yet. |
| 652 | */ |
| 653 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 654 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 655 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 656 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 657 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 658 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 659 | enum ec_status { |
| 660 | EC_RES_SUCCESS = 0, |
| 661 | EC_RES_INVALID_COMMAND = 1, |
| 662 | EC_RES_ERROR = 2, |
| 663 | EC_RES_INVALID_PARAM = 3, |
| 664 | EC_RES_ACCESS_DENIED = 4, |
| 665 | EC_RES_INVALID_RESPONSE = 5, |
| 666 | EC_RES_INVALID_VERSION = 6, |
| 667 | EC_RES_INVALID_CHECKSUM = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 668 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 669 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 670 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 671 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
| 672 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 673 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
| 674 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
| 675 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
| 676 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 677 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 678 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 679 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 680 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 681 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 682 | EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 683 | } __packed; |
| 684 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 685 | |
| 686 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 687 | * Host event codes. ACPI query EC command uses code 0 to mean "no event |
| 688 | * pending". We explicitly specify each value in the enum listing so they won't |
| 689 | * change if we delete/insert an item or rearrange the list (it needs to be |
| 690 | * stable across platforms, not just within a single compiled instance). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 691 | */ |
| 692 | enum host_event_code { |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 693 | EC_HOST_EVENT_NONE = 0, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 694 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 695 | EC_HOST_EVENT_LID_OPEN = 2, |
| 696 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 697 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 698 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 699 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 700 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 701 | EC_HOST_EVENT_BATTERY = 8, |
| 702 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 703 | /* Event generated by a device attached to the EC */ |
| 704 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 705 | EC_HOST_EVENT_THERMAL = 11, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 706 | /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */ |
| 707 | EC_HOST_EVENT_GPU = 12, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 708 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 709 | /* |
| 710 | * EC has finished initializing the host interface. The host can check |
| 711 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 712 | * determine when the EC is ready to accept subsequent commands. |
| 713 | */ |
| 714 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 715 | /* Keyboard recovery combo has been pressed */ |
| 716 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 717 | |
| 718 | /* Shutdown due to thermal overload */ |
| 719 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 720 | /* Shutdown due to battery level too low */ |
| 721 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 722 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 723 | /* Suggest that the AP throttle itself */ |
| 724 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 725 | /* Suggest that the AP resume normal speed */ |
| 726 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 727 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 728 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 729 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 730 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 731 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 732 | |
| 733 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 734 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 735 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 736 | /* Battery Status flags have changed */ |
| 737 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 738 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 739 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 740 | EC_HOST_EVENT_PANIC = 24, |
| 741 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 742 | /* Keyboard fastboot combo has been pressed */ |
| 743 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 744 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 745 | /* EC RTC event occurred */ |
| 746 | EC_HOST_EVENT_RTC = 26, |
| 747 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 748 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 749 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 750 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 751 | /* EC desires to change state of host-controlled USB mux */ |
| 752 | EC_HOST_EVENT_USB_MUX = 28, |
| 753 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 754 | /* |
| 755 | * The device has changed "modes". This can be one of the following: |
| 756 | * |
| 757 | * - TABLET/LAPTOP mode |
| 758 | * - detachable base attach/detach event |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 759 | * - on body/off body transition event |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 760 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 761 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 762 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 763 | /* Keyboard recovery combo with hardware reinitialization */ |
| 764 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 765 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 766 | /* WoV */ |
| 767 | EC_HOST_EVENT_WOV = 31, |
| 768 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 769 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 770 | * The high bit of the event mask is not used as a host event code. If |
| 771 | * it reads back as set, then the entire event mask should be |
| 772 | * considered invalid by the host. This can happen when reading the |
| 773 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 774 | * not initialized on the EC, or improperly configured on the host. |
| 775 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 776 | EC_HOST_EVENT_INVALID = 32, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 777 | }; |
| 778 | /* Host event mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 779 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 780 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 781 | /* clang-format off */ |
| 782 | #define HOST_EVENT_TEXT \ |
| 783 | { \ |
| 784 | [EC_HOST_EVENT_NONE] = "NONE", \ |
| 785 | [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \ |
| 786 | [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \ |
| 787 | [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \ |
| 788 | [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \ |
| 789 | [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \ |
| 790 | [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \ |
| 791 | [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \ |
| 792 | [EC_HOST_EVENT_BATTERY] = "BATTERY", \ |
| 793 | [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \ |
| 794 | [EC_HOST_EVENT_DEVICE] = "DEVICE", \ |
| 795 | [EC_HOST_EVENT_THERMAL] = "THERMAL", \ |
| 796 | [EC_HOST_EVENT_GPU] = "GPU", \ |
| 797 | [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \ |
| 798 | [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \ |
| 799 | [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \ |
| 800 | [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \ |
| 801 | [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \ |
| 802 | [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \ |
| 803 | [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \ |
| 804 | [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \ |
| 805 | [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \ |
| 806 | [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \ |
| 807 | [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \ |
| 808 | [EC_HOST_EVENT_PANIC] = "PANIC", \ |
| 809 | [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \ |
| 810 | [EC_HOST_EVENT_RTC] = "RTC", \ |
| 811 | [EC_HOST_EVENT_MKBP] = "MKBP", \ |
| 812 | [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \ |
| 813 | [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \ |
| 814 | [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \ |
| 815 | "KEYBOARD_RECOVERY_HW_REINIT", \ |
| 816 | [EC_HOST_EVENT_WOV] = "WOV", \ |
| 817 | [EC_HOST_EVENT_INVALID] = "INVALID", \ |
| 818 | } |
| 819 | /* clang-format on */ |
| 820 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 821 | /** |
| 822 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 823 | * @flags: The host argument flags. |
| 824 | * @command_version: Command version. |
| 825 | * @data_size: The length of data. |
| 826 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 827 | * all params/response data bytes. |
| 828 | */ |
| 829 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 830 | uint8_t flags; |
| 831 | uint8_t command_version; |
| 832 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 833 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 834 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 835 | |
| 836 | /* Flags for ec_lpc_host_args.flags */ |
| 837 | /* |
| 838 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 839 | * params. |
| 840 | * |
| 841 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 842 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 843 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 844 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 845 | */ |
| 846 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 847 | /* |
| 848 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 849 | * |
| 850 | * If EC responds to a command and this flag is not set, this is an old-style |
| 851 | * response. Command version is 0 and response data from EC is at |
| 852 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 853 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 854 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 855 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 856 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 857 | /* |
| 858 | * Byte codes returned by EC over SPI interface. |
| 859 | * |
| 860 | * These can be used by the AP to debug the EC interface, and to determine |
| 861 | * when the EC is not in a state where it will ever get around to responding |
| 862 | * to the AP. |
| 863 | * |
| 864 | * Example of sequence of bytes read from EC for a current good transfer: |
| 865 | * 1. - - AP asserts chip select (CS#) |
| 866 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 867 | * 3. - - EC starts handling CS# interrupt |
| 868 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 869 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 870 | * bytes looking for EC_SPI_FRAME_START |
| 871 | * 6. - - EC finishes processing and sets up response |
| 872 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 873 | * 8. (response packet) - AP reads response packet |
| 874 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 875 | * 10 - - AP deasserts chip select |
| 876 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 877 | * next request |
| 878 | * |
| 879 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 880 | * the following byte values: |
| 881 | * EC_SPI_OLD_READY |
| 882 | * EC_SPI_RX_READY |
| 883 | * EC_SPI_RECEIVING |
| 884 | * EC_SPI_PROCESSING |
| 885 | * |
| 886 | * Then the EC found an error in the request, or was not ready for the request |
| 887 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 888 | * because the EC is unable to tell when the AP is done sending its request. |
| 889 | */ |
| 890 | |
| 891 | /* |
| 892 | * Framing byte which precedes a response packet from the EC. After sending a |
| 893 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 894 | * clock in the response packet. |
| 895 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 896 | #define EC_SPI_FRAME_START 0xec |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 897 | |
| 898 | /* |
| 899 | * Padding bytes which are clocked out after the end of a response packet. |
| 900 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 901 | #define EC_SPI_PAST_END 0xed |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 902 | |
| 903 | /* |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 904 | * 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] | 905 | * that the AP will send a valid packet header (starting with |
| 906 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 907 | * |
| 908 | * NOTE: Some SPI configurations place the Most Significant Bit on SDO when |
| 909 | * CS goes low. This macro has the Most Significant Bit set to zero, |
| 910 | * so SDO will not be driven high when CS goes low. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 911 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 912 | #define EC_SPI_RX_READY 0x78 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 913 | |
| 914 | /* |
| 915 | * EC has started receiving the request from the AP, but hasn't started |
| 916 | * processing it yet. |
| 917 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 918 | #define EC_SPI_RECEIVING 0xf9 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 919 | |
| 920 | /* 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] | 921 | #define EC_SPI_PROCESSING 0xfa |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 922 | |
| 923 | /* |
| 924 | * EC received bad data from the AP, such as a packet header with an invalid |
| 925 | * length. EC will ignore all data until chip select deasserts. |
| 926 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 927 | #define EC_SPI_RX_BAD_DATA 0xfb |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 928 | |
| 929 | /* |
| 930 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 931 | * chip select and started clocking data before the EC was ready to receive it. |
| 932 | * EC will ignore all data until chip select deasserts. |
| 933 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 934 | #define EC_SPI_NOT_READY 0xfc |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 935 | |
| 936 | /* |
| 937 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 938 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 939 | * a fully received packet but is not ready to respond yet. |
| 940 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 941 | #define EC_SPI_OLD_READY 0xfd |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 942 | |
| 943 | /*****************************************************************************/ |
| 944 | |
| 945 | /* |
| 946 | * Protocol version 2 for I2C and SPI send a request this way: |
| 947 | * |
| 948 | * 0 EC_CMD_VERSION0 + (command version) |
| 949 | * 1 Command number |
| 950 | * 2 Length of params = N |
| 951 | * 3..N+2 Params, if any |
| 952 | * N+3 8-bit checksum of bytes 0..N+2 |
| 953 | * |
| 954 | * The corresponding response is: |
| 955 | * |
| 956 | * 0 Result code (EC_RES_*) |
| 957 | * 1 Length of params = M |
| 958 | * 2..M+1 Params, if any |
| 959 | * M+2 8-bit checksum of bytes 0..M+1 |
| 960 | */ |
| 961 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 962 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 963 | #define EC_PROTO2_REQUEST_OVERHEAD \ |
| 964 | (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 965 | |
| 966 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 967 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 968 | #define EC_PROTO2_RESPONSE_OVERHEAD \ |
| 969 | (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 970 | |
| 971 | /* Parameter length was limited by the LPC interface */ |
| 972 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 973 | |
| 974 | /* Maximum request and response packet sizes for protocol version 2 */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 975 | #define EC_PROTO2_MAX_REQUEST_SIZE \ |
| 976 | (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE) |
| 977 | #define EC_PROTO2_MAX_RESPONSE_SIZE \ |
| 978 | (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 979 | |
| 980 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 981 | |
| 982 | /* |
| 983 | * Value written to legacy command port / prefix byte to indicate protocol |
| 984 | * 3+ structs are being used. Usage is bus-dependent. |
| 985 | */ |
| 986 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 987 | |
| 988 | #define EC_HOST_REQUEST_VERSION 3 |
| 989 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 990 | /** |
| 991 | * struct ec_host_request - Version 3 request from host. |
| 992 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 993 | * receives a header with a version it doesn't know how to |
| 994 | * parse. |
| 995 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 996 | * should total to 0. |
| 997 | * @command: Command to send (EC_CMD_...) |
| 998 | * @command_version: Command version. |
| 999 | * @reserved: Unused byte in current protocol version; set to 0. |
| 1000 | * @data_len: Length of data which follows this header. |
| 1001 | */ |
| 1002 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1003 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1004 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1005 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1006 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1007 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1008 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1009 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1010 | |
| 1011 | #define EC_HOST_RESPONSE_VERSION 3 |
| 1012 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1013 | /** |
| 1014 | * struct ec_host_response - Version 3 response from EC. |
| 1015 | * @struct_version: Struct version (=3). |
| 1016 | * @checksum: Checksum of response and data; sum of all bytes including |
| 1017 | * checksum should total to 0. |
| 1018 | * @result: EC's response to the command (separate from communication failure) |
| 1019 | * @data_len: Length of data which follows this header. |
| 1020 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 1021 | */ |
| 1022 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1023 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1024 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1025 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1026 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1027 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1028 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 1029 | |
| 1030 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1031 | |
| 1032 | /* |
| 1033 | * Host command protocol V4. |
| 1034 | * |
| 1035 | * Packets always start with a request or response header. They are followed |
| 1036 | * 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] | 1037 | * 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] | 1038 | * polynomial. |
| 1039 | * |
| 1040 | * Host algorithm when sending a request q: |
| 1041 | * |
| 1042 | * 101) tries_left=(some value, e.g. 3); |
| 1043 | * 102) q.seq_num++ |
| 1044 | * 103) q.seq_dup=0 |
| 1045 | * 104) Calculate q.header_crc. |
| 1046 | * 105) Send request q to EC. |
| 1047 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 1048 | * |
| 1049 | * 201) If r.struct_version != 4, go to 301. |
| 1050 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 1051 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 1052 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 1053 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 1054 | * 207) If r.seq_dup == 1, go to 301. |
| 1055 | * 208) Return error. |
| 1056 | * |
| 1057 | * 301) If --tries_left <= 0, return error. |
| 1058 | * 302) If q.seq_dup == 1, go to 105. |
| 1059 | * 303) q.seq_dup = 1 |
| 1060 | * 304) Go to 104. |
| 1061 | * |
| 1062 | * EC algorithm when receiving a request q. |
| 1063 | * EC has response buffer r, error buffer e. |
| 1064 | * |
| 1065 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 1066 | * and go to 301 |
| 1067 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 1068 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 1069 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 1070 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 1071 | * and go to 301. |
| 1072 | * 104) If q.seq_dup == 0, go to 201. |
| 1073 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 1074 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 1075 | * |
| 1076 | * 201) Process request q into response r. |
| 1077 | * 202) r.seq_num = q.seq_num |
| 1078 | * 203) r.seq_dup = q.seq_dup |
| 1079 | * 204) Calculate r.header_crc |
| 1080 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 1081 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 1082 | * 206) Send response r. |
| 1083 | * |
| 1084 | * 301) e.seq_num = q.seq_num |
| 1085 | * 302) e.seq_dup = q.seq_dup |
| 1086 | * 303) Calculate e.header_crc. |
| 1087 | * 304) Send error response e. |
| 1088 | */ |
| 1089 | |
| 1090 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1091 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1092 | /* |
| 1093 | * bits 0-3: struct_version: Structure version (=4) |
| 1094 | * bit 4: is_response: Is response (=0) |
| 1095 | * bits 5-6: seq_num: Sequence number |
| 1096 | * bit 7: seq_dup: Sequence duplicate flag |
| 1097 | */ |
| 1098 | uint8_t fields0; |
| 1099 | |
| 1100 | /* |
| 1101 | * bits 0-4: command_version: Command version |
| 1102 | * bits 5-6: Reserved (set 0, ignore on read) |
| 1103 | * bit 7: data_crc_present: Is data CRC present after data |
| 1104 | */ |
| 1105 | uint8_t fields1; |
| 1106 | |
| 1107 | /* Command code (EC_CMD_*) */ |
| 1108 | uint16_t command; |
| 1109 | |
| 1110 | /* Length of data which follows this header (not including data CRC) */ |
| 1111 | uint16_t data_len; |
| 1112 | |
| 1113 | /* Reserved (set 0, ignore on read) */ |
| 1114 | uint8_t reserved; |
| 1115 | |
| 1116 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1117 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1118 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1119 | |
| 1120 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1121 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1122 | /* |
| 1123 | * bits 0-3: struct_version: Structure version (=4) |
| 1124 | * bit 4: is_response: Is response (=1) |
| 1125 | * bits 5-6: seq_num: Sequence number |
| 1126 | * bit 7: seq_dup: Sequence duplicate flag |
| 1127 | */ |
| 1128 | uint8_t fields0; |
| 1129 | |
| 1130 | /* |
| 1131 | * bits 0-6: Reserved (set 0, ignore on read) |
| 1132 | * bit 7: data_crc_present: Is data CRC present after data |
| 1133 | */ |
| 1134 | uint8_t fields1; |
| 1135 | |
| 1136 | /* Result code (EC_RES_*) */ |
| 1137 | uint16_t result; |
| 1138 | |
| 1139 | /* Length of data which follows this header (not including data CRC) */ |
| 1140 | uint16_t data_len; |
| 1141 | |
| 1142 | /* Reserved (set 0, ignore on read) */ |
| 1143 | uint8_t reserved; |
| 1144 | |
| 1145 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 1146 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1147 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1148 | |
| 1149 | /* Fields in fields0 byte */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1150 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 1151 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 1152 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 1153 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 1154 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1155 | |
| 1156 | /* Fields in fields1 byte */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1157 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1158 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1159 | |
| 1160 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1161 | /* |
| 1162 | * Notes on commands: |
| 1163 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1164 | * 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] | 1165 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1166 | * specified, the command does not input or output data, respectively. |
| 1167 | * Parameter/response length is implicit in the structs. Some underlying |
| 1168 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1169 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1170 | * |
| 1171 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1172 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1173 | */ |
| 1174 | |
| 1175 | /*****************************************************************************/ |
| 1176 | /* General / test commands */ |
| 1177 | |
| 1178 | /* |
| 1179 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1180 | * changes. |
| 1181 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1182 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1183 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1184 | /** |
| 1185 | * struct ec_response_proto_version - Response to the proto version command. |
| 1186 | * @version: The protocol version. |
| 1187 | */ |
| 1188 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1189 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1190 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1191 | |
| 1192 | /* |
| 1193 | * Hello. This is a simple command to test the EC is responsive to |
| 1194 | * commands. |
| 1195 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1196 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1197 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1198 | /** |
| 1199 | * struct ec_params_hello - Parameters to the hello command. |
| 1200 | * @in_data: Pass anything here. |
| 1201 | */ |
| 1202 | struct ec_params_hello { |
| 1203 | uint32_t in_data; |
| 1204 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1205 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1206 | /** |
| 1207 | * struct ec_response_hello - Response to the hello command. |
| 1208 | * @out_data: Output will be in_data + 0x01020304. |
| 1209 | */ |
| 1210 | struct ec_response_hello { |
| 1211 | uint32_t out_data; |
| 1212 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1213 | |
| 1214 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1215 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1216 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1217 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1218 | EC_IMAGE_UNKNOWN = 0, |
| 1219 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1220 | EC_IMAGE_RW, |
| 1221 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1222 | EC_IMAGE_RO_B, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1223 | EC_IMAGE_RW_B, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1224 | }; |
| 1225 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1226 | /** |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1227 | * 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] | 1228 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1229 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1230 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1231 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1232 | */ |
| 1233 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1234 | char version_string_ro[32]; |
| 1235 | char version_string_rw[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1236 | char reserved[32]; /* Changed to cros_fwid_ro in version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1237 | uint32_t current_image; |
| 1238 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1239 | |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1240 | /** |
| 1241 | * struct ec_response_get_version_v1 - Response to the v1 get version command. |
| 1242 | * |
| 1243 | * ec_response_get_version_v1 is a strict superset of ec_response_get_version. |
| 1244 | * The v1 response changes the semantics of one field (reserved to cros_fwid_ro) |
| 1245 | * and adds one additional field (cros_fwid_rw). |
| 1246 | * |
| 1247 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1248 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1249 | * @cros_fwid_ro: Null-terminated RO CrOS FWID string. |
| 1250 | * @current_image: One of ec_image. |
| 1251 | * @cros_fwid_rw: Null-terminated RW CrOS FWID string. |
| 1252 | */ |
| 1253 | struct ec_response_get_version_v1 { |
| 1254 | char version_string_ro[32]; |
| 1255 | char version_string_rw[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1256 | 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] | 1257 | uint32_t current_image; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1258 | char cros_fwid_rw[32]; /* Added in version 1 */ |
Rob Barnes | 5ab1466 | 2021-09-17 10:24:45 -0600 | [diff] [blame] | 1259 | } __ec_align4; |
| 1260 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1261 | /* Read test - DEPRECATED */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1262 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1263 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1264 | /* |
| 1265 | * Get build information |
| 1266 | * |
| 1267 | * Response is null-terminated string. |
| 1268 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1269 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1270 | |
| 1271 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1272 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1273 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1274 | /** |
| 1275 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1276 | * @vendor: Null-terminated string for chip vendor. |
| 1277 | * @name: Null-terminated string for chip name. |
| 1278 | * @revision: Null-terminated string for chip mask version. |
| 1279 | */ |
| 1280 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1281 | char vendor[32]; |
| 1282 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1283 | char revision[32]; |
| 1284 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1285 | |
| 1286 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1287 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1288 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1289 | /** |
| 1290 | * struct ec_response_board_version - Response to the board version command. |
| 1291 | * @board_version: A monotonously incrementing number. |
| 1292 | */ |
| 1293 | struct ec_response_board_version { |
| 1294 | uint16_t board_version; |
| 1295 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1296 | |
| 1297 | /* |
| 1298 | * Read memory-mapped data. |
| 1299 | * |
| 1300 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1301 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1302 | * |
| 1303 | * Response is params.size bytes of data. |
| 1304 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1305 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1306 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1307 | /** |
| 1308 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1309 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1310 | * @size: Size to read in bytes. |
| 1311 | */ |
| 1312 | struct ec_params_read_memmap { |
| 1313 | uint8_t offset; |
| 1314 | uint8_t size; |
| 1315 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1316 | |
| 1317 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1318 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1319 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1320 | /** |
| 1321 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1322 | * @cmd: Command to check. |
| 1323 | */ |
| 1324 | struct ec_params_get_cmd_versions { |
| 1325 | uint8_t cmd; |
| 1326 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1327 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1328 | /** |
| 1329 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1330 | * versions (v1) |
| 1331 | * @cmd: Command to check. |
| 1332 | */ |
| 1333 | struct ec_params_get_cmd_versions_v1 { |
| 1334 | uint16_t cmd; |
| 1335 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1336 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1337 | /** |
| 1338 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1339 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1340 | * a desired version. |
| 1341 | */ |
| 1342 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1343 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1344 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1345 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1346 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1347 | * 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] | 1348 | * on lpc since it has its own out-of-band busy indicator. |
| 1349 | * |
| 1350 | * lpc must read the status from the command register. Attempting this on |
| 1351 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1352 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1353 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1354 | |
| 1355 | /* Avoid using ec_status which is for return values */ |
| 1356 | enum ec_comms_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1357 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1358 | }; |
| 1359 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1360 | /** |
| 1361 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1362 | * command. |
| 1363 | * @flags: Mask of enum ec_comms_status. |
| 1364 | */ |
| 1365 | struct ec_response_get_comms_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1366 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1367 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1368 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1369 | /* Fake a variety of responses, purely for testing purposes. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1370 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1371 | |
| 1372 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1373 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1374 | uint32_t ec_result; |
| 1375 | uint32_t ret_len; |
| 1376 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1377 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1378 | |
| 1379 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1380 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1381 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1382 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1383 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1384 | /* Get protocol information */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1385 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1386 | |
| 1387 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1388 | /* 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] | 1389 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1390 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1391 | /** |
| 1392 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1393 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1394 | * version n). |
| 1395 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1396 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1397 | * @flags: see EC_PROTOCOL_INFO_* |
| 1398 | */ |
| 1399 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1400 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1401 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1402 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1403 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1404 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1405 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1406 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1407 | /*****************************************************************************/ |
| 1408 | /* Get/Set miscellaneous values */ |
| 1409 | |
| 1410 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1411 | #define EC_GSV_SET 0x80000000 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1412 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1413 | /* |
| 1414 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1415 | * meaning for an individual command. |
| 1416 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1417 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1418 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1419 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1420 | uint32_t flags; |
| 1421 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1422 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1423 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1424 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1425 | uint32_t flags; |
| 1426 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1427 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1428 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1429 | /* More than one command can use these structs to get/set parameters. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1430 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1431 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1432 | /*****************************************************************************/ |
| 1433 | /* List the features supported by the firmware */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1434 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1435 | |
| 1436 | /* Supported features */ |
| 1437 | enum ec_feature_code { |
| 1438 | /* |
| 1439 | * This image contains a limited set of features. Another image |
| 1440 | * in RW partition may support more features. |
| 1441 | */ |
| 1442 | EC_FEATURE_LIMITED = 0, |
| 1443 | /* |
| 1444 | * Commands for probing/reading/writing/erasing the flash in the |
| 1445 | * EC are present. |
| 1446 | */ |
| 1447 | EC_FEATURE_FLASH = 1, |
| 1448 | /* |
| 1449 | * Can control the fan speed directly. |
| 1450 | */ |
| 1451 | EC_FEATURE_PWM_FAN = 2, |
| 1452 | /* |
| 1453 | * Can control the intensity of the keyboard backlight. |
| 1454 | */ |
| 1455 | EC_FEATURE_PWM_KEYB = 3, |
| 1456 | /* |
| 1457 | * Support Google lightbar, introduced on Pixel. |
| 1458 | */ |
| 1459 | EC_FEATURE_LIGHTBAR = 4, |
| 1460 | /* Control of LEDs */ |
| 1461 | EC_FEATURE_LED = 5, |
| 1462 | /* Exposes an interface to control gyro and sensors. |
| 1463 | * The host goes through the EC to access these sensors. |
| 1464 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1465 | */ |
| 1466 | EC_FEATURE_MOTION_SENSE = 6, |
| 1467 | /* The keyboard is controlled by the EC */ |
| 1468 | EC_FEATURE_KEYB = 7, |
| 1469 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1470 | EC_FEATURE_PSTORE = 8, |
| 1471 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1472 | EC_FEATURE_PORT80 = 9, |
| 1473 | /* |
| 1474 | * Thermal management: include TMP specific commands. |
| 1475 | * Higher level than direct fan control. |
| 1476 | */ |
| 1477 | EC_FEATURE_THERMAL = 10, |
| 1478 | /* Can switch the screen backlight on/off */ |
| 1479 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1480 | /* Can switch the wifi module on/off */ |
| 1481 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1482 | /* Monitor host events, through for example SMI or SCI */ |
| 1483 | EC_FEATURE_HOST_EVENTS = 13, |
| 1484 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1485 | EC_FEATURE_GPIO = 14, |
| 1486 | /* The EC can send i2c messages to downstream devices. */ |
| 1487 | EC_FEATURE_I2C = 15, |
| 1488 | /* Command to control charger are included */ |
| 1489 | EC_FEATURE_CHARGER = 16, |
| 1490 | /* Simple battery support. */ |
| 1491 | EC_FEATURE_BATTERY = 17, |
| 1492 | /* |
| 1493 | * Support Smart battery protocol |
| 1494 | * (Common Smart Battery System Interface Specification) |
| 1495 | */ |
| 1496 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1497 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1498 | EC_FEATURE_HANG_DETECT = 19, |
| 1499 | /* Report power information, for pit only */ |
| 1500 | EC_FEATURE_PMU = 20, |
| 1501 | /* Another Cros EC device is present downstream of this one */ |
| 1502 | EC_FEATURE_SUB_MCU = 21, |
| 1503 | /* Support USB Power delivery (PD) commands */ |
| 1504 | EC_FEATURE_USB_PD = 22, |
| 1505 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1506 | EC_FEATURE_USB_MUX = 23, |
| 1507 | /* Motion Sensor code has an internal software FIFO */ |
| 1508 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1509 | /* Support temporary secure vstore */ |
| 1510 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1511 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1512 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1513 | /* EC has RTC feature that can be controlled by host commands */ |
| 1514 | EC_FEATURE_RTC = 27, |
| 1515 | /* The MCU exposes a Fingerprint sensor */ |
| 1516 | EC_FEATURE_FINGERPRINT = 28, |
| 1517 | /* The MCU exposes a Touchpad */ |
| 1518 | EC_FEATURE_TOUCHPAD = 29, |
| 1519 | /* The MCU has RWSIG task enabled */ |
| 1520 | EC_FEATURE_RWSIG = 30, |
| 1521 | /* EC has device events support */ |
| 1522 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1523 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1524 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1525 | /* EC supports 64-bit host events */ |
| 1526 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1527 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1528 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1529 | /* EC supports CEC commands */ |
| 1530 | EC_FEATURE_CEC = 35, |
| 1531 | /* EC supports tight sensor timestamping. */ |
| 1532 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1533 | /* |
| 1534 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1535 | * setting of threshold by host command using |
| 1536 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1537 | */ |
| 1538 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1539 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1540 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1541 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1542 | * be sent to RO to be precise. |
| 1543 | */ |
| 1544 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1545 | /* The MCU is a System Companion Processor (SCP). */ |
| 1546 | EC_FEATURE_SCP = 39, |
| 1547 | /* The MCU is an Integrated Sensor Hub */ |
| 1548 | EC_FEATURE_ISH = 40, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 1549 | /* New TCPMv2 TYPEC_ prefaced commands supported */ |
| 1550 | EC_FEATURE_TYPEC_CMD = 41, |
| 1551 | /* |
| 1552 | * The EC will wait for direction from the AP to enter Type-C alternate |
| 1553 | * modes or USB4. |
| 1554 | */ |
| 1555 | EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42, |
| 1556 | /* |
| 1557 | * The EC will wait for an acknowledge from the AP after setting the |
| 1558 | * mux. |
| 1559 | */ |
| 1560 | EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 1561 | /* |
| 1562 | * The EC supports entering and residing in S4. |
| 1563 | */ |
| 1564 | EC_FEATURE_S4_RESIDENCY = 44, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 1565 | /* |
| 1566 | * The EC supports the AP directing mux sets for the board. |
| 1567 | */ |
| 1568 | EC_FEATURE_TYPEC_AP_MUX_SET = 45, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1569 | /* |
| 1570 | * The EC supports the AP composing VDMs for us to send. |
| 1571 | */ |
| 1572 | EC_FEATURE_TYPEC_AP_VDM_SEND = 46, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1573 | }; |
| 1574 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1575 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1576 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1577 | |
| 1578 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1579 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1580 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1581 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1582 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1583 | /* Get the board's SKU ID from EC */ |
| 1584 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1585 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1586 | /* Set SKU ID from AP */ |
| 1587 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1588 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1589 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1590 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1591 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1592 | |
| 1593 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1594 | /* Flash commands */ |
| 1595 | |
| 1596 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1597 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1598 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1599 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1600 | /** |
| 1601 | * struct ec_response_flash_info - Response to the flash info command. |
| 1602 | * @flash_size: Usable flash size in bytes. |
| 1603 | * @write_block_size: Write block size. Write offset and size must be a |
| 1604 | * multiple of this. |
| 1605 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1606 | * multiple of this. |
| 1607 | * @protect_block_size: Protection block size. Protection offset and size |
| 1608 | * must be a multiple of this. |
| 1609 | * |
| 1610 | * Version 0 returns these fields. |
| 1611 | */ |
| 1612 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1613 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1614 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1615 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1616 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1617 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1618 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1619 | /* |
| 1620 | * Flags for version 1+ flash info command |
| 1621 | * EC flash erases bits to 0 instead of 1. |
| 1622 | */ |
| 1623 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1624 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1625 | /* |
| 1626 | * 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] | 1627 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1628 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1629 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1630 | * chip functionality. |
| 1631 | */ |
| 1632 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1633 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1634 | /** |
| 1635 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1636 | * @flash_size: Usable flash size in bytes. |
| 1637 | * @write_block_size: Write block size. Write offset and size must be a |
| 1638 | * multiple of this. |
| 1639 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1640 | * multiple of this. |
| 1641 | * @protect_block_size: Protection block size. Protection offset and size |
| 1642 | * must be a multiple of this. |
| 1643 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1644 | * size is exactly this and offset is a multiple of this. |
| 1645 | * For example, an EC may have a write buffer which can do |
| 1646 | * half-page operations if data is aligned, and a slower |
| 1647 | * word-at-a-time write mode. |
| 1648 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1649 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1650 | * Version 1 returns the same initial fields as version 0, with additional |
| 1651 | * fields following. |
| 1652 | * |
| 1653 | * 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] | 1654 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1655 | * one. |
| 1656 | * |
| 1657 | * Version 2 supports flash banks of different sizes: |
| 1658 | * The caller specified the number of banks it has preallocated |
| 1659 | * (num_banks_desc) |
| 1660 | * The EC returns the number of banks describing the flash memory. |
| 1661 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1662 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1663 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1664 | /* Version 0 fields; see above for description */ |
| 1665 | uint32_t flash_size; |
| 1666 | uint32_t write_block_size; |
| 1667 | uint32_t erase_block_size; |
| 1668 | uint32_t protect_block_size; |
| 1669 | |
| 1670 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1671 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1672 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1673 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1674 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1675 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1676 | /* Number of banks to describe */ |
| 1677 | uint16_t num_banks_desc; |
| 1678 | /* Reserved; set 0; ignore on read */ |
| 1679 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1680 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1681 | |
| 1682 | struct ec_flash_bank { |
| 1683 | /* Number of sector is in this bank. */ |
| 1684 | uint16_t count; |
| 1685 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1686 | uint8_t size_exp; |
| 1687 | /* Minimal write size for the sectors in this bank */ |
| 1688 | uint8_t write_size_exp; |
| 1689 | /* Erase size for the sectors in this bank */ |
| 1690 | uint8_t erase_size_exp; |
| 1691 | /* Size for write protection, usually identical to erase size. */ |
| 1692 | uint8_t protect_size_exp; |
| 1693 | /* Reserved; set 0; ignore on read */ |
| 1694 | uint8_t reserved[2]; |
| 1695 | }; |
| 1696 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1697 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1698 | /* Total flash in the EC. */ |
| 1699 | uint32_t flash_size; |
| 1700 | /* Flags; see EC_FLASH_INFO_* */ |
| 1701 | uint32_t flags; |
| 1702 | /* Maximum size to use to send data to write to the EC. */ |
| 1703 | uint32_t write_ideal_size; |
| 1704 | /* Number of banks present in the EC. */ |
| 1705 | uint16_t num_banks_total; |
| 1706 | /* Number of banks described in banks array. */ |
| 1707 | uint16_t num_banks_desc; |
| 1708 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1709 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1710 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1711 | /* |
| 1712 | * Read flash |
| 1713 | * |
| 1714 | * Response is params.size bytes of data. |
| 1715 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1716 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1717 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1718 | /** |
| 1719 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1720 | * @offset: Byte offset to read. |
| 1721 | * @size: Size to read in bytes. |
| 1722 | */ |
| 1723 | struct ec_params_flash_read { |
| 1724 | uint32_t offset; |
| 1725 | uint32_t size; |
| 1726 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1727 | |
| 1728 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1729 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1730 | #define EC_VER_FLASH_WRITE 1 |
| 1731 | |
| 1732 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1733 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1734 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1735 | /** |
| 1736 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1737 | * @offset: Byte offset to write. |
| 1738 | * @size: Size to write in bytes. |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1739 | * @data: Data to write. |
| 1740 | * @data.words32: uint32_t data to write. |
| 1741 | * @data.bytes: uint8_t data to write. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1742 | */ |
| 1743 | struct ec_params_flash_write { |
| 1744 | uint32_t offset; |
| 1745 | uint32_t size; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1746 | /* Followed by data to write. This union allows accessing an |
| 1747 | * underlying buffer as uint32s or uint8s for convenience. |
| 1748 | */ |
| 1749 | union { |
| 1750 | uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1751 | uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1752 | } data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1753 | } __ec_align4; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1754 | BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1755 | |
| 1756 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1757 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1758 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1759 | /** |
| 1760 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1761 | * @offset: Byte offset to erase. |
| 1762 | * @size: Size to erase in bytes. |
| 1763 | */ |
| 1764 | struct ec_params_flash_erase { |
| 1765 | uint32_t offset; |
| 1766 | uint32_t size; |
| 1767 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1768 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1769 | /* |
| 1770 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1771 | * subcommands can returns: |
| 1772 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1773 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1774 | * EC_RES_ERROR : other errors. |
| 1775 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1776 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1777 | * |
| 1778 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1779 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1780 | * the proper result. |
| 1781 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1782 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1783 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1784 | * permitted while erasing. (For instance, STM32F4). |
| 1785 | */ |
| 1786 | enum ec_flash_erase_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1787 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1788 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1789 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1790 | }; |
| 1791 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1792 | /** |
| 1793 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1794 | * @cmd: One of ec_flash_erase_cmd. |
| 1795 | * @reserved: Pad byte; currently always contains 0. |
| 1796 | * @flag: No flags defined yet; set to 0. |
| 1797 | * @params: Same as v0 parameters. |
| 1798 | */ |
| 1799 | struct ec_params_flash_erase_v1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1800 | uint8_t cmd; |
| 1801 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1802 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1803 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1804 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1805 | |
| 1806 | /* |
| 1807 | * Get/set flash protection. |
| 1808 | * |
| 1809 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1810 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1811 | * some flags require a subsequent hard reset to take effect. Check the |
| 1812 | * returned flags bits to see what actually happened. |
| 1813 | * |
| 1814 | * If mask=0, simply returns the current flags state. |
| 1815 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1816 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1817 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1818 | |
| 1819 | /* Flags for flash protection */ |
| 1820 | /* RO flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1821 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1822 | /* |
| 1823 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1824 | * be changed. |
| 1825 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1826 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1827 | /* Entire flash code protected now, until reboot. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1828 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1829 | /* Flash write protect GPIO is asserted now */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1830 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1831 | /* 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] | 1832 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1833 | /* |
| 1834 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1835 | * flash which should be protected is not protected. Usually fixed by |
| 1836 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1837 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1838 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1839 | /* Entire flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1840 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1841 | /* RW flash code protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1842 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1843 | /* RW flash code protected now. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1844 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1845 | /* Rollback information flash region protected when the EC boots */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1846 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1847 | /* Rollback information flash region protected now */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1848 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 1849 | /* Error - Unknown error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1850 | #define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 1851 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1852 | /** |
| 1853 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1854 | * @mask: Bits in flags to apply. |
| 1855 | * @flags: New flags to apply. |
| 1856 | */ |
| 1857 | struct ec_params_flash_protect { |
| 1858 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1859 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1860 | } __ec_align4; |
| 1861 | |
| 1862 | /** |
| 1863 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1864 | * @flags: Current value of flash protect flags. |
| 1865 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1866 | * caller to distinguish between flags which aren't set vs. flags |
| 1867 | * which can't be set on this platform. |
| 1868 | * @writable_flags: Flags which can be changed given the current protection |
| 1869 | * state. |
| 1870 | */ |
| 1871 | struct ec_response_flash_protect { |
| 1872 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1873 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1874 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1875 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1876 | |
| 1877 | /* |
| 1878 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1879 | * write protect. These commands may be reused with version > 0. |
| 1880 | */ |
| 1881 | |
| 1882 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1883 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1884 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1885 | |
| 1886 | enum ec_flash_region { |
| 1887 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1888 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1889 | /* |
| 1890 | * Region which holds active RW image. 'Active' is different from |
| 1891 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1892 | * scheduled to run, active/non-active applies only to RW images (for |
| 1893 | * the same reason 'update' applies only to RW images. It's a state of |
| 1894 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1895 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1896 | * doesn't enter 'running' state but it's still active on a flash. |
| 1897 | */ |
| 1898 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1899 | /* |
| 1900 | * Region which should be write-protected in the factory (a superset of |
| 1901 | * EC_FLASH_REGION_RO) |
| 1902 | */ |
| 1903 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1904 | /* Region which holds updatable (non-active) RW image */ |
| 1905 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1906 | /* Number of regions */ |
| 1907 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1908 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1909 | /* |
| 1910 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1911 | * so the old constant is deprecated. |
| 1912 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1913 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1914 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1915 | /** |
| 1916 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1917 | * command. |
| 1918 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1919 | */ |
| 1920 | struct ec_params_flash_region_info { |
| 1921 | uint32_t region; |
| 1922 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1923 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1924 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1925 | uint32_t offset; |
| 1926 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1927 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1928 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1929 | /* Get SPI flash information */ |
| 1930 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1931 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1932 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1933 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1934 | uint8_t jedec[3]; |
| 1935 | |
| 1936 | /* Pad byte; currently always contains 0 */ |
| 1937 | uint8_t reserved0; |
| 1938 | |
| 1939 | /* Manufacturer / device ID from command 0x90 */ |
| 1940 | uint8_t mfr_dev_id[2]; |
| 1941 | |
| 1942 | /* Status registers from command 0x05 and 0x35 */ |
| 1943 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1944 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1945 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1946 | /* Select flash during flash operations */ |
| 1947 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1948 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1949 | /** |
| 1950 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1951 | * @select: 1 to select flash, 0 to deselect flash |
| 1952 | */ |
| 1953 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1954 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1955 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1956 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1957 | /** |
| 1958 | * Request random numbers to be generated and returned. |
| 1959 | * Can be used to test the random number generator is truly random. |
| 1960 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1961 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1962 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1963 | #define EC_CMD_RAND_NUM 0x001A |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1964 | #define EC_VER_RAND_NUM 0 |
| 1965 | |
| 1966 | struct ec_params_rand_num { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 1967 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1968 | } __ec_align4; |
| 1969 | |
| 1970 | struct ec_response_rand_num { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 1971 | /** |
| 1972 | * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true |
| 1973 | * size of rand is determined by ec_params_rand_num's num_rand_bytes. |
| 1974 | */ |
| 1975 | uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE]; |
| 1976 | } __ec_align1; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1977 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1978 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1979 | /** |
| 1980 | * Get information about the key used to sign the RW firmware. |
| 1981 | * For more details on the fields, see "struct vb21_packed_key". |
| 1982 | */ |
| 1983 | #define EC_CMD_RWSIG_INFO 0x001B |
| 1984 | #define EC_VER_RWSIG_INFO 0 |
| 1985 | |
| 1986 | #define VBOOT2_KEY_ID_BYTES 20 |
| 1987 | |
| 1988 | #ifdef CHROMIUM_EC |
| 1989 | /* Don't force external projects to depend on the vboot headers. */ |
| 1990 | #include "vb21_struct.h" |
| 1991 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 1992 | #endif |
| 1993 | |
| 1994 | struct ec_response_rwsig_info { |
| 1995 | /** |
| 1996 | * Signature algorithm used by the key |
| 1997 | * (enum vb2_signature_algorithm). |
| 1998 | */ |
| 1999 | uint16_t sig_alg; |
| 2000 | |
| 2001 | /** |
| 2002 | * Hash digest algorithm used with the key |
| 2003 | * (enum vb2_hash_algorithm). |
| 2004 | */ |
| 2005 | uint16_t hash_alg; |
| 2006 | |
| 2007 | /** Key version. */ |
| 2008 | uint32_t key_version; |
| 2009 | |
| 2010 | /** Key ID (struct vb2_id). */ |
| 2011 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 2012 | |
| 2013 | uint8_t key_is_valid; |
| 2014 | |
| 2015 | /** Alignment padding. */ |
| 2016 | uint8_t reserved[3]; |
| 2017 | } __ec_align4; |
| 2018 | |
| 2019 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 2020 | |
| 2021 | /** |
| 2022 | * Get information about the system, such as reset flags, locked state, etc. |
| 2023 | */ |
| 2024 | #define EC_CMD_SYSINFO 0x001C |
| 2025 | #define EC_VER_SYSINFO 0 |
| 2026 | |
| 2027 | enum sysinfo_flags { |
| 2028 | SYSTEM_IS_LOCKED = BIT(0), |
| 2029 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 2030 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 2031 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2032 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4), |
| 2033 | /* |
| 2034 | * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is |
| 2035 | * set and cleared when the system shuts down (not when the host event |
| 2036 | * flag is cleared). |
| 2037 | */ |
| 2038 | SYSTEM_IN_MANUAL_RECOVERY = BIT(5), |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2039 | }; |
| 2040 | |
| 2041 | struct ec_response_sysinfo { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2042 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2043 | uint32_t current_image; /**< enum ec_image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2044 | uint32_t flags; /**< enum sysinfo_flags */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2045 | } __ec_align4; |
| 2046 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2047 | /*****************************************************************************/ |
| 2048 | /* PWM commands */ |
| 2049 | |
| 2050 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2051 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2053 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2054 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2055 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2056 | |
| 2057 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2058 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2059 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2060 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2061 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2062 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2063 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2064 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2065 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2066 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2067 | uint32_t rpm; |
| 2068 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2069 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2070 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2071 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2072 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2073 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2074 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2075 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2076 | uint8_t percent; |
| 2077 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2078 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2079 | |
| 2080 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2081 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2082 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2083 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2084 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2085 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2086 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2087 | |
| 2088 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2089 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2090 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2091 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2092 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2093 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2094 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2095 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2096 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2097 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2098 | uint32_t percent; |
| 2099 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2100 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2101 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2102 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2103 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 2104 | #define EC_PWM_MAX_DUTY 0xffff |
| 2105 | |
| 2106 | enum ec_pwm_type { |
| 2107 | /* All types, indexed by board-specific enum pwm_channel */ |
| 2108 | EC_PWM_TYPE_GENERIC = 0, |
| 2109 | /* Keyboard backlight */ |
| 2110 | EC_PWM_TYPE_KB_LIGHT, |
| 2111 | /* Display backlight */ |
| 2112 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 2113 | EC_PWM_TYPE_COUNT, |
| 2114 | }; |
| 2115 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2116 | struct ec_params_pwm_set_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2117 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 2118 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2119 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2120 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2121 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2122 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2123 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2124 | struct ec_params_pwm_get_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2125 | uint8_t pwm_type; /* ec_pwm_type */ |
| 2126 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2127 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2128 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2129 | struct ec_response_pwm_get_duty { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2130 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2131 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2132 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2133 | /*****************************************************************************/ |
| 2134 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2135 | * 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] | 2136 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 2137 | * into a subcommand. We'll make separate structs for subcommands with |
| 2138 | * different input args, so that we know how much to expect. |
| 2139 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2140 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2141 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2142 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2143 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2144 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2145 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2146 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2147 | |
| 2148 | /* |
| 2149 | * 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] | 2150 | * host command, but the alignment is the same regardless. Keep it that way. |
| 2151 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2152 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2153 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2154 | int32_t google_ramp_up; |
| 2155 | int32_t google_ramp_down; |
| 2156 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2157 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2158 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2159 | int32_t s0s3_ramp_down; |
| 2160 | int32_t s3_sleep_for; |
| 2161 | int32_t s3_ramp_up; |
| 2162 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2163 | |
| 2164 | /* Oscillation */ |
| 2165 | uint8_t new_s0; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2166 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2167 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2168 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2169 | |
| 2170 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2171 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2172 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2173 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2174 | |
| 2175 | /* Battery level thresholds */ |
| 2176 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2177 | |
| 2178 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2179 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2180 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2181 | |
| 2182 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2183 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2184 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2185 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2186 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2187 | /* Timing */ |
| 2188 | int32_t google_ramp_up; |
| 2189 | int32_t google_ramp_down; |
| 2190 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2191 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2192 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2193 | int32_t s0s3_ramp_down; |
| 2194 | int32_t s3_sleep_for; |
| 2195 | int32_t s3_ramp_up; |
| 2196 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2197 | int32_t s5_ramp_up; |
| 2198 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2199 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2200 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2201 | int32_t tap_display_time; |
| 2202 | |
| 2203 | /* Tap-for-battery params */ |
| 2204 | uint8_t tap_pct_red; |
| 2205 | uint8_t tap_pct_green; |
| 2206 | uint8_t tap_seg_min_on; |
| 2207 | uint8_t tap_seg_max_on; |
| 2208 | uint8_t tap_seg_osc; |
| 2209 | uint8_t tap_idx[3]; |
| 2210 | |
| 2211 | /* Oscillation */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2212 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2213 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2214 | uint8_t w_ofs[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2215 | |
| 2216 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2217 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2218 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2219 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2220 | |
| 2221 | /* Battery level thresholds */ |
| 2222 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2223 | |
| 2224 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2225 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2226 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2227 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2228 | /* s5: single color pulse on inhibited power-up */ |
| 2229 | uint8_t s5_idx; |
| 2230 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2231 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2232 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2233 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2234 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2235 | /* Lightbar command params v2 |
| 2236 | * crbug.com/467716 |
| 2237 | * |
| 2238 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2239 | * logical groups to make it more manageable ( < 120 bytes). |
| 2240 | * |
| 2241 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2242 | */ |
| 2243 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2244 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2245 | /* Timing */ |
| 2246 | int32_t google_ramp_up; |
| 2247 | int32_t google_ramp_down; |
| 2248 | int32_t s3s0_ramp_up; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2249 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2250 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2251 | int32_t s0s3_ramp_down; |
| 2252 | int32_t s3_sleep_for; |
| 2253 | int32_t s3_ramp_up; |
| 2254 | int32_t s3_ramp_down; |
| 2255 | int32_t s5_ramp_up; |
| 2256 | int32_t s5_ramp_down; |
| 2257 | int32_t tap_tick_delay; |
| 2258 | int32_t tap_gate_delay; |
| 2259 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2260 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2261 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2262 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2263 | /* Tap-for-battery params */ |
| 2264 | uint8_t tap_pct_red; |
| 2265 | uint8_t tap_pct_green; |
| 2266 | uint8_t tap_seg_min_on; |
| 2267 | uint8_t tap_seg_max_on; |
| 2268 | uint8_t tap_seg_osc; |
| 2269 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2270 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2271 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2272 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2273 | /* Oscillation */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2274 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2275 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2276 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2277 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2278 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2279 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2280 | /* Brightness limits based on the backlight and AC. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2281 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2282 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2283 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2284 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2285 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2286 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2287 | /* Battery level thresholds */ |
| 2288 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2289 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2290 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2291 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2292 | /* Map [AC][battery_level] to color index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2293 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2294 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2295 | |
| 2296 | /* s5: single color pulse on inhibited power-up */ |
| 2297 | uint8_t s5_idx; |
| 2298 | |
| 2299 | /* Color palette */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2300 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2301 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2302 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2303 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2304 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2305 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2306 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2307 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2308 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2309 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2310 | struct ec_params_lightbar { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2311 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2312 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2313 | /* |
| 2314 | * The following commands have no args: |
| 2315 | * |
| 2316 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2317 | * version, get_brightness, get_demo, suspend, resume, |
| 2318 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2319 | * get_params_v2_bright, get_params_v2_thlds, |
| 2320 | * get_params_v2_colors |
| 2321 | * |
| 2322 | * Don't use an empty struct, because C++ hates that. |
| 2323 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2324 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2325 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2326 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2327 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2328 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2329 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2330 | uint8_t ctrl, reg, value; |
| 2331 | } reg; |
| 2332 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2333 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2334 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2335 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2336 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2337 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2338 | uint8_t led; |
| 2339 | } get_rgb; |
| 2340 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2341 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2342 | uint8_t enable; |
| 2343 | } manual_suspend_ctrl; |
| 2344 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2345 | struct lightbar_params_v0 set_params_v0; |
| 2346 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2347 | |
| 2348 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2349 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2350 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2351 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2352 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2353 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2354 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2355 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2356 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2357 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2358 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2359 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2360 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2361 | struct __ec_todo_unpacked { |
| 2362 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2363 | uint8_t reg; |
| 2364 | uint8_t ic0; |
| 2365 | uint8_t ic1; |
| 2366 | } vals[23]; |
| 2367 | } dump; |
| 2368 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2369 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2370 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2371 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2372 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2373 | struct lightbar_params_v0 get_params_v0; |
| 2374 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2375 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2376 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2377 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2378 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2379 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2380 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2381 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2382 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2383 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2384 | uint32_t num; |
| 2385 | uint32_t flags; |
| 2386 | } version; |
| 2387 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2388 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2389 | uint8_t red, green, blue; |
| 2390 | } get_rgb; |
| 2391 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2392 | /* |
| 2393 | * The following commands have no response: |
| 2394 | * |
| 2395 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2396 | * set_params_v0, set_params_v1, set_program, |
| 2397 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2398 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2399 | * set_v2par_thlds, set_v2par_colors |
| 2400 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2401 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2402 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2403 | |
| 2404 | /* Lightbar commands */ |
| 2405 | enum lightbar_command { |
| 2406 | LIGHTBAR_CMD_DUMP = 0, |
| 2407 | LIGHTBAR_CMD_OFF = 1, |
| 2408 | LIGHTBAR_CMD_ON = 2, |
| 2409 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2410 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2411 | LIGHTBAR_CMD_SEQ = 5, |
| 2412 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2413 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2414 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2415 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2416 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2417 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2418 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2419 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2420 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2421 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2422 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2423 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2424 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2425 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2426 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2427 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2428 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2429 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2430 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2431 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2432 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2433 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2434 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2435 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2436 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2437 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2438 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2439 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2440 | LIGHTBAR_NUM_CMDS, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2441 | }; |
| 2442 | |
| 2443 | /*****************************************************************************/ |
| 2444 | /* LED control commands */ |
| 2445 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2446 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2447 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2448 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2449 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2450 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2451 | /* |
| 2452 | * LED to indicate system power state (on or in suspend). |
| 2453 | * May be on power button or on C-panel. |
| 2454 | */ |
| 2455 | EC_LED_ID_POWER_LED, |
| 2456 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2457 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2458 | /* LED to indicate left side */ |
| 2459 | EC_LED_ID_LEFT_LED, |
| 2460 | /* LED to indicate right side */ |
| 2461 | EC_LED_ID_RIGHT_LED, |
| 2462 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2463 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2464 | /* LED to indicate sysrq debug mode. */ |
| 2465 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2466 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2467 | EC_LED_ID_COUNT, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2468 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2469 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2470 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2471 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2472 | #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] | 2473 | |
| 2474 | enum ec_led_colors { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2475 | EC_LED_COLOR_INVALID = -1, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2476 | EC_LED_COLOR_RED = 0, |
| 2477 | EC_LED_COLOR_GREEN, |
| 2478 | EC_LED_COLOR_BLUE, |
| 2479 | EC_LED_COLOR_YELLOW, |
| 2480 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2481 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2482 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2483 | EC_LED_COLOR_COUNT, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2484 | }; |
| 2485 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2486 | struct ec_params_led_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2487 | uint8_t led_id; /* Which LED to control */ |
| 2488 | uint8_t flags; /* Control flags */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2489 | |
| 2490 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2491 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2492 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2493 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2494 | /* |
| 2495 | * Available brightness value range. |
| 2496 | * |
| 2497 | * Range 0 means color channel not present. |
| 2498 | * Range 1 means on/off control. |
| 2499 | * Other values means the LED is control by PWM. |
| 2500 | */ |
| 2501 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2502 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2503 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2504 | /*****************************************************************************/ |
| 2505 | /* Verified boot commands */ |
| 2506 | |
| 2507 | /* |
| 2508 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2509 | * reused for other purposes with version > 0. |
| 2510 | */ |
| 2511 | |
| 2512 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2513 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2514 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2515 | struct ec_params_vboot_hash { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2516 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2517 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2518 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2519 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2520 | uint32_t offset; /* Offset in flash to hash */ |
| 2521 | uint32_t size; /* Number of bytes to hash */ |
| 2522 | 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] | 2523 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2524 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2525 | struct ec_response_vboot_hash { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2526 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2527 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2528 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2529 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2530 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2531 | uint32_t size; /* Number of bytes hashed */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2532 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2533 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2534 | |
| 2535 | enum ec_vboot_hash_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2536 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2537 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2538 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2539 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2540 | }; |
| 2541 | |
| 2542 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2543 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2544 | }; |
| 2545 | |
| 2546 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2547 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2548 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2549 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2550 | }; |
| 2551 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2552 | /* |
| 2553 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2554 | * If one of these is specified, the EC will automatically update offset and |
| 2555 | * size to the correct values for the specified image (RO or RW). |
| 2556 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2557 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2558 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2559 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2560 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2561 | /* |
| 2562 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2563 | * so the old constant is deprecated. |
| 2564 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2565 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2566 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2567 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2568 | /* |
| 2569 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2570 | * different input args, so that we know how much to expect. |
| 2571 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2572 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2573 | |
| 2574 | /* Motion sense commands */ |
| 2575 | enum motionsense_command { |
| 2576 | /* |
| 2577 | * Dump command returns all motion sensor data including motion sense |
| 2578 | * module flags and individual sensor flags. |
| 2579 | */ |
| 2580 | MOTIONSENSE_CMD_DUMP = 0, |
| 2581 | |
| 2582 | /* |
| 2583 | * Info command returns data describing the details of a given sensor, |
| 2584 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2585 | * enum motionsensor_chip. |
| 2586 | */ |
| 2587 | MOTIONSENSE_CMD_INFO = 1, |
| 2588 | |
| 2589 | /* |
| 2590 | * 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] | 2591 | * in milliseconds. |
| 2592 | * It is per sensor, the EC run sample task at the minimum of all |
| 2593 | * sensors EC_RATE. |
| 2594 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2595 | * to collect all the sensor samples. |
| 2596 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2597 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2598 | */ |
| 2599 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2600 | |
| 2601 | /* |
| 2602 | * Sensor ODR command is a setter/getter command for the output data |
| 2603 | * rate of a specific motion sensor in millihertz. |
| 2604 | */ |
| 2605 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2606 | |
| 2607 | /* |
| 2608 | * Sensor range command is a setter/getter command for the range of |
| 2609 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2610 | */ |
| 2611 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2612 | |
| 2613 | /* |
| 2614 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2615 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2616 | * and when the lid angle goes less than this value, keyboard wake is |
| 2617 | * enabled. Note, the lid angle measurement is an approximate, |
| 2618 | * un-calibrated value, hence the wake angle isn't exact. |
| 2619 | */ |
| 2620 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2621 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2622 | /* |
| 2623 | * Returns a single sensor data. |
| 2624 | */ |
| 2625 | MOTIONSENSE_CMD_DATA = 6, |
| 2626 | |
| 2627 | /* |
| 2628 | * Return sensor fifo info. |
| 2629 | */ |
| 2630 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2631 | |
| 2632 | /* |
| 2633 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2634 | * The host can use that element to synchronize its operation. |
| 2635 | */ |
| 2636 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2637 | |
| 2638 | /* |
| 2639 | * Return a portion of the fifo. |
| 2640 | */ |
| 2641 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2642 | |
| 2643 | /* |
| 2644 | * Perform low level calibration. |
| 2645 | * On sensors that support it, ask to do offset calibration. |
| 2646 | */ |
| 2647 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2648 | |
| 2649 | /* |
| 2650 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2651 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2652 | * The offsets can be calculated by the host, or via |
| 2653 | * PERFORM_CALIB command. |
| 2654 | */ |
| 2655 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2656 | |
| 2657 | /* |
| 2658 | * List available activities for a MOTION sensor. |
| 2659 | * Indicates if they are enabled or disabled. |
| 2660 | */ |
| 2661 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2662 | |
| 2663 | /* |
| 2664 | * Activity management |
| 2665 | * Enable/Disable activity recognition. |
| 2666 | */ |
| 2667 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2668 | |
| 2669 | /* |
| 2670 | * Lid Angle |
| 2671 | */ |
| 2672 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2673 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2674 | /* |
| 2675 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2676 | * By default the FIFO does not send interrupt to process the FIFO |
| 2677 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2678 | */ |
| 2679 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2680 | |
| 2681 | /* |
| 2682 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2683 | * to arbitrary values, or will lock to the last read actual values. |
| 2684 | */ |
| 2685 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2686 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2687 | /* Set lid angle for tablet mode detection. */ |
| 2688 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2689 | |
| 2690 | /* |
| 2691 | * Sensor Scale command is a setter/getter command for the calibration |
| 2692 | * scale. |
| 2693 | */ |
| 2694 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2695 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2696 | /* |
| 2697 | * Read the current online calibration values (if available). |
| 2698 | */ |
| 2699 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2700 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2701 | /* |
| 2702 | * Activity management |
| 2703 | * Retrieve current status of given activity. |
| 2704 | */ |
| 2705 | MOTIONSENSE_CMD_GET_ACTIVITY = 20, |
| 2706 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2707 | /* Number of motionsense sub-commands. */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2708 | MOTIONSENSE_NUM_CMDS, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2709 | }; |
| 2710 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2711 | /* List of motion sensor types. */ |
| 2712 | enum motionsensor_type { |
| 2713 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2714 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2715 | MOTIONSENSE_TYPE_MAG = 2, |
| 2716 | MOTIONSENSE_TYPE_PROX = 3, |
| 2717 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2718 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2719 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2720 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2721 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2722 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2723 | }; |
| 2724 | |
| 2725 | /* List of motion sensor locations. */ |
| 2726 | enum motionsensor_location { |
| 2727 | MOTIONSENSE_LOC_BASE = 0, |
| 2728 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2729 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2730 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2731 | }; |
| 2732 | |
| 2733 | /* List of motion sensor chips. */ |
| 2734 | enum motionsensor_chip { |
| 2735 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2736 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2737 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2738 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2739 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2740 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2741 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2742 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2743 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2744 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2745 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2746 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2747 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2748 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2749 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2750 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2751 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2752 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2753 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2754 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2755 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2756 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2757 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2758 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2759 | MOTIONSENSE_CHIP_BMI260 = 24, |
| 2760 | MOTIONSENSE_CHIP_ICM426XX = 25, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2761 | MOTIONSENSE_CHIP_ICM42607 = 26, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 2762 | MOTIONSENSE_CHIP_BMA422 = 27, |
| 2763 | MOTIONSENSE_CHIP_BMI323 = 28, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 2764 | MOTIONSENSE_CHIP_BMI220 = 29, |
| 2765 | MOTIONSENSE_CHIP_CM32183 = 30, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2766 | MOTIONSENSE_CHIP_MAX, |
| 2767 | }; |
| 2768 | |
| 2769 | /* List of orientation positions */ |
| 2770 | enum motionsensor_orientation { |
| 2771 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2772 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2773 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2774 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2775 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2776 | }; |
| 2777 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2778 | struct ec_response_activity_data { |
| 2779 | uint8_t activity; /* motionsensor_activity */ |
| 2780 | uint8_t state; |
| 2781 | } __ec_todo_packed; |
| 2782 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2783 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2784 | /* Flags for each sensor. */ |
| 2785 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2786 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2787 | uint8_t sensor_num; |
| 2788 | /* Each sensor is up to 3-axis. */ |
| 2789 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2790 | int16_t data[3]; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2791 | /* for sensors using unsigned data */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2792 | uint16_t udata[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2793 | struct __ec_todo_packed { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2794 | uint16_t reserved; |
| 2795 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2796 | }; |
| 2797 | struct __ec_todo_unpacked { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 2798 | struct ec_response_activity_data activity_data; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2799 | int16_t add_info[2]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2800 | }; |
| 2801 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2802 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2803 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2804 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2805 | struct ec_response_online_calibration_data { |
| 2806 | /** The calibration values. */ |
| 2807 | int16_t data[3]; |
| 2808 | }; |
| 2809 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2810 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2811 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2812 | /* Size of the fifo */ |
| 2813 | uint16_t size; |
| 2814 | /* Amount of space used in the fifo */ |
| 2815 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2816 | /* Timestamp recorded in us. |
| 2817 | * aka accurate timestamp when host event was triggered. |
| 2818 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2819 | uint32_t timestamp; |
| 2820 | /* Total amount of vector lost */ |
| 2821 | uint16_t total_lost; |
| 2822 | /* Lost events since the last fifo_info, per sensors */ |
| 2823 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2824 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2825 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2826 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2827 | uint32_t number_data; |
| 2828 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2829 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2830 | |
| 2831 | /* List supported activity recognition */ |
| 2832 | enum motionsensor_activity { |
| 2833 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2834 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2835 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2836 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 2837 | MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2838 | }; |
| 2839 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2840 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2841 | uint8_t sensor_num; |
| 2842 | uint8_t activity; /* one of enum motionsensor_activity */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 2843 | uint8_t enable; /* 1: enable, 0: disable */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2844 | uint8_t reserved; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2845 | uint16_t parameters[4]; /* activity dependent parameters */ |
| 2846 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2847 | |
| 2848 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2849 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2850 | |
| 2851 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2852 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2853 | |
| 2854 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2855 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2856 | * data contains time stamp |
| 2857 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2858 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2859 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2860 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2861 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2862 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2863 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 2864 | #define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7) |
| 2865 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2866 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2867 | * Send this value for the data element to only perform a read. If you |
| 2868 | * send any other value, the EC will interpret it as data to set and will |
| 2869 | * return the actual value set. |
| 2870 | */ |
| 2871 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2872 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 2873 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2874 | |
| 2875 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2876 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2877 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2878 | |
| 2879 | /* Default Scale value, factor 1. */ |
| 2880 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2881 | |
| 2882 | #define LID_ANGLE_UNRELIABLE 500 |
| 2883 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2884 | enum motionsense_spoof_mode { |
| 2885 | /* Disable spoof mode. */ |
| 2886 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2887 | |
| 2888 | /* Enable spoof mode, but use provided component values. */ |
| 2889 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2890 | |
| 2891 | /* Enable spoof mode, but use the current sensor values. */ |
| 2892 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2893 | |
| 2894 | /* Query the current spoof mode status for the sensor. */ |
| 2895 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2896 | }; |
| 2897 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2898 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2899 | uint8_t cmd; |
| 2900 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2901 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2902 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2903 | /* |
| 2904 | * Maximal number of sensor the host is expecting. |
| 2905 | * 0 means the host is only interested in the number |
| 2906 | * of sensors controlled by the EC. |
| 2907 | */ |
| 2908 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2909 | } dump; |
| 2910 | |
| 2911 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2912 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2913 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2914 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2915 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 2916 | * kb_wake_angle: angle to wakup AP. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2917 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2918 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2919 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2920 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2921 | /* |
| 2922 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2923 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2924 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2925 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2926 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2927 | |
| 2928 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2929 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2930 | * Allow entering/exiting the calibration mode. |
| 2931 | */ |
| 2932 | struct __ec_todo_unpacked { |
| 2933 | uint8_t sensor_num; |
| 2934 | uint8_t enable; |
| 2935 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2936 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2937 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2938 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2939 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2940 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2941 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2942 | uint8_t sensor_num; |
| 2943 | |
| 2944 | /* Rounding flag, true for round-up, false for down. */ |
| 2945 | uint8_t roundup; |
| 2946 | |
| 2947 | uint16_t reserved; |
| 2948 | |
| 2949 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2950 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2951 | } ec_rate, sensor_odr, sensor_range; |
| 2952 | |
| 2953 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2954 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2955 | uint8_t sensor_num; |
| 2956 | |
| 2957 | /* |
| 2958 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2959 | * the calibration information in the EC. |
| 2960 | * If unset, just retrieve calibration information. |
| 2961 | */ |
| 2962 | uint16_t flags; |
| 2963 | |
| 2964 | /* |
| 2965 | * Temperature at calibration, in units of 0.01 C |
| 2966 | * 0x8000: invalid / unknown. |
| 2967 | * 0x0: 0C |
| 2968 | * 0x7fff: +327.67C |
| 2969 | */ |
| 2970 | int16_t temp; |
| 2971 | |
| 2972 | /* |
| 2973 | * Offset for calibration. |
| 2974 | * Unit: |
| 2975 | * Accelerometer: 1/1024 g |
| 2976 | * Gyro: 1/1024 deg/s |
| 2977 | * Compass: 1/16 uT |
| 2978 | */ |
| 2979 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2980 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2981 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2982 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2983 | struct __ec_todo_packed { |
| 2984 | uint8_t sensor_num; |
| 2985 | |
| 2986 | /* |
| 2987 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2988 | * the calibration information in the EC. |
| 2989 | * If unset, just retrieve calibration information. |
| 2990 | */ |
| 2991 | uint16_t flags; |
| 2992 | |
| 2993 | /* |
| 2994 | * Temperature at calibration, in units of 0.01 C |
| 2995 | * 0x8000: invalid / unknown. |
| 2996 | * 0x0: 0C |
| 2997 | * 0x7fff: +327.67C |
| 2998 | */ |
| 2999 | int16_t temp; |
| 3000 | |
| 3001 | /* |
| 3002 | * Scale for calibration: |
| 3003 | * By default scale is 1, it is encoded on 16bits: |
| 3004 | * 1 = BIT(15) |
| 3005 | * ~2 = 0xFFFF |
| 3006 | * ~0 = 0. |
| 3007 | */ |
| 3008 | uint16_t scale[3]; |
| 3009 | } sensor_scale; |
| 3010 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3011 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3012 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3013 | |
| 3014 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
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 | /* |
| 3017 | * Number of expected vector to return. |
| 3018 | * EC may return less or 0 if none available. |
| 3019 | */ |
| 3020 | uint32_t max_data_vector; |
| 3021 | } fifo_read; |
| 3022 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3023 | /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3024 | struct ec_motion_sense_activity set_activity; |
| 3025 | |
| 3026 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3027 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3028 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3029 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 3030 | struct __ec_todo_unpacked { |
| 3031 | /* |
| 3032 | * 1: enable, 0 disable fifo, |
| 3033 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 3034 | */ |
| 3035 | int8_t enable; |
| 3036 | } fifo_int_enable; |
| 3037 | |
| 3038 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 3039 | struct __ec_todo_packed { |
| 3040 | uint8_t sensor_id; |
| 3041 | |
| 3042 | /* See enum motionsense_spoof_mode. */ |
| 3043 | uint8_t spoof_enable; |
| 3044 | |
| 3045 | /* Ignored, used for alignment. */ |
| 3046 | uint8_t reserved; |
| 3047 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 3048 | union { |
| 3049 | /* Individual component values to spoof. */ |
| 3050 | int16_t components[3]; |
| 3051 | |
| 3052 | /* Used when spoofing an activity */ |
| 3053 | struct { |
| 3054 | /* enum motionsensor_activity */ |
| 3055 | uint8_t activity_num; |
| 3056 | |
| 3057 | /* spoof activity state */ |
| 3058 | uint8_t activity_state; |
| 3059 | }; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3060 | } __ec_todo_packed; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3061 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3062 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3063 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3064 | struct __ec_todo_unpacked { |
| 3065 | /* |
| 3066 | * Lid angle threshold for switching between tablet and |
| 3067 | * clamshell mode. |
| 3068 | */ |
| 3069 | int16_t lid_angle; |
| 3070 | |
| 3071 | /* |
| 3072 | * Hysteresis degree to prevent fluctuations between |
| 3073 | * clamshell and tablet mode if lid angle keeps |
| 3074 | * changing around the threshold. Lid motion driver will |
| 3075 | * use lid_angle + hys_degree to trigger tablet mode and |
| 3076 | * lid_angle - hys_degree to trigger clamshell mode. |
| 3077 | */ |
| 3078 | int16_t hys_degree; |
| 3079 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3080 | |
| 3081 | /* |
| 3082 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 3083 | * Allow reading a single sensor's online calibration value. |
| 3084 | */ |
| 3085 | struct __ec_todo_unpacked { |
| 3086 | uint8_t sensor_num; |
| 3087 | } online_calib_read; |
| 3088 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3089 | /* |
| 3090 | * Used for MOTIONSENSE_CMD_GET_ACTIVITY. |
| 3091 | */ |
| 3092 | struct __ec_todo_unpacked { |
| 3093 | uint8_t sensor_num; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3094 | uint8_t activity; /* enum motionsensor_activity */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3095 | } get_activity; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3096 | } __ec_todo_packed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3097 | } __ec_todo_packed; |
| 3098 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3099 | enum motion_sense_cmd_info_flags { |
| 3100 | /* The sensor supports online calibration */ |
| 3101 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 3102 | }; |
| 3103 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3104 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3105 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3106 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3107 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3108 | /* Flags representing the motion sensor module. */ |
| 3109 | uint8_t module_flags; |
| 3110 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3111 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3112 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3113 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3114 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3115 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3116 | * for holding all the data. |
| 3117 | */ |
| 3118 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3119 | } dump; |
| 3120 | |
| 3121 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3122 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3123 | /* Should be element of enum motionsensor_type. */ |
| 3124 | uint8_t type; |
| 3125 | |
| 3126 | /* Should be element of enum motionsensor_location. */ |
| 3127 | uint8_t location; |
| 3128 | |
| 3129 | /* Should be element of enum motionsensor_chip. */ |
| 3130 | uint8_t chip; |
| 3131 | } info; |
| 3132 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3133 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 3134 | struct __ec_todo_unpacked { |
| 3135 | /* Should be element of enum motionsensor_type. */ |
| 3136 | uint8_t type; |
| 3137 | |
| 3138 | /* Should be element of enum motionsensor_location. */ |
| 3139 | uint8_t location; |
| 3140 | |
| 3141 | /* Should be element of enum motionsensor_chip. */ |
| 3142 | uint8_t chip; |
| 3143 | |
| 3144 | /* Minimum sensor sampling frequency */ |
| 3145 | uint32_t min_frequency; |
| 3146 | |
| 3147 | /* Maximum sensor sampling frequency */ |
| 3148 | uint32_t max_frequency; |
| 3149 | |
| 3150 | /* Max number of sensor events that could be in fifo */ |
| 3151 | uint32_t fifo_max_event_count; |
| 3152 | } info_3; |
| 3153 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 3154 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 3155 | struct __ec_align4 { |
| 3156 | /* Should be element of enum motionsensor_type. */ |
| 3157 | uint8_t type; |
| 3158 | |
| 3159 | /* Should be element of enum motionsensor_location. */ |
| 3160 | uint8_t location; |
| 3161 | |
| 3162 | /* Should be element of enum motionsensor_chip. */ |
| 3163 | uint8_t chip; |
| 3164 | |
| 3165 | /* Minimum sensor sampling frequency */ |
| 3166 | uint32_t min_frequency; |
| 3167 | |
| 3168 | /* Maximum sensor sampling frequency */ |
| 3169 | uint32_t max_frequency; |
| 3170 | |
| 3171 | /* Max number of sensor events that could be in fifo */ |
| 3172 | uint32_t fifo_max_event_count; |
| 3173 | |
| 3174 | /* |
| 3175 | * Should be elements of |
| 3176 | * enum motion_sense_cmd_info_flags |
| 3177 | */ |
| 3178 | uint32_t flags; |
| 3179 | } info_4; |
| 3180 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3181 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 3182 | struct ec_response_motion_sensor_data data; |
| 3183 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3184 | /* |
| 3185 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3186 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 3187 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 3188 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 3189 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3190 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3191 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3192 | /* Current value of the parameter queried. */ |
| 3193 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3194 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3195 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3196 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3197 | /* |
| 3198 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 3199 | * PERFORM_CALIB. |
| 3200 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3201 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3202 | int16_t temp; |
| 3203 | int16_t offset[3]; |
| 3204 | } sensor_offset, perform_calib; |
| 3205 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3206 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3207 | struct __ec_todo_unpacked { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3208 | int16_t temp; |
| 3209 | uint16_t scale[3]; |
| 3210 | } sensor_scale; |
| 3211 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3212 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3213 | |
| 3214 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3215 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3216 | struct ec_response_online_calibration_data online_calib_read; |
| 3217 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3218 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3219 | uint16_t reserved; |
| 3220 | uint32_t enabled; |
| 3221 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3222 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3223 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3224 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3225 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3226 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3227 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3228 | /* |
| 3229 | * Angle between 0 and 360 degree if available, |
| 3230 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3231 | */ |
| 3232 | uint16_t value; |
| 3233 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3234 | |
| 3235 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3236 | struct __ec_todo_unpacked { |
| 3237 | /* |
| 3238 | * Lid angle threshold for switching between tablet and |
| 3239 | * clamshell mode. |
| 3240 | */ |
| 3241 | uint16_t lid_angle; |
| 3242 | |
| 3243 | /* Hysteresis degree. */ |
| 3244 | uint16_t hys_degree; |
| 3245 | } tablet_mode_threshold; |
| 3246 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 3247 | /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */ |
| 3248 | struct __ec_todo_unpacked { |
| 3249 | uint8_t state; |
| 3250 | } get_activity; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3251 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3252 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3253 | |
| 3254 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3255 | /* Force lid open command */ |
| 3256 | |
| 3257 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3258 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3259 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3260 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3261 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3262 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3263 | |
| 3264 | /*****************************************************************************/ |
| 3265 | /* Configure the behavior of the power button */ |
| 3266 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3267 | |
| 3268 | enum ec_config_power_button_flags { |
| 3269 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3270 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3271 | }; |
| 3272 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3273 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3274 | /* See enum ec_config_power_button_flags */ |
| 3275 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3276 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3277 | |
| 3278 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3279 | /* USB charging control commands */ |
| 3280 | |
| 3281 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3282 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3283 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3284 | enum usb_charge_mode { |
| 3285 | /* Disable USB port. */ |
| 3286 | USB_CHARGE_MODE_DISABLED, |
| 3287 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3288 | USB_CHARGE_MODE_SDP2, |
| 3289 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3290 | USB_CHARGE_MODE_CDP, |
| 3291 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3292 | USB_CHARGE_MODE_DCP_SHORT, |
| 3293 | /* Enable USB port (for dumb ports). */ |
| 3294 | USB_CHARGE_MODE_ENABLED, |
| 3295 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3296 | USB_CHARGE_MODE_DEFAULT, |
| 3297 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3298 | USB_CHARGE_MODE_COUNT, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3299 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3300 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3301 | enum usb_suspend_charge { |
| 3302 | /* Enable charging in suspend */ |
| 3303 | USB_ALLOW_SUSPEND_CHARGE, |
| 3304 | /* Disable charging in suspend */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3305 | USB_DISALLOW_SUSPEND_CHARGE, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3306 | }; |
| 3307 | |
| 3308 | struct ec_params_usb_charge_set_mode { |
| 3309 | uint8_t usb_port_id; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3310 | uint8_t mode : 7; /* enum usb_charge_mode */ |
| 3311 | uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3312 | } __ec_align1; |
| 3313 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3314 | /*****************************************************************************/ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3315 | /* Tablet mode commands */ |
| 3316 | |
| 3317 | /* Set tablet mode */ |
| 3318 | #define EC_CMD_SET_TABLET_MODE 0x0031 |
| 3319 | |
| 3320 | enum tablet_mode_override { |
| 3321 | TABLET_MODE_DEFAULT, |
| 3322 | TABLET_MODE_FORCE_TABLET, |
| 3323 | TABLET_MODE_FORCE_CLAMSHELL, |
| 3324 | }; |
| 3325 | |
| 3326 | struct ec_params_set_tablet_mode { |
| 3327 | uint8_t tablet_mode; /* enum tablet_mode_override */ |
| 3328 | } __ec_align1; |
| 3329 | |
| 3330 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3331 | /* Persistent storage for host */ |
| 3332 | |
| 3333 | /* Maximum bytes that can be read/written in a single command */ |
| 3334 | #define EC_PSTORE_SIZE_MAX 64 |
| 3335 | |
| 3336 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3337 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3338 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3339 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3340 | /* Persistent storage size, in bytes */ |
| 3341 | uint32_t pstore_size; |
| 3342 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3343 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3344 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3345 | |
| 3346 | /* |
| 3347 | * Read persistent storage |
| 3348 | * |
| 3349 | * Response is params.size bytes of data. |
| 3350 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3351 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3352 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3353 | struct ec_params_pstore_read { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3354 | uint32_t offset; /* Byte offset to read */ |
| 3355 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3356 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3357 | |
| 3358 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3359 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3360 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3361 | struct ec_params_pstore_write { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3362 | uint32_t offset; /* Byte offset to write */ |
| 3363 | uint32_t size; /* Size to write in bytes */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3364 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3365 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3366 | |
| 3367 | /*****************************************************************************/ |
| 3368 | /* Real-time clock */ |
| 3369 | |
| 3370 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3371 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3372 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3373 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3374 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3375 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3376 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3377 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3378 | |
| 3379 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3380 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3381 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3382 | |
| 3383 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3384 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3385 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3386 | |
| 3387 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3388 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3389 | |
| 3390 | /*****************************************************************************/ |
| 3391 | /* Port80 log access */ |
| 3392 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3393 | /* Maximum entries that can be read/written in a single command */ |
| 3394 | #define EC_PORT80_SIZE_MAX 32 |
| 3395 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3396 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3397 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3398 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3399 | |
| 3400 | enum ec_port80_subcmd { |
| 3401 | EC_PORT80_GET_INFO = 0, |
| 3402 | EC_PORT80_READ_BUFFER, |
| 3403 | }; |
| 3404 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3405 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3406 | uint16_t subcmd; |
| 3407 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3408 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3409 | uint32_t offset; |
| 3410 | uint32_t num_entries; |
| 3411 | } read_buffer; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3412 | } __ec_todo_packed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3413 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3414 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3415 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3416 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3417 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3418 | uint32_t writes; |
| 3419 | uint32_t history_size; |
| 3420 | uint32_t last_boot; |
| 3421 | } get_info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3422 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3423 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3424 | } data; |
| 3425 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3426 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3427 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3428 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3429 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3430 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3431 | |
| 3432 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3433 | /* Temporary secure storage for host verified boot use */ |
| 3434 | |
| 3435 | /* Number of bytes in a vstore slot */ |
| 3436 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3437 | |
| 3438 | /* Maximum number of vstore slots */ |
| 3439 | #define EC_VSTORE_SLOT_MAX 32 |
| 3440 | |
| 3441 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3442 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3443 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3444 | /* Indicates which slots are locked */ |
| 3445 | uint32_t slot_locked; |
| 3446 | /* Total number of slots available */ |
| 3447 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3448 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3449 | |
| 3450 | /* |
| 3451 | * Read temporary secure storage |
| 3452 | * |
| 3453 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3454 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3455 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3456 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3457 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3458 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3459 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3460 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3461 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3462 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3463 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3464 | |
| 3465 | /* |
| 3466 | * Write temporary secure storage and lock it. |
| 3467 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3468 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3469 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3470 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3471 | uint8_t slot; /* Slot to write to */ |
| 3472 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3473 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3474 | |
| 3475 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3476 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3477 | * reuse the command number, but the data and behavior is incompatible. |
| 3478 | * Version 0 is what originally shipped on Link. |
| 3479 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3480 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3481 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3482 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3483 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3484 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3485 | /* The version 0 structs are opaque. You have to know what they are for |
| 3486 | * the get/set commands to make any sense. |
| 3487 | */ |
| 3488 | |
| 3489 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3490 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3491 | uint8_t sensor_type; |
| 3492 | uint8_t threshold_id; |
| 3493 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3494 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3495 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3496 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3497 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3498 | uint8_t sensor_type; |
| 3499 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3500 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3501 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3502 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3503 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3504 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3505 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3506 | /* The version 1 structs are visible. */ |
| 3507 | enum ec_temp_thresholds { |
| 3508 | EC_TEMP_THRESH_WARN = 0, |
| 3509 | EC_TEMP_THRESH_HIGH, |
| 3510 | EC_TEMP_THRESH_HALT, |
| 3511 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3512 | EC_TEMP_THRESH_COUNT, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3513 | }; |
| 3514 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3515 | /* |
| 3516 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3517 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3518 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3519 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3520 | * hysteresis. |
| 3521 | * For example, |
| 3522 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3523 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3524 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3525 | * temperature <= 299 K. |
| 3526 | * |
| 3527 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3528 | * For example, |
| 3529 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3530 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3531 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3532 | * temperature <= 294 K. |
| 3533 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3534 | * Note that this structure is a sub-structure of |
| 3535 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3536 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3537 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3538 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3539 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3540 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3541 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3542 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3543 | |
| 3544 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3545 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3546 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3547 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3548 | /* This returns a struct ec_thermal_config */ |
| 3549 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3550 | /* |
| 3551 | * Version 1 - set config for one sensor. |
| 3552 | * Use read-modify-write for best results! |
| 3553 | */ |
| 3554 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3555 | uint32_t sensor_num; |
| 3556 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3557 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3558 | /* This returns no data */ |
| 3559 | |
| 3560 | /****************************************************************************/ |
| 3561 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3562 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3563 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3564 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3565 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3566 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3567 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3568 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3569 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3570 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3571 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3572 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3573 | |
| 3574 | /* |
| 3575 | * The original TMP006 calibration only needed four params, but now we need |
| 3576 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3577 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3578 | * and how many params it requires. That way we can change the EC code without |
| 3579 | * needing to update this file. We can also use a different algorithm on each |
| 3580 | * sensor. |
| 3581 | */ |
| 3582 | |
| 3583 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3584 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3585 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3586 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3587 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3588 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3589 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3590 | float s0; |
| 3591 | float b0; |
| 3592 | float b1; |
| 3593 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3594 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3595 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3596 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3597 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3598 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3599 | float s0; |
| 3600 | float b0; |
| 3601 | float b1; |
| 3602 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3603 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3604 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3605 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3606 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3607 | uint8_t algorithm; |
| 3608 | uint8_t num_params; |
| 3609 | uint8_t reserved[2]; |
| 3610 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3611 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3612 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3613 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3614 | uint8_t index; |
| 3615 | uint8_t algorithm; |
| 3616 | uint8_t num_params; |
| 3617 | uint8_t reserved; |
| 3618 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3619 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3620 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3621 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3622 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3623 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3624 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3625 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3626 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3627 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3628 | struct ec_response_tmp006_get_raw { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3629 | int32_t t; /* In 1/100 K */ |
| 3630 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3631 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3632 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3633 | /*****************************************************************************/ |
| 3634 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3635 | |
| 3636 | /* |
| 3637 | * Read key state |
| 3638 | * |
| 3639 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3640 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3641 | * |
| 3642 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3643 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3644 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3645 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3646 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3647 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3648 | /* |
| 3649 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3650 | */ |
| 3651 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3652 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3653 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3654 | uint32_t rows; |
| 3655 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3656 | /* Formerly "switches", which was 0. */ |
| 3657 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3658 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3659 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3660 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3661 | uint8_t info_type; |
| 3662 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3663 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3664 | |
| 3665 | enum ec_mkbp_info_type { |
| 3666 | /* |
| 3667 | * Info about the keyboard matrix: number of rows and columns. |
| 3668 | * |
| 3669 | * Returns struct ec_response_mkbp_info. |
| 3670 | */ |
| 3671 | EC_MKBP_INFO_KBD = 0, |
| 3672 | |
| 3673 | /* |
| 3674 | * For buttons and switches, info about which specifically are |
| 3675 | * supported. event_type must be set to one of the values in enum |
| 3676 | * ec_mkbp_event. |
| 3677 | * |
| 3678 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3679 | * bitmask indicating which buttons or switches are present. See the |
| 3680 | * bit inidices below. |
| 3681 | */ |
| 3682 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3683 | |
| 3684 | /* |
| 3685 | * Instantaneous state of buttons and switches. |
| 3686 | * |
| 3687 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3688 | * |
| 3689 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3690 | * indicating the current state of the keyboard matrix. |
| 3691 | * |
| 3692 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3693 | * event state. |
| 3694 | * |
| 3695 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3696 | * state of supported buttons. |
| 3697 | * |
| 3698 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3699 | * state of supported switches. |
| 3700 | */ |
| 3701 | EC_MKBP_INFO_CURRENT = 2, |
| 3702 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3703 | |
| 3704 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3705 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3706 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3707 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3708 | uint8_t col; |
| 3709 | uint8_t row; |
| 3710 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3711 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3712 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3713 | #define EC_CMD_GET_KEYBOARD_ID 0x0063 |
| 3714 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3715 | struct ec_response_keyboard_id { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3716 | uint32_t keyboard_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3717 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3718 | |
| 3719 | enum keyboard_id { |
| 3720 | KEYBOARD_ID_UNSUPPORTED = 0, |
| 3721 | KEYBOARD_ID_UNREADABLE = 0xffffffff, |
| 3722 | }; |
| 3723 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3724 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3725 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3726 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3727 | |
| 3728 | /* flags */ |
| 3729 | enum mkbp_config_flags { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3730 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3731 | }; |
| 3732 | |
| 3733 | enum mkbp_config_valid { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3734 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3735 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3736 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3737 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3738 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3739 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3740 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3741 | }; |
| 3742 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3743 | /* |
| 3744 | * Configuration for our key scanning algorithm. |
| 3745 | * |
| 3746 | * Note that this is used as a sub-structure of |
| 3747 | * ec_{params/response}_mkbp_get_config. |
| 3748 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3749 | struct ec_mkbp_config { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3750 | uint32_t valid_mask; /* valid fields */ |
| 3751 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3752 | uint8_t valid_flags; /* which flags are valid */ |
| 3753 | uint16_t scan_period_us; /* period between start of scans */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3754 | /* revert to interrupt mode after no activity for this long */ |
| 3755 | uint32_t poll_timeout_us; |
| 3756 | /* |
| 3757 | * minimum post-scan relax time. Once we finish a scan we check |
| 3758 | * the time until we are due to start the next one. If this time is |
| 3759 | * shorter this field, we use this instead. |
| 3760 | */ |
| 3761 | uint16_t min_post_scan_delay_us; |
| 3762 | /* delay between setting up output and waiting for it to settle */ |
| 3763 | uint16_t output_settle_us; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3764 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3765 | uint16_t debounce_up_us; /* time for debounce on key up */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3766 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3767 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3768 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3769 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3770 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3771 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3772 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3773 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3774 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3775 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3776 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3777 | |
| 3778 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3779 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3780 | |
| 3781 | enum ec_keyscan_seq_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3782 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3783 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3784 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3785 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3786 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3787 | }; |
| 3788 | |
| 3789 | enum ec_collect_flags { |
| 3790 | /* |
| 3791 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3792 | * scans may be skipped. |
| 3793 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3794 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3795 | }; |
| 3796 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3797 | struct ec_collect_item { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3798 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3799 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3800 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3801 | struct ec_params_keyscan_seq_ctrl { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3802 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3803 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3804 | struct __ec_align1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3805 | uint8_t active; /* still active */ |
| 3806 | uint8_t num_items; /* number of items */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3807 | /* Current item being presented */ |
| 3808 | uint8_t cur_item; |
| 3809 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3810 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3811 | /* |
| 3812 | * Absolute time for this scan, measured from the |
| 3813 | * start of the sequence. |
| 3814 | */ |
| 3815 | uint32_t time_us; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3816 | uint8_t scan[0]; /* keyscan data */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3817 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3818 | struct __ec_align1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3819 | uint8_t start_item; /* First item to return */ |
| 3820 | uint8_t num_items; /* Number of items to return */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3821 | } collect; |
| 3822 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3823 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3824 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3825 | struct ec_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3826 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3827 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3828 | uint8_t num_items; /* Number of items */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3829 | /* Data for each item */ |
| 3830 | struct ec_collect_item item[0]; |
| 3831 | } collect; |
| 3832 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3833 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3834 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3835 | /* |
| 3836 | * Get the next pending MKBP event. |
| 3837 | * |
| 3838 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3839 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3840 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3841 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3842 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3843 | |
| 3844 | /* |
| 3845 | * We use the most significant bit of the event type to indicate to the host |
| 3846 | * that the EC has more MKBP events available to provide. |
| 3847 | */ |
| 3848 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3849 | |
| 3850 | /* The mask to apply to get the raw event type */ |
| 3851 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3852 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3853 | enum ec_mkbp_event { |
| 3854 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3855 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3856 | |
| 3857 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3858 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3859 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3860 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3861 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3862 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3863 | /* The state of the non-matrixed buttons have changed. */ |
| 3864 | EC_MKBP_EVENT_BUTTON = 3, |
| 3865 | |
| 3866 | /* The state of the switches have changed. */ |
| 3867 | EC_MKBP_EVENT_SWITCH = 4, |
| 3868 | |
| 3869 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3870 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3871 | |
| 3872 | /* |
| 3873 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3874 | * corresponding to the key to be pressed. |
| 3875 | */ |
| 3876 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3877 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3878 | /* |
| 3879 | * New 64-bit host event. |
| 3880 | * The event data is 8 bytes of host event flags. |
| 3881 | */ |
| 3882 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3883 | |
| 3884 | /* Notify the AP that something happened on CEC */ |
| 3885 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3886 | |
| 3887 | /* Send an incoming CEC message to the AP */ |
| 3888 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3889 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3890 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3891 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3892 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3893 | /* New online calibration values are available. */ |
| 3894 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3895 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 3896 | /* Peripheral device charger event */ |
| 3897 | EC_MKBP_EVENT_PCHG = 12, |
| 3898 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3899 | /* Number of MKBP events */ |
| 3900 | EC_MKBP_EVENT_COUNT, |
| 3901 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3902 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3903 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 3904 | /* clang-format off */ |
| 3905 | #define EC_MKBP_EVENT_TEXT \ |
| 3906 | { \ |
| 3907 | [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \ |
| 3908 | [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \ |
| 3909 | [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \ |
| 3910 | [EC_MKBP_EVENT_BUTTON] = "BUTTON", \ |
| 3911 | [EC_MKBP_EVENT_SWITCH] = "SWITCH", \ |
| 3912 | [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \ |
| 3913 | [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \ |
| 3914 | [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \ |
| 3915 | [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \ |
| 3916 | [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \ |
| 3917 | [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \ |
| 3918 | [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \ |
| 3919 | [EC_MKBP_EVENT_PCHG] = "PCHG", \ |
| 3920 | } |
| 3921 | /* clang-format on */ |
| 3922 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3923 | union __ec_align_offset1 ec_response_get_next_data { |
| 3924 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3925 | |
| 3926 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3927 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3928 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3929 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3930 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3931 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3932 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3933 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3934 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3935 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3936 | uint32_t buttons; |
| 3937 | |
| 3938 | uint32_t switches; |
| 3939 | |
| 3940 | uint32_t fp_events; |
| 3941 | |
| 3942 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3943 | |
| 3944 | /* CEC events from enum mkbp_cec_event */ |
| 3945 | uint32_t cec_events; |
| 3946 | }; |
| 3947 | |
| 3948 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3949 | uint8_t key_matrix[16]; |
| 3950 | |
| 3951 | /* Unaligned */ |
| 3952 | uint32_t host_event; |
| 3953 | uint64_t host_event64; |
| 3954 | |
| 3955 | struct __ec_todo_unpacked { |
| 3956 | /* For aligning the fifo_info */ |
| 3957 | uint8_t reserved[3]; |
| 3958 | struct ec_response_motion_sense_fifo_info info; |
| 3959 | } sensor_fifo; |
| 3960 | |
| 3961 | uint32_t buttons; |
| 3962 | |
| 3963 | uint32_t switches; |
| 3964 | |
| 3965 | uint32_t fp_events; |
| 3966 | |
| 3967 | uint32_t sysrq; |
| 3968 | |
| 3969 | /* CEC events from enum mkbp_cec_event */ |
| 3970 | uint32_t cec_events; |
| 3971 | |
| 3972 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3973 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3974 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3975 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3976 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3977 | uint8_t event_type; |
| 3978 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3979 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3980 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3981 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3982 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3983 | uint8_t event_type; |
| 3984 | /* Followed by event data if any */ |
| 3985 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3986 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3987 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3988 | /* Bit indices for buttons and switches.*/ |
| 3989 | /* Buttons */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3990 | #define EC_MKBP_POWER_BUTTON 0 |
| 3991 | #define EC_MKBP_VOL_UP 1 |
| 3992 | #define EC_MKBP_VOL_DOWN 2 |
| 3993 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3994 | |
| 3995 | /* Switches */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 3996 | #define EC_MKBP_LID_OPEN 0 |
| 3997 | #define EC_MKBP_TABLET_MODE 1 |
| 3998 | #define EC_MKBP_BASE_ATTACHED 2 |
| 3999 | #define EC_MKBP_FRONT_PROXIMITY 3 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 4000 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4001 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4002 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4003 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4004 | struct ec_response_keyboard_factory_test { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4005 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4006 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4007 | |
| 4008 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4009 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF) |
| 4010 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4011 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4012 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \ |
| 4013 | (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4014 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 4015 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4016 | #define EC_MKBP_FP_MATCH_IDX(fpe) \ |
| 4017 | (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
| 4018 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 4019 | #define EC_MKBP_FP_MATCH BIT(28) |
| 4020 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 4021 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 4022 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4023 | /* 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] | 4024 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 4025 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 4026 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 4027 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 4028 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4029 | /* 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] | 4030 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4031 | /* 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] | 4032 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 4033 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
| 4034 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
| 4035 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 4036 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 4037 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 4038 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4039 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 4040 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4041 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 4042 | enum ec_mkbp_event_mask_action { |
| 4043 | /* Retrieve the value of a wake mask. */ |
| 4044 | GET_WAKE_MASK = 0, |
| 4045 | |
| 4046 | /* Set the value of a wake mask. */ |
| 4047 | SET_WAKE_MASK, |
| 4048 | }; |
| 4049 | |
| 4050 | enum ec_mkbp_mask_type { |
| 4051 | /* |
| 4052 | * These are host events sent via MKBP. |
| 4053 | * |
| 4054 | * Some examples are: |
| 4055 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 4056 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 4057 | * |
| 4058 | * The only things that should be in this mask are: |
| 4059 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 4060 | */ |
| 4061 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 4062 | |
| 4063 | /* |
| 4064 | * These are MKBP events. Some examples are: |
| 4065 | * |
| 4066 | * EC_MKBP_EVENT_KEY_MATRIX |
| 4067 | * EC_MKBP_EVENT_SWITCH |
| 4068 | * |
| 4069 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 4070 | */ |
| 4071 | EC_MKBP_EVENT_WAKE_MASK, |
| 4072 | }; |
| 4073 | |
| 4074 | struct ec_params_mkbp_event_wake_mask { |
| 4075 | /* One of enum ec_mkbp_event_mask_action */ |
| 4076 | uint8_t action; |
| 4077 | |
| 4078 | /* |
| 4079 | * Which MKBP mask are you interested in acting upon? This is one of |
| 4080 | * ec_mkbp_mask_type. |
| 4081 | */ |
| 4082 | uint8_t mask_type; |
| 4083 | |
| 4084 | /* If setting a new wake mask, this contains the mask to set. */ |
| 4085 | uint32_t new_wake_mask; |
| 4086 | }; |
| 4087 | |
| 4088 | struct ec_response_mkbp_event_wake_mask { |
| 4089 | uint32_t wake_mask; |
| 4090 | }; |
| 4091 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4092 | /*****************************************************************************/ |
| 4093 | /* Temperature sensor commands */ |
| 4094 | |
| 4095 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4096 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4097 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4098 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4099 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4100 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4101 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4102 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4103 | char sensor_name[32]; |
| 4104 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4105 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4106 | |
| 4107 | /*****************************************************************************/ |
| 4108 | |
| 4109 | /* |
| 4110 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 4111 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 4112 | * below. |
| 4113 | */ |
| 4114 | |
| 4115 | /*****************************************************************************/ |
| 4116 | /* Host event commands */ |
| 4117 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4118 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4119 | /* |
| 4120 | * Host event mask params and response structures, shared by all of the host |
| 4121 | * event commands below. |
| 4122 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4123 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4124 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4125 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4126 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4127 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4128 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4129 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4130 | |
| 4131 | /* These all use ec_response_host_event_mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4132 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 4133 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 4134 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4135 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4136 | |
| 4137 | /* These all use ec_params_host_event_mask */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4138 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 4139 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 4140 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4141 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4142 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4143 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4144 | /* |
| 4145 | * Unified host event programming interface - Should be used by newer versions |
| 4146 | * of BIOS/OS to program host events and masks |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 4147 | * |
| 4148 | * EC returns: |
| 4149 | * - EC_RES_INVALID_PARAM: Action or mask type is unknown. |
| 4150 | * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type. |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4151 | */ |
| 4152 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4153 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4154 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 4155 | uint8_t action; |
| 4156 | |
| 4157 | /* |
| 4158 | * Mask type that the host requested the action on - one of |
| 4159 | * enum ec_host_event_mask_type. |
| 4160 | */ |
| 4161 | uint8_t mask_type; |
| 4162 | |
| 4163 | /* Set to 0, ignore on read */ |
| 4164 | uint16_t reserved; |
| 4165 | |
| 4166 | /* Value to be used in case of set operations. */ |
| 4167 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4168 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4169 | |
| 4170 | /* |
| 4171 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 4172 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 4173 | */ |
| 4174 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4175 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4176 | /* Mask value in case of get operation */ |
| 4177 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4178 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4179 | |
| 4180 | enum ec_host_event_action { |
| 4181 | /* |
| 4182 | * params.value is ignored. Value of mask_type populated |
| 4183 | * in response.value |
| 4184 | */ |
| 4185 | EC_HOST_EVENT_GET, |
| 4186 | |
| 4187 | /* Bits in params.value are set */ |
| 4188 | EC_HOST_EVENT_SET, |
| 4189 | |
| 4190 | /* Bits in params.value are cleared */ |
| 4191 | EC_HOST_EVENT_CLEAR, |
| 4192 | }; |
| 4193 | |
| 4194 | enum ec_host_event_mask_type { |
| 4195 | |
| 4196 | /* Main host event copy */ |
| 4197 | EC_HOST_EVENT_MAIN, |
| 4198 | |
| 4199 | /* Copy B of host events */ |
| 4200 | EC_HOST_EVENT_B, |
| 4201 | |
| 4202 | /* SCI Mask */ |
| 4203 | EC_HOST_EVENT_SCI_MASK, |
| 4204 | |
| 4205 | /* SMI Mask */ |
| 4206 | EC_HOST_EVENT_SMI_MASK, |
| 4207 | |
| 4208 | /* Mask of events that should be always reported in hostevents */ |
| 4209 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 4210 | |
| 4211 | /* Active wake mask */ |
| 4212 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 4213 | |
| 4214 | /* Lazy wake mask for S0ix */ |
| 4215 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 4216 | |
| 4217 | /* Lazy wake mask for S3 */ |
| 4218 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 4219 | |
| 4220 | /* Lazy wake mask for S5 */ |
| 4221 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 4222 | }; |
| 4223 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4224 | #define EC_CMD_HOST_EVENT 0x00A4 |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 4225 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4226 | /*****************************************************************************/ |
| 4227 | /* Switch commands */ |
| 4228 | |
| 4229 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4230 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4231 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4232 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4233 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4234 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4235 | |
| 4236 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4237 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4238 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4239 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4240 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4241 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4242 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4243 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4244 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4245 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4246 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4247 | /* Flags to enable now */ |
| 4248 | uint8_t now_flags; |
| 4249 | |
| 4250 | /* Which flags to copy from now_flags */ |
| 4251 | uint8_t now_mask; |
| 4252 | |
| 4253 | /* |
| 4254 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4255 | * transition. (Other flags will be disabled by the S0->S3 |
| 4256 | * transition.) |
| 4257 | */ |
| 4258 | uint8_t suspend_flags; |
| 4259 | |
| 4260 | /* Which flags to copy from suspend_flags */ |
| 4261 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4262 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4263 | |
| 4264 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4265 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4266 | /* Flags to enable now */ |
| 4267 | uint8_t now_flags; |
| 4268 | |
| 4269 | /* Flags to leave enabled in S3 */ |
| 4270 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4271 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4272 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4273 | /*****************************************************************************/ |
| 4274 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4275 | |
| 4276 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4277 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4278 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4279 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4280 | char name[32]; |
| 4281 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4282 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4283 | |
| 4284 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4285 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4286 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4287 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4288 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4289 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4290 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4291 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4292 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4293 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4294 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4295 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4296 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4297 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4298 | uint8_t subcmd; |
| 4299 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4300 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4301 | char name[32]; |
| 4302 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4303 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4304 | uint8_t index; |
| 4305 | } get_info; |
| 4306 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4307 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4308 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4309 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4310 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4311 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4312 | uint8_t val; |
| 4313 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4314 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4315 | uint8_t val; |
| 4316 | char name[32]; |
| 4317 | uint32_t flags; |
| 4318 | } get_info; |
| 4319 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4320 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4321 | |
| 4322 | enum gpio_get_subcmd { |
| 4323 | EC_GPIO_GET_BY_NAME = 0, |
| 4324 | EC_GPIO_GET_COUNT = 1, |
| 4325 | EC_GPIO_GET_INFO = 2, |
| 4326 | }; |
| 4327 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4328 | /*****************************************************************************/ |
| 4329 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4330 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4331 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4332 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4333 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4334 | * |
| 4335 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4336 | */ |
| 4337 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4338 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4339 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4340 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4341 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4342 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4343 | uint8_t read_size; /* Either 8 or 16. */ |
| 4344 | uint8_t port; |
| 4345 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4346 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4347 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4348 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4349 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4350 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4351 | |
| 4352 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4353 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4354 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4355 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4356 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4357 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4358 | uint8_t write_size; /* Either 8 or 16. */ |
| 4359 | uint8_t port; |
| 4360 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4361 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4362 | |
| 4363 | /*****************************************************************************/ |
| 4364 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4365 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4366 | /* Force charge state machine to stop charging the battery or force it to |
| 4367 | * discharge the battery. |
| 4368 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4369 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4370 | #define EC_VER_CHARGE_CONTROL 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4371 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4372 | enum ec_charge_control_mode { |
| 4373 | CHARGE_CONTROL_NORMAL = 0, |
| 4374 | CHARGE_CONTROL_IDLE, |
| 4375 | CHARGE_CONTROL_DISCHARGE, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4376 | /* Add no more entry below. */ |
| 4377 | CHARGE_CONTROL_COUNT, |
| 4378 | }; |
| 4379 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4380 | #define EC_CHARGE_MODE_TEXT \ |
| 4381 | { \ |
| 4382 | [CHARGE_CONTROL_NORMAL] = "NORMAL", \ |
| 4383 | [CHARGE_CONTROL_IDLE] = "IDLE", \ |
| 4384 | [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4385 | } |
| 4386 | |
| 4387 | enum ec_charge_control_cmd { |
| 4388 | EC_CHARGE_CONTROL_CMD_SET = 0, |
| 4389 | EC_CHARGE_CONTROL_CMD_GET, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4390 | }; |
| 4391 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4392 | struct ec_params_charge_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4393 | uint32_t mode; /* enum charge_control_mode */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4394 | |
| 4395 | /* Below are the fields added in V2. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4396 | uint8_t cmd; /* enum ec_charge_control_cmd. */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4397 | uint8_t reserved; |
| 4398 | /* |
| 4399 | * Lower and upper thresholds for battery sustainer. This struct isn't |
| 4400 | * named to avoid tainting foreign projects' name spaces. |
| 4401 | * |
| 4402 | * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer |
| 4403 | * will be disabled. To disable battery sustainer, set mode=NORMAL, |
| 4404 | * lower=-1, upper=-1. |
| 4405 | */ |
| 4406 | struct { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4407 | int8_t lower; /* Display SoC in percentage. */ |
| 4408 | int8_t upper; /* Display SoC in percentage. */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4409 | } sustain_soc; |
| 4410 | } __ec_align4; |
| 4411 | |
| 4412 | /* Added in v2 */ |
| 4413 | struct ec_response_charge_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4414 | uint32_t mode; /* enum charge_control_mode */ |
| 4415 | struct { /* Battery sustainer thresholds */ |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 4416 | int8_t lower; |
| 4417 | int8_t upper; |
| 4418 | } sustain_soc; |
| 4419 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4420 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4421 | |
| 4422 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4423 | |
| 4424 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4425 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4426 | |
| 4427 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4428 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4429 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4430 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4431 | * end of the previous snapshot. |
| 4432 | * |
| 4433 | * The params are only looked at in version >= 1 of this command. Prior |
| 4434 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4435 | * |
| 4436 | * Response is null-terminated string. Empty string, if there is no more |
| 4437 | * remaining output. |
| 4438 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4439 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4440 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 4441 | enum ec_console_read_subcmd { |
| 4442 | CONSOLE_READ_NEXT = 0, |
| 4443 | CONSOLE_READ_RECENT, |
| 4444 | }; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4445 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4446 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4447 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4448 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4449 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4450 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4451 | |
| 4452 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4453 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4454 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4455 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4456 | * EC_RES_SUCCESS if the command was successful. |
| 4457 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4458 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4459 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4460 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4461 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4462 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4463 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4464 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4465 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4466 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4467 | /*****************************************************************************/ |
| 4468 | /* USB port mux control. */ |
| 4469 | |
| 4470 | /* |
| 4471 | * Switch USB mux or return to automatic switching. |
| 4472 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4473 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4474 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4475 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4476 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4477 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4478 | |
| 4479 | /*****************************************************************************/ |
| 4480 | /* LDOs / FETs control. */ |
| 4481 | |
| 4482 | enum ec_ldo_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4483 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4484 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4485 | }; |
| 4486 | |
| 4487 | /* |
| 4488 | * Switch on/off a LDO. |
| 4489 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4490 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4491 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4492 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4493 | uint8_t index; |
| 4494 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4495 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4496 | |
| 4497 | /* |
| 4498 | * Get LDO state. |
| 4499 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4500 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4501 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4502 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4503 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4504 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4505 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4506 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4507 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4508 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4509 | |
| 4510 | /*****************************************************************************/ |
| 4511 | /* Power info. */ |
| 4512 | |
| 4513 | /* |
| 4514 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4515 | * |
| 4516 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4517 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4518 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4519 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4520 | /* |
| 4521 | * v1 of EC_CMD_POWER_INFO |
| 4522 | */ |
| 4523 | enum system_power_source { |
| 4524 | /* |
| 4525 | * Haven't established which power source is used yet, |
| 4526 | * or no presence signals are available |
| 4527 | */ |
| 4528 | POWER_SOURCE_UNKNOWN = 0, |
| 4529 | /* System is running on battery alone */ |
| 4530 | POWER_SOURCE_BATTERY = 1, |
| 4531 | /* System is running on A/C alone */ |
| 4532 | POWER_SOURCE_AC = 2, |
| 4533 | /* System is running on A/C and battery */ |
| 4534 | POWER_SOURCE_AC_BATTERY = 3, |
| 4535 | }; |
| 4536 | |
| 4537 | struct ec_response_power_info_v1 { |
| 4538 | /* enum system_power_source */ |
| 4539 | uint8_t system_power_source; |
| 4540 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4541 | uint8_t battery_soc; |
| 4542 | /* AC Adapter 100% rating, Watts */ |
| 4543 | uint8_t ac_adapter_100pct; |
| 4544 | /* AC Adapter 10ms rating, Watts */ |
| 4545 | uint8_t ac_adapter_10ms; |
| 4546 | /* Battery 1C rating, derated */ |
| 4547 | uint8_t battery_1cd; |
| 4548 | /* Rest of Platform average, Watts */ |
| 4549 | uint8_t rop_avg; |
| 4550 | /* Rest of Platform peak, Watts */ |
| 4551 | uint8_t rop_peak; |
| 4552 | /* Nominal charger efficiency, % */ |
| 4553 | uint8_t nominal_charger_eff; |
| 4554 | /* Rest of Platform VR Average Efficiency, % */ |
| 4555 | uint8_t rop_avg_eff; |
| 4556 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4557 | uint8_t rop_peak_eff; |
| 4558 | /* SoC VR Efficiency at Average level, % */ |
| 4559 | uint8_t soc_avg_eff; |
| 4560 | /* SoC VR Efficiency at Peak level, % */ |
| 4561 | uint8_t soc_peak_eff; |
| 4562 | /* Intel-specific items */ |
| 4563 | struct { |
| 4564 | /* Battery's level of DBPT support: 0, 2 */ |
| 4565 | uint8_t batt_dbpt_support_level; |
| 4566 | /* |
| 4567 | * Maximum peak power from battery (10ms), Watts |
| 4568 | * If DBPT is not supported, this is 0 |
| 4569 | */ |
| 4570 | uint8_t batt_dbpt_max_peak_power; |
| 4571 | /* |
| 4572 | * Sustained peak power from battery, Watts |
| 4573 | * If DBPT is not supported, this is 0 |
| 4574 | */ |
| 4575 | uint8_t batt_dbpt_sus_peak_power; |
| 4576 | } intel; |
| 4577 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4578 | |
| 4579 | /*****************************************************************************/ |
| 4580 | /* I2C passthru command */ |
| 4581 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4582 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4583 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4584 | /* Read data; if not present, message is a write */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4585 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4586 | |
| 4587 | /* Mask for address */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4588 | #define EC_I2C_ADDR_MASK 0x3ff |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4589 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4590 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4591 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4592 | |
| 4593 | /* Any error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4594 | #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] | 4595 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4596 | struct ec_params_i2c_passthru_msg { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4597 | uint16_t addr_flags; /* I2C peripheral address and flags */ |
| 4598 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4599 | } __ec_align2; |
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_params_i2c_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4602 | uint8_t port; /* I2C port number */ |
| 4603 | uint8_t num_msgs; /* Number of messages */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4604 | struct ec_params_i2c_passthru_msg msg[]; |
| 4605 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4606 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4607 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4608 | struct ec_response_i2c_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4609 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4610 | uint8_t num_msgs; /* Number of messages processed */ |
| 4611 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4612 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4613 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4614 | /*****************************************************************************/ |
| 4615 | /* Power button hang detect */ |
| 4616 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4617 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4618 | |
| 4619 | /* Reasons to start hang detection timer */ |
| 4620 | /* Power button pressed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4621 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4622 | |
| 4623 | /* Lid closed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4624 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4625 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4626 | /* Lid opened */ |
| 4627 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4628 | |
| 4629 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4630 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4631 | |
| 4632 | /* Reasons to cancel hang detection */ |
| 4633 | |
| 4634 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4635 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4636 | |
| 4637 | /* Any host command from AP received */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4638 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4639 | |
| 4640 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4641 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4642 | |
| 4643 | /* |
| 4644 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4645 | * timer is started. This provides the AP a way to start the hang timer |
| 4646 | * without reconfiguring any of the other hang detect settings. Note that |
| 4647 | * you must previously have configured the timeouts. |
| 4648 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4649 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4650 | |
| 4651 | /* |
| 4652 | * If this flag is set, all the other fields are ignored (including |
| 4653 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4654 | * without reconfiguring any of the other hang detect settings. |
| 4655 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4656 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4657 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4658 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4659 | /* Flags; see EC_HANG_* */ |
| 4660 | uint32_t flags; |
| 4661 | |
| 4662 | /* Timeout in msec before generating host event, if enabled */ |
| 4663 | uint16_t host_event_timeout_msec; |
| 4664 | |
| 4665 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4666 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4667 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4668 | |
| 4669 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4670 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4671 | |
| 4672 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4673 | * This is the single catch-all host command to exchange data regarding the |
| 4674 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4675 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4676 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4677 | |
| 4678 | /* Subcommands for this host command */ |
| 4679 | enum charge_state_command { |
| 4680 | CHARGE_STATE_CMD_GET_STATE, |
| 4681 | CHARGE_STATE_CMD_GET_PARAM, |
| 4682 | CHARGE_STATE_CMD_SET_PARAM, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 4683 | CHARGE_STATE_NUM_CMDS, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4684 | }; |
| 4685 | |
| 4686 | /* |
| 4687 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4688 | * params, which are handled by the particular implementations. |
| 4689 | */ |
| 4690 | enum charge_state_params { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 4691 | /* charger voltage limit */ |
| 4692 | CS_PARAM_CHG_VOLTAGE, |
| 4693 | |
| 4694 | /* charger current limit */ |
| 4695 | CS_PARAM_CHG_CURRENT, |
| 4696 | |
| 4697 | /* charger input current limit */ |
| 4698 | CS_PARAM_CHG_INPUT_CURRENT, |
| 4699 | |
| 4700 | /* charger-specific status */ |
| 4701 | CS_PARAM_CHG_STATUS, |
| 4702 | |
| 4703 | /* charger-specific options */ |
| 4704 | CS_PARAM_CHG_OPTION, |
| 4705 | |
| 4706 | /* |
| 4707 | * Check if power is limited due to low battery and / or a |
| 4708 | * weak external charger. READ ONLY. |
| 4709 | */ |
| 4710 | CS_PARAM_LIMIT_POWER, |
| 4711 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4712 | /* How many so far? */ |
| 4713 | CS_NUM_BASE_PARAMS, |
| 4714 | |
| 4715 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4716 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4717 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4718 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4719 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4720 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4721 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4722 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4723 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4724 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4725 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4726 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4727 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4728 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4729 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4730 | /* Other custom param ranges go here... */ |
| 4731 | }; |
| 4732 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4733 | struct ec_params_charge_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4734 | uint8_t cmd; /* enum charge_state_command */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4735 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4736 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4737 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4738 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4739 | uint32_t param; /* enum charge_state_param */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 4740 | } get_param; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4741 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4742 | struct __ec_todo_unpacked { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4743 | uint32_t param; /* param to set */ |
| 4744 | uint32_t value; /* value to set */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 4745 | } set_param; |
| 4746 | } __ec_todo_packed; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4747 | uint8_t chgnum; /* Version 1 supports chgnum */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4748 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4749 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4750 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4751 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4752 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4753 | int ac; |
| 4754 | int chg_voltage; |
| 4755 | int chg_current; |
| 4756 | int chg_input_current; |
| 4757 | int batt_state_of_charge; |
| 4758 | } get_state; |
| 4759 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4760 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4761 | uint32_t value; |
| 4762 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4763 | |
| 4764 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4765 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4766 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4767 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4768 | /* |
| 4769 | * Set maximum battery charging current. |
| 4770 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4771 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4772 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4773 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4774 | uint32_t limit; /* in mA */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4775 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4776 | |
| 4777 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4778 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4779 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4780 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4781 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4782 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4783 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4784 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4785 | 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] | 4786 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4787 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4788 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4789 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4790 | /* |
| 4791 | * Set maximum voltage & current of a dedicated charge port |
| 4792 | */ |
| 4793 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4794 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4795 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4796 | uint16_t current_lim; /* in mA */ |
| 4797 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4798 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4799 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 4800 | /* |
| 4801 | * Get and set charging splashscreen variables |
| 4802 | */ |
| 4803 | #define EC_CMD_CHARGESPLASH 0x00A5 |
| 4804 | |
| 4805 | enum ec_chargesplash_cmd { |
| 4806 | /* Get the current state variables */ |
| 4807 | EC_CHARGESPLASH_GET_STATE = 0, |
| 4808 | |
| 4809 | /* Indicate initialization of the display loop */ |
| 4810 | EC_CHARGESPLASH_DISPLAY_READY, |
| 4811 | |
| 4812 | /* Manually put the EC into the requested state */ |
| 4813 | EC_CHARGESPLASH_REQUEST, |
| 4814 | |
| 4815 | /* Reset all state variables */ |
| 4816 | EC_CHARGESPLASH_RESET, |
| 4817 | |
| 4818 | /* Manually trigger a lockout */ |
| 4819 | EC_CHARGESPLASH_LOCKOUT, |
| 4820 | }; |
| 4821 | |
| 4822 | struct __ec_align1 ec_params_chargesplash { |
| 4823 | /* enum ec_chargesplash_cmd */ |
| 4824 | uint8_t cmd; |
| 4825 | }; |
| 4826 | |
| 4827 | struct __ec_align1 ec_response_chargesplash { |
| 4828 | uint8_t requested; |
| 4829 | uint8_t display_initialized; |
| 4830 | uint8_t locked_out; |
| 4831 | }; |
| 4832 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4833 | /*****************************************************************************/ |
| 4834 | /* Hibernate/Deep Sleep Commands */ |
| 4835 | |
| 4836 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4837 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4838 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4839 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4840 | /* |
| 4841 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4842 | * current settings without changing them. |
| 4843 | */ |
| 4844 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4845 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4846 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4847 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4848 | /* |
| 4849 | * The current time in seconds in which the system has been in the G3 |
| 4850 | * state. This value is reset if the EC transitions out of G3. |
| 4851 | */ |
| 4852 | uint32_t time_g3; |
| 4853 | |
| 4854 | /* |
| 4855 | * The current time remaining in seconds until the EC should hibernate. |
| 4856 | * This value is also reset if the EC transitions out of G3. |
| 4857 | */ |
| 4858 | uint32_t time_remaining; |
| 4859 | |
| 4860 | /* |
| 4861 | * The current time in seconds that the EC should wait in G3 before |
| 4862 | * hibernating. |
| 4863 | */ |
| 4864 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4865 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4866 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4867 | /* Inform the EC when entering a sleep state */ |
| 4868 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4869 | |
| 4870 | enum host_sleep_event { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4871 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4872 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4873 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4874 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4875 | /* S3 suspend with additional enabled wake sources */ |
| 4876 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4877 | }; |
| 4878 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4879 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4880 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4881 | } __ec_align1; |
| 4882 | |
| 4883 | /* |
| 4884 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4885 | * transition failures |
| 4886 | */ |
| 4887 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4888 | |
| 4889 | /* Disable timeout detection for this sleep transition */ |
| 4890 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4891 | |
| 4892 | struct ec_params_host_sleep_event_v1 { |
| 4893 | /* The type of sleep being entered or exited. */ |
| 4894 | uint8_t sleep_event; |
| 4895 | |
| 4896 | /* Padding */ |
| 4897 | uint8_t reserved; |
| 4898 | union { |
| 4899 | /* Parameters that apply for suspend messages. */ |
| 4900 | struct { |
| 4901 | /* |
| 4902 | * The timeout in milliseconds between when this message |
| 4903 | * is received and when the EC will declare sleep |
| 4904 | * transition failure if the sleep signal is not |
| 4905 | * asserted. |
| 4906 | */ |
| 4907 | uint16_t sleep_timeout_ms; |
| 4908 | } suspend_params; |
| 4909 | |
| 4910 | /* No parameters for non-suspend messages. */ |
| 4911 | }; |
| 4912 | } __ec_align2; |
| 4913 | |
| 4914 | /* A timeout occurred when this bit is set */ |
| 4915 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4916 | |
| 4917 | /* |
| 4918 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4919 | * as well as the maximum number of suspend line transitions that will be |
| 4920 | * reported back to the host. |
| 4921 | */ |
| 4922 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4923 | |
| 4924 | struct ec_response_host_sleep_event_v1 { |
| 4925 | union { |
| 4926 | /* Response fields that apply for resume messages. */ |
| 4927 | struct { |
| 4928 | /* |
| 4929 | * The number of sleep power signal transitions that |
| 4930 | * occurred since the suspend message. The high bit |
| 4931 | * indicates a timeout occurred. |
| 4932 | */ |
| 4933 | uint32_t sleep_transitions; |
| 4934 | } resume_response; |
| 4935 | |
| 4936 | /* No response fields for non-resume messages. */ |
| 4937 | }; |
| 4938 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4939 | |
| 4940 | /*****************************************************************************/ |
| 4941 | /* Device events */ |
| 4942 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4943 | |
| 4944 | enum ec_device_event { |
| 4945 | EC_DEVICE_EVENT_TRACKPAD, |
| 4946 | EC_DEVICE_EVENT_DSP, |
| 4947 | EC_DEVICE_EVENT_WIFI, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 4948 | EC_DEVICE_EVENT_WLC, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4949 | }; |
| 4950 | |
| 4951 | enum ec_device_event_param { |
| 4952 | /* Get and clear pending device events */ |
| 4953 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4954 | /* Get device event mask */ |
| 4955 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4956 | /* Set device event mask */ |
| 4957 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4958 | }; |
| 4959 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4960 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4961 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4962 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4963 | uint32_t event_mask; |
| 4964 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4965 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4966 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4967 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4968 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4969 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4970 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4971 | /*****************************************************************************/ |
| 4972 | /* Smart battery pass-through */ |
| 4973 | |
| 4974 | /* Get / Set 16-bit smart battery registers */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4975 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 4976 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4977 | |
| 4978 | /* Get / Set string smart battery parameters |
| 4979 | * formatted as SMBUS "block". |
| 4980 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 4981 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4982 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4983 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4984 | struct ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4985 | uint8_t reg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4986 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4987 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4988 | struct ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4989 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4990 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4991 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4992 | struct ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4993 | uint8_t reg; |
| 4994 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4995 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4996 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4997 | struct ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4998 | uint8_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4999 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5000 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5001 | struct ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5002 | uint8_t reg; |
| 5003 | uint16_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5004 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5005 | |
| 5006 | /*****************************************************************************/ |
| 5007 | /* Battery vendor parameters |
| 5008 | * |
| 5009 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 5010 | * differ between boards or batteries. On a set operation, the response |
| 5011 | * contains the actual value set, which may be rounded or clipped from the |
| 5012 | * requested value. |
| 5013 | */ |
| 5014 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5015 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5016 | |
| 5017 | enum ec_battery_vendor_param_mode { |
| 5018 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 5019 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 5020 | }; |
| 5021 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5022 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5023 | uint32_t param; |
| 5024 | uint32_t value; |
| 5025 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5026 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5027 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5028 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5029 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5030 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5031 | |
| 5032 | /*****************************************************************************/ |
| 5033 | /* |
| 5034 | * Smart Battery Firmware Update Commands |
| 5035 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5036 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5037 | |
| 5038 | enum ec_sb_fw_update_subcmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5039 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 5040 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 5041 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 5042 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 5043 | EC_SB_FW_UPDATE_END = 0x4, |
| 5044 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 5045 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 5046 | EC_SB_FW_UPDATE_MAX = 0x7, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5047 | }; |
| 5048 | |
| 5049 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 5050 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 5051 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 5052 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5053 | struct ec_sb_fw_update_header { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5054 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 5055 | uint16_t fw_id; /* firmware id */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5056 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5057 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5058 | struct ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5059 | struct ec_sb_fw_update_header hdr; |
| 5060 | union { |
| 5061 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 5062 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 5063 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 5064 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 5065 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 5066 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5067 | /* Those have no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5068 | |
| 5069 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5070 | struct __ec_align4 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5071 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5072 | } write; |
| 5073 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5074 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5075 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5076 | struct ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5077 | union { |
| 5078 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5079 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5080 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 5081 | } info; |
| 5082 | |
| 5083 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5084 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5085 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 5086 | } status; |
| 5087 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5088 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5089 | |
| 5090 | /* |
| 5091 | * Entering Verified Boot Mode Command |
| 5092 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 5093 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5094 | * |
| 5095 | * EC no longer needs to know what mode vboot has entered, |
| 5096 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5097 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5098 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5099 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5100 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5101 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5102 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5103 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5104 | #define VBOOT_MODE_NORMAL 0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5105 | #define VBOOT_MODE_DEVELOPER 1 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5106 | #define VBOOT_MODE_RECOVERY 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5107 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5108 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5109 | /* |
| 5110 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 5111 | * certain addresses (board-specific). |
| 5112 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5113 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5114 | |
| 5115 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5116 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 5117 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 5118 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5119 | }; |
| 5120 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5121 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5122 | uint8_t subcmd; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5123 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5124 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5125 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5126 | struct ec_response_i2c_passthru_protect { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5127 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5128 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5129 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5130 | /*****************************************************************************/ |
| 5131 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5132 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5133 | * |
| 5134 | * These commands are for sending and receiving message via HDMI CEC |
| 5135 | */ |
| 5136 | |
| 5137 | #define MAX_CEC_MSG_LEN 16 |
| 5138 | |
| 5139 | /* CEC message from the AP to be written on the CEC bus */ |
| 5140 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 5141 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5142 | /** |
| 5143 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 5144 | * @msg: message content to write to the CEC bus |
| 5145 | */ |
| 5146 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5147 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5148 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5149 | |
| 5150 | /* Set various CEC parameters */ |
| 5151 | #define EC_CMD_CEC_SET 0x00BA |
| 5152 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5153 | /** |
| 5154 | * struct ec_params_cec_set - CEC parameters set |
| 5155 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 5156 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 5157 | * or 1 to enable CEC functionality, in case cmd is |
| 5158 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 5159 | * address between 0 and 15 or 0xff to unregister |
| 5160 | */ |
| 5161 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5162 | uint8_t cmd; /* enum cec_command */ |
| 5163 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5164 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5165 | |
| 5166 | /* Read various CEC parameters */ |
| 5167 | #define EC_CMD_CEC_GET 0x00BB |
| 5168 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5169 | /** |
| 5170 | * struct ec_params_cec_get - CEC parameters get |
| 5171 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 5172 | */ |
| 5173 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5174 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5175 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5176 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5177 | /** |
| 5178 | * struct ec_response_cec_get - CEC parameters get response |
| 5179 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 5180 | * disabled or 1 if CEC functionality is enabled, |
| 5181 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 5182 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 5183 | */ |
| 5184 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5185 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5186 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5187 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5188 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5189 | enum cec_command { |
| 5190 | /* CEC reading, writing and events enable */ |
| 5191 | CEC_CMD_ENABLE, |
| 5192 | /* CEC logical address */ |
| 5193 | CEC_CMD_LOGICAL_ADDRESS, |
| 5194 | }; |
| 5195 | |
| 5196 | /* Events from CEC to AP */ |
| 5197 | enum mkbp_cec_event { |
| 5198 | /* Outgoing message was acknowledged by a follower */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5199 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5200 | /* Outgoing message was not acknowledged */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5201 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5202 | }; |
| 5203 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5204 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5205 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5206 | /* Commands for audio codec. */ |
| 5207 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5208 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5209 | enum ec_codec_subcmd { |
| 5210 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 5211 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 5212 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 5213 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5214 | }; |
| 5215 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5216 | enum ec_codec_cap { |
| 5217 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 5218 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 5219 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5220 | }; |
| 5221 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5222 | enum ec_codec_shm_id { |
| 5223 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 5224 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 5225 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5226 | }; |
| 5227 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5228 | enum ec_codec_shm_type { |
| 5229 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 5230 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5231 | }; |
| 5232 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5233 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 5234 | uint8_t shm_id; |
| 5235 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5236 | }; |
| 5237 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5238 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 5239 | uint64_t phys_addr; |
| 5240 | uint32_t len; |
| 5241 | uint8_t shm_id; |
| 5242 | uint8_t reserved[3]; |
| 5243 | }; |
| 5244 | |
| 5245 | struct __ec_align4 ec_param_ec_codec { |
| 5246 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 5247 | uint8_t reserved[3]; |
| 5248 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5249 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5250 | struct ec_param_ec_codec_get_shm_addr get_shm_addr_param; |
| 5251 | 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] | 5252 | }; |
| 5253 | }; |
| 5254 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5255 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 5256 | uint32_t capabilities; |
| 5257 | }; |
| 5258 | |
| 5259 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 5260 | uint64_t phys_addr; |
| 5261 | uint32_t len; |
| 5262 | uint8_t type; |
| 5263 | uint8_t reserved[3]; |
| 5264 | }; |
| 5265 | |
| 5266 | /*****************************************************************************/ |
| 5267 | |
| 5268 | /* Commands for DMIC on audio codec. */ |
| 5269 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 5270 | |
| 5271 | enum ec_codec_dmic_subcmd { |
| 5272 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 5273 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 5274 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 5275 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 5276 | }; |
| 5277 | |
| 5278 | enum ec_codec_dmic_channel { |
| 5279 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 5280 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 5281 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 5282 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 5283 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 5284 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 5285 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 5286 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 5287 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 5288 | }; |
| 5289 | |
| 5290 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 5291 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5292 | uint8_t gain; |
| 5293 | uint8_t reserved[2]; |
| 5294 | }; |
| 5295 | |
| 5296 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 5297 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 5298 | uint8_t reserved[3]; |
| 5299 | }; |
| 5300 | |
| 5301 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 5302 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 5303 | uint8_t reserved[3]; |
| 5304 | |
| 5305 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5306 | struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param; |
| 5307 | 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] | 5308 | }; |
| 5309 | }; |
| 5310 | |
| 5311 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 5312 | uint8_t max_gain; |
| 5313 | }; |
| 5314 | |
| 5315 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 5316 | uint8_t gain; |
| 5317 | }; |
| 5318 | |
| 5319 | /*****************************************************************************/ |
| 5320 | |
| 5321 | /* Commands for I2S RX on audio codec. */ |
| 5322 | |
| 5323 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 5324 | |
| 5325 | enum ec_codec_i2s_rx_subcmd { |
| 5326 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 5327 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 5328 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 5329 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 5330 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5331 | EC_CODEC_I2S_RX_RESET = 0x5, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5332 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5333 | }; |
| 5334 | |
| 5335 | enum ec_codec_i2s_rx_sample_depth { |
| 5336 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5337 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5338 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5339 | }; |
| 5340 | |
| 5341 | enum ec_codec_i2s_rx_daifmt { |
| 5342 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5343 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5344 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5345 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5346 | }; |
| 5347 | |
| 5348 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5349 | uint8_t depth; |
| 5350 | uint8_t reserved[3]; |
| 5351 | }; |
| 5352 | |
| 5353 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5354 | uint8_t left; |
| 5355 | uint8_t right; |
| 5356 | uint8_t reserved[2]; |
| 5357 | }; |
| 5358 | |
| 5359 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5360 | uint8_t daifmt; |
| 5361 | uint8_t reserved[3]; |
| 5362 | }; |
| 5363 | |
| 5364 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5365 | uint32_t bclk; |
| 5366 | }; |
| 5367 | |
| 5368 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5369 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5370 | uint8_t reserved[3]; |
| 5371 | |
| 5372 | union { |
| 5373 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5374 | set_sample_depth_param; |
| 5375 | struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param; |
| 5376 | struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5377 | }; |
| 5378 | }; |
| 5379 | |
| 5380 | /*****************************************************************************/ |
| 5381 | /* Commands for WoV on audio codec. */ |
| 5382 | |
| 5383 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5384 | |
| 5385 | enum ec_codec_wov_subcmd { |
| 5386 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5387 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5388 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5389 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5390 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5391 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5392 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5393 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5394 | }; |
| 5395 | |
| 5396 | /* |
| 5397 | * @hash is SHA256 of the whole language model. |
| 5398 | * @total_len indicates the length of whole language model. |
| 5399 | * @offset is the cursor from the beginning of the model. |
| 5400 | * @buf is the packet buffer. |
| 5401 | * @len denotes how many bytes in the buf. |
| 5402 | */ |
| 5403 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5404 | uint8_t hash[32]; |
| 5405 | uint32_t total_len; |
| 5406 | uint32_t offset; |
| 5407 | uint8_t buf[128]; |
| 5408 | uint32_t len; |
| 5409 | }; |
| 5410 | |
| 5411 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5412 | uint8_t hash[32]; |
| 5413 | uint32_t total_len; |
| 5414 | }; |
| 5415 | |
| 5416 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5417 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5418 | uint8_t reserved[3]; |
| 5419 | |
| 5420 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5421 | struct ec_param_ec_codec_wov_set_lang set_lang_param; |
| 5422 | 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] | 5423 | }; |
| 5424 | }; |
| 5425 | |
| 5426 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5427 | uint8_t hash[32]; |
| 5428 | }; |
| 5429 | |
| 5430 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5431 | uint8_t buf[128]; |
| 5432 | uint32_t len; |
| 5433 | }; |
| 5434 | |
| 5435 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5436 | uint32_t offset; |
| 5437 | uint32_t len; |
| 5438 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5439 | |
| 5440 | /*****************************************************************************/ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5441 | /* Commands for PoE PSE controller */ |
| 5442 | |
| 5443 | #define EC_CMD_PSE 0x00C0 |
| 5444 | |
| 5445 | enum ec_pse_subcmd { |
| 5446 | EC_PSE_STATUS = 0x0, |
| 5447 | EC_PSE_ENABLE = 0x1, |
| 5448 | EC_PSE_DISABLE = 0x2, |
| 5449 | EC_PSE_SUBCMD_COUNT, |
| 5450 | }; |
| 5451 | |
| 5452 | struct __ec_align1 ec_params_pse { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5453 | uint8_t cmd; /* enum ec_pse_subcmd */ |
| 5454 | uint8_t port; /* PSE port */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5455 | }; |
| 5456 | |
| 5457 | enum ec_pse_status { |
| 5458 | EC_PSE_STATUS_DISABLED = 0x0, |
| 5459 | EC_PSE_STATUS_ENABLED = 0x1, |
| 5460 | EC_PSE_STATUS_POWERED = 0x2, |
| 5461 | }; |
| 5462 | |
| 5463 | struct __ec_align1 ec_response_pse_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5464 | uint8_t status; /* enum ec_pse_status */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 5465 | }; |
| 5466 | |
| 5467 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5468 | /* System commands */ |
| 5469 | |
| 5470 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5471 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5472 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5473 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5474 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5475 | |
| 5476 | /* Command */ |
| 5477 | enum ec_reboot_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5478 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
| 5479 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
| 5480 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5481 | /* (command 3 was jump to RW-B) */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5482 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
| 5483 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
| 5484 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5485 | /* |
| 5486 | * DEPRECATED: Hibernate EC and clears AP_IDLE flag. |
| 5487 | * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead. |
| 5488 | */ |
| 5489 | EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5490 | EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */ |
| 5491 | EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5492 | }; |
| 5493 | |
| 5494 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5495 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5496 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5497 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
| 5498 | #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] | 5499 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5500 | struct ec_params_reboot_ec { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5501 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5502 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5503 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5504 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5505 | /* |
| 5506 | * Get information on last EC panic. |
| 5507 | * |
| 5508 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5509 | * for details. |
| 5510 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5511 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5512 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5513 | /*****************************************************************************/ |
| 5514 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5515 | * Special commands |
| 5516 | * |
| 5517 | * These do not follow the normal rules for commands. See each command for |
| 5518 | * details. |
| 5519 | */ |
| 5520 | |
| 5521 | /* |
| 5522 | * Reboot NOW |
| 5523 | * |
| 5524 | * This command will work even when the EC LPC interface is busy, because the |
| 5525 | * reboot command is processed at interrupt level. Note that when the EC |
| 5526 | * reboots, the host will reboot too, so there is no response to this command. |
| 5527 | * |
| 5528 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5529 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5530 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5531 | |
| 5532 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5533 | * Resend last response (not supported on LPC). |
| 5534 | * |
| 5535 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5536 | * there was no previous command, or the previous command's response was too |
| 5537 | * big to save. |
| 5538 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5539 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5540 | |
| 5541 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5542 | * This header byte on a command indicate version 0. Any header byte less |
| 5543 | * than this means that we are talking to an old EC which doesn't support |
| 5544 | * versioning. In that case, we assume version 0. |
| 5545 | * |
| 5546 | * Header bytes greater than this indicate a later version. For example, |
| 5547 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5548 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5549 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5550 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5551 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5552 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5553 | /*****************************************************************************/ |
| 5554 | /* |
| 5555 | * PD commands |
| 5556 | * |
| 5557 | * These commands are for PD MCU communication. |
| 5558 | */ |
| 5559 | |
| 5560 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5561 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5562 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5563 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5564 | enum pd_charge_state { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5565 | /* Don't change charge state */ |
| 5566 | PD_CHARGE_NO_CHANGE = 0, |
| 5567 | |
| 5568 | /* No charging allowed */ |
| 5569 | PD_CHARGE_NONE, |
| 5570 | |
| 5571 | /* 5V charging only */ |
| 5572 | PD_CHARGE_5V, |
| 5573 | |
| 5574 | /* Charge at max voltage */ |
| 5575 | PD_CHARGE_MAX, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5576 | }; |
| 5577 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5578 | /* Status of EC being sent to PD */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5579 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5580 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5581 | struct ec_params_pd_status { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5582 | /* EC status */ |
| 5583 | uint8_t status; |
| 5584 | |
| 5585 | /* battery state of charge */ |
| 5586 | int8_t batt_soc; |
| 5587 | |
| 5588 | /* charging state (from enum pd_charge_state) */ |
| 5589 | uint8_t charge_state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5590 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5591 | |
| 5592 | /* Status of PD being sent back to EC */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5593 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5594 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5595 | #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] | 5596 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5597 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5598 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5599 | #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */ |
| 5600 | #define PD_STATUS_EC_INT_ACTIVE \ |
| 5601 | (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] | 5602 | struct ec_response_pd_status { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5603 | /* input current limit */ |
| 5604 | uint32_t curr_lim_ma; |
| 5605 | |
| 5606 | /* PD MCU status */ |
| 5607 | uint16_t status; |
| 5608 | |
| 5609 | /* active charging port */ |
| 5610 | int8_t active_charge_port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5611 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5612 | |
| 5613 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5614 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5615 | |
| 5616 | /* PD MCU host event status bits */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5617 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5618 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5619 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5620 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5621 | #define PD_EVENT_TYPEC BIT(4) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5622 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5623 | struct ec_response_host_event_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5624 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5625 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5626 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 5627 | /* |
| 5628 | * Set USB type-C port role and muxes |
| 5629 | * |
| 5630 | * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands. |
| 5631 | * |
| 5632 | * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL |
| 5633 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5634 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5635 | |
| 5636 | enum usb_pd_control_role { |
| 5637 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5638 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5639 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5640 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5641 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5642 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5643 | USB_PD_CTRL_ROLE_COUNT, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5644 | }; |
| 5645 | |
| 5646 | enum usb_pd_control_mux { |
| 5647 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5648 | USB_PD_CTRL_MUX_NONE = 1, |
| 5649 | USB_PD_CTRL_MUX_USB = 2, |
| 5650 | USB_PD_CTRL_MUX_DP = 3, |
| 5651 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5652 | USB_PD_CTRL_MUX_AUTO = 5, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5653 | USB_PD_CTRL_MUX_COUNT, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5654 | }; |
| 5655 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5656 | enum usb_pd_control_swap { |
| 5657 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5658 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5659 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5660 | USB_PD_CTRL_SWAP_VCONN = 3, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5661 | USB_PD_CTRL_SWAP_COUNT, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5662 | }; |
| 5663 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5664 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5665 | uint8_t port; |
| 5666 | uint8_t role; |
| 5667 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5668 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5669 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5670 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5671 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5672 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5673 | #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] | 5674 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5675 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5676 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5677 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5678 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5679 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5680 | #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^] | 5681 | /* Partner unconstrained power */ |
| 5682 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5683 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5684 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5685 | uint8_t enabled; |
| 5686 | uint8_t role; |
| 5687 | uint8_t polarity; |
| 5688 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5689 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5690 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5691 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5692 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5693 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5694 | uint8_t polarity; |
| 5695 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5696 | } __ec_align1; |
| 5697 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5698 | /* Possible port partner connections based on CC line states */ |
| 5699 | enum pd_cc_states { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5700 | PD_CC_NONE = 0, /* No port partner attached */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5701 | |
| 5702 | /* From DFP perspective */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5703 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
| 5704 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5705 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5706 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5707 | |
| 5708 | /* From UFP perspective */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5709 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
| 5710 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5711 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5712 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5713 | /* Active/Passive Cable */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5714 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5715 | /* Optical/Non-optical cable */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5716 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5717 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5718 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5719 | /* Active Link Uni-Direction */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5720 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5721 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5722 | struct ec_response_usb_pd_control_v2 { |
| 5723 | uint8_t enabled; |
| 5724 | uint8_t role; |
| 5725 | uint8_t polarity; |
| 5726 | char state[32]; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5727 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5728 | uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ |
| 5729 | uint8_t reserved; /* Reserved for future use */ |
| 5730 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
| 5731 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
| 5732 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5733 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5734 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5735 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5736 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5737 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5738 | #define EC_USB_PD_MAX_PORTS 8 |
| 5739 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5740 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5741 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5742 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5743 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5744 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5745 | |
| 5746 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5747 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5748 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5749 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5750 | |
| 5751 | enum usb_chg_type { |
| 5752 | USB_CHG_TYPE_NONE, |
| 5753 | USB_CHG_TYPE_PD, |
| 5754 | USB_CHG_TYPE_C, |
| 5755 | USB_CHG_TYPE_PROPRIETARY, |
| 5756 | USB_CHG_TYPE_BC12_DCP, |
| 5757 | USB_CHG_TYPE_BC12_CDP, |
| 5758 | USB_CHG_TYPE_BC12_SDP, |
| 5759 | USB_CHG_TYPE_OTHER, |
| 5760 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5761 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5762 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5763 | }; |
| 5764 | enum usb_power_roles { |
| 5765 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5766 | USB_PD_PORT_POWER_SOURCE, |
| 5767 | USB_PD_PORT_POWER_SINK, |
| 5768 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5769 | }; |
| 5770 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5771 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5772 | uint16_t voltage_max; |
| 5773 | uint16_t voltage_now; |
| 5774 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5775 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5776 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5777 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5778 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5779 | uint8_t role; |
| 5780 | uint8_t type; |
| 5781 | uint8_t dualrole; |
| 5782 | uint8_t reserved1; |
| 5783 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5784 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5785 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5786 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5787 | /* |
| 5788 | * This command will return the number of USB PD charge port + the number |
| 5789 | * of dedicated port present. |
| 5790 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5791 | */ |
| 5792 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5793 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5794 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5795 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5796 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 5797 | /* |
| 5798 | * This command enable/disable dynamic PDO selection. |
| 5799 | */ |
| 5800 | #define EC_CMD_USB_PD_DPS_CONTROL 0x0106 |
| 5801 | |
| 5802 | struct ec_params_usb_pd_dps_control { |
| 5803 | uint8_t enable; |
| 5804 | } __ec_align1; |
| 5805 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5806 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5807 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5808 | |
| 5809 | enum usb_pd_fw_update_cmds { |
| 5810 | USB_PD_FW_REBOOT, |
| 5811 | USB_PD_FW_FLASH_ERASE, |
| 5812 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5813 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5814 | }; |
| 5815 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5816 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5817 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5818 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5819 | uint8_t port; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5820 | |
| 5821 | /* Size to write in bytes */ |
| 5822 | uint32_t size; |
| 5823 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5824 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5825 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5826 | |
| 5827 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5828 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5829 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5830 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5831 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5832 | uint16_t dev_id; |
| 5833 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 5834 | |
| 5835 | /* |
| 5836 | * Reserved for alignment of current_image |
| 5837 | * TODO(rspangler) but it's not aligned! |
| 5838 | * Should have been reserved[2]. |
| 5839 | */ |
| 5840 | uint8_t reserved; |
| 5841 | |
| 5842 | /* One of ec_image */ |
| 5843 | uint32_t current_image; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5844 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5845 | |
| 5846 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5847 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5848 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5849 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5850 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5851 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5852 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5853 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5854 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5855 | struct ec_params_usb_pd_discovery_entry { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5856 | uint16_t vid; /* USB-IF VID */ |
| 5857 | uint16_t pid; /* USB-IF PID */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5858 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5859 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5860 | |
| 5861 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5862 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5863 | |
| 5864 | /* Negative port parameters have special meaning */ |
| 5865 | enum usb_pd_override_ports { |
| 5866 | OVERRIDE_DONT_CHARGE = -2, |
| 5867 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5868 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5869 | }; |
| 5870 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5871 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5872 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5873 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5874 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5875 | /* |
| 5876 | * Read (and delete) one entry of PD event log. |
| 5877 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5878 | * future non-PD logs that use the same internal EC event_log. |
| 5879 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5880 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5881 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5882 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5883 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5884 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5885 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5886 | uint16_t data; /* type-defined data payload */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5887 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5888 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5889 | |
| 5890 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5891 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5892 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5893 | #define PD_LOG_SIZE_MASK 0x1f |
| 5894 | #define PD_LOG_PORT_MASK 0xe0 |
| 5895 | #define PD_LOG_PORT_SHIFT 5 |
| 5896 | #define PD_LOG_PORT_SIZE(port, size) \ |
| 5897 | (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK)) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5898 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5899 | #define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5900 | |
| 5901 | /* PD event log : entry types */ |
| 5902 | /* PD MCU events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5903 | #define PD_EVENT_MCU_BASE 0x00 |
| 5904 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0) |
| 5905 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5906 | /* Reserved for custom board event */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5907 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5908 | /* PD generic accessory events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5909 | #define PD_EVENT_ACC_BASE 0x20 |
| 5910 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0) |
| 5911 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5912 | /* PD power supply events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5913 | #define PD_EVENT_PS_BASE 0x40 |
| 5914 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5915 | /* PD video dongles events */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5916 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5917 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0) |
| 5918 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5919 | /* Returned in the "type" field, when there is no entry available */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5920 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5921 | |
| 5922 | /* |
| 5923 | * PD_EVENT_MCU_CHARGE event definition : |
| 5924 | * the payload is "struct usb_chg_measures" |
| 5925 | * the data field contains the port state flags as defined below : |
| 5926 | */ |
| 5927 | /* Port partner is a dual role device */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5928 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5929 | /* Port is the pending override port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5930 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5931 | /* Port is the override port */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5932 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5933 | /* Charger type */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5934 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
| 5935 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5936 | /* Power delivery role */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5937 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5938 | |
| 5939 | /* |
| 5940 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5941 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5942 | #define PS_FAULT_OCP 1 |
| 5943 | #define PS_FAULT_FAST_OCP 2 |
| 5944 | #define PS_FAULT_OVP 3 |
| 5945 | #define PS_FAULT_DISCH 4 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5946 | |
| 5947 | /* |
| 5948 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5949 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5950 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5951 | uint8_t major; |
| 5952 | uint8_t minor; |
| 5953 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5954 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5955 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5956 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5957 | uint8_t family[2]; |
| 5958 | uint8_t chipid[2]; |
| 5959 | struct mcdp_version irom; |
| 5960 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5961 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5962 | |
| 5963 | /* struct mcdp_info field decoding */ |
| 5964 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5965 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5966 | |
| 5967 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5968 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5969 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5970 | uint16_t svid_idx; /* SVID index to get */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5971 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5972 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5973 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5974 | struct ec_params_usb_pd_get_mode_response { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5975 | uint16_t svid; /* SVID */ |
| 5976 | uint16_t opos; /* Object Position */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5977 | uint32_t vdo[6]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5978 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5979 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5980 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5981 | |
| 5982 | enum pd_mode_cmd { |
| 5983 | PD_EXIT_MODE = 0, |
| 5984 | PD_ENTER_MODE = 1, |
| 5985 | /* Not a command. Do NOT remove. */ |
| 5986 | PD_MODE_CMD_COUNT, |
| 5987 | }; |
| 5988 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5989 | struct ec_params_usb_pd_set_mode_request { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5990 | uint32_t cmd; /* enum pd_mode_cmd */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5991 | uint16_t svid; /* SVID to set */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 5992 | uint8_t opos; /* Object Position */ |
| 5993 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5994 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5995 | |
| 5996 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5997 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5998 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5999 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6000 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 6001 | 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] | 6002 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 6003 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6004 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6005 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6006 | |
| 6007 | enum ec_pd_control_cmd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6008 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 6009 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 6010 | PD_RESET, /* Force reset the PD chip */ |
| 6011 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 6012 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6013 | }; |
| 6014 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6015 | struct ec_params_pd_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6016 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6017 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6018 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 6019 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6020 | /* Get info about USB-C SS muxes */ |
| 6021 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 6022 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6023 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6024 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6025 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6026 | |
| 6027 | /* Flags representing mux state */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6028 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 6029 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 6030 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 6031 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 6032 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 6033 | #define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */ |
| 6034 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 6035 | #define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */ |
| 6036 | #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] | 6037 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6038 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6039 | |
| 6040 | /* USB-C Dock connected */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6041 | #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] | 6042 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6043 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6044 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6045 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6046 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6047 | #define EC_CMD_PD_CHIP_INFO 0x011B |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6048 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6049 | struct ec_params_pd_chip_info { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6050 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6051 | /* |
| 6052 | * Fetch the live chip info or hard-coded + cached chip info |
| 6053 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 6054 | * 1: live chip value for VID/PID/FW Version |
| 6055 | */ |
| 6056 | uint8_t live; |
| 6057 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6058 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6059 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6060 | uint16_t vendor_id; |
| 6061 | uint16_t product_id; |
| 6062 | uint16_t device_id; |
| 6063 | union { |
| 6064 | uint8_t fw_version_string[8]; |
| 6065 | uint64_t fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6066 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6067 | } __ec_align2; |
| 6068 | |
| 6069 | struct ec_response_pd_chip_info_v1 { |
| 6070 | uint16_t vendor_id; |
| 6071 | uint16_t product_id; |
| 6072 | uint16_t device_id; |
| 6073 | union { |
| 6074 | uint8_t fw_version_string[8]; |
| 6075 | uint64_t fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6076 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6077 | union { |
| 6078 | uint8_t min_req_fw_version_string[8]; |
| 6079 | uint64_t min_req_fw_version_number; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6080 | } __ec_align2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6081 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6082 | |
| 6083 | /* Run RW signature verification and get status */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6084 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6085 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6086 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6087 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6088 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6089 | |
| 6090 | /* For controlling RWSIG task */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6091 | #define EC_CMD_RWSIG_ACTION 0x011D |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6092 | |
| 6093 | enum rwsig_action { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6094 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 6095 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6096 | }; |
| 6097 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6098 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6099 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6100 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6101 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6102 | /* Run verification on a slot */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6103 | #define EC_CMD_EFS_VERIFY 0x011E |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6104 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6105 | struct ec_params_efs_verify { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6106 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6107 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6108 | |
| 6109 | /* |
| 6110 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 6111 | * type. Integers return a uint32. Strings return a string, using the response |
| 6112 | * size to determine how big it is. |
| 6113 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6114 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6115 | /* |
| 6116 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 6117 | * hardware write-protect enabled. |
| 6118 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6119 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6120 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6121 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6122 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6123 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 6124 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 6125 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6126 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
| 6127 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
| 6128 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
| 6129 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6130 | /* Second Source Factory Cache */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6131 | CBI_TAG_SSFC = 8, /* uint32_t bit field */ |
| 6132 | CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6133 | CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 6134 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6135 | }; |
| 6136 | |
| 6137 | /* |
| 6138 | * Flags to control read operation |
| 6139 | * |
| 6140 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 6141 | * write was successful without reboot. |
| 6142 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6143 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6144 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6145 | struct ec_params_get_cbi { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6146 | uint32_t tag; /* enum cbi_data_tag */ |
| 6147 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6148 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6149 | |
| 6150 | /* |
| 6151 | * Flags to control write behavior. |
| 6152 | * |
| 6153 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 6154 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6155 | * 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] | 6156 | * will be initialized to zero first. |
| 6157 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6158 | #define CBI_SET_NO_SYNC BIT(0) |
| 6159 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6160 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6161 | struct ec_params_set_cbi { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6162 | uint32_t tag; /* enum cbi_data_tag */ |
| 6163 | uint32_t flag; /* CBI_SET_* */ |
| 6164 | uint32_t size; /* Data size */ |
| 6165 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6166 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 6167 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6168 | /* |
| 6169 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 6170 | */ |
| 6171 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 6172 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6173 | /* EC reset causes */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6174 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 6175 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 6176 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 6177 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 6178 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 6179 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 6180 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 6181 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 6182 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 6183 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 6184 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 6185 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 6186 | #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^] | 6187 | /* Some reset flags preserved from previous boot */ |
| 6188 | #define EC_RESET_FLAG_PRESERVED BIT(13) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6189 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 6190 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 6191 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 6192 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6193 | /* AP experienced a watchdog reset */ |
| 6194 | #define EC_RESET_FLAG_AP_WATCHDOG BIT(18) |
| 6195 | /* Do not select RW in EFS. This enables PD in RO for Chromebox. */ |
| 6196 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6197 | #define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */ |
| 6198 | #define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */ |
| 6199 | #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] | 6200 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6201 | /* |
| 6202 | * Reason codes used by the AP after a shutdown to figure out why it was reset |
| 6203 | * by the EC. These are sent in EC commands. Therefore, to maintain protocol |
| 6204 | * compatibility: |
| 6205 | * - New entries must be inserted prior to the _COUNT field |
| 6206 | * - If an existing entry is no longer in service, it must be replaced with a |
| 6207 | * RESERVED entry instead. |
| 6208 | * - The semantic meaning of an entry should not change. |
| 6209 | * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons. |
| 6210 | */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6211 | enum chipset_shutdown_reason { |
| 6212 | /* |
| 6213 | * Beginning of reset reasons. |
| 6214 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6215 | CHIPSET_RESET_BEGIN = 0, |
| 6216 | CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN, |
| 6217 | /* Custom reason defined by a board.c or baseboard.c file */ |
| 6218 | CHIPSET_RESET_BOARD_CUSTOM, |
| 6219 | /* Believe that the AP has hung */ |
| 6220 | CHIPSET_RESET_HANG_REBOOT, |
| 6221 | /* Reset by EC console command */ |
| 6222 | CHIPSET_RESET_CONSOLE_CMD, |
| 6223 | /* Reset by EC host command */ |
| 6224 | CHIPSET_RESET_HOST_CMD, |
| 6225 | /* Keyboard module reset key combination */ |
| 6226 | CHIPSET_RESET_KB_SYSRESET, |
| 6227 | /* Keyboard module warm reboot */ |
| 6228 | CHIPSET_RESET_KB_WARM_REBOOT, |
| 6229 | /* Debug module warm reboot */ |
| 6230 | CHIPSET_RESET_DBG_WARM_REBOOT, |
| 6231 | /* I cannot self-terminate. You must lower me into the steel. */ |
| 6232 | CHIPSET_RESET_AP_REQ, |
| 6233 | /* Reset as side-effect of startup sequence */ |
| 6234 | CHIPSET_RESET_INIT, |
| 6235 | /* EC detected an AP watchdog event. */ |
| 6236 | CHIPSET_RESET_AP_WATCHDOG, |
| 6237 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6238 | CHIPSET_RESET_COUNT, /* End of reset reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6239 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6240 | /* |
| 6241 | * Beginning of shutdown reasons. |
| 6242 | */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6243 | CHIPSET_SHUTDOWN_BEGIN = BIT(15), |
| 6244 | CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN, |
| 6245 | /* Forcing a shutdown as part of EC initialization */ |
| 6246 | CHIPSET_SHUTDOWN_INIT, |
| 6247 | /* Custom reason on a per-board basis. */ |
| 6248 | CHIPSET_SHUTDOWN_BOARD_CUSTOM, |
| 6249 | /* This is a reason to inhibit startup, not cause shut down. */ |
| 6250 | CHIPSET_SHUTDOWN_BATTERY_INHIBIT, |
| 6251 | /* A power_wait_signal is being asserted */ |
| 6252 | CHIPSET_SHUTDOWN_WAIT, |
| 6253 | /* Critical battery level. */ |
| 6254 | CHIPSET_SHUTDOWN_BATTERY_CRIT, |
| 6255 | /* Because you told me to. */ |
| 6256 | CHIPSET_SHUTDOWN_CONSOLE_CMD, |
| 6257 | /* Forcing a shutdown to effect entry to G3. */ |
| 6258 | CHIPSET_SHUTDOWN_G3, |
| 6259 | /* Force shutdown due to over-temperature. */ |
| 6260 | CHIPSET_SHUTDOWN_THERMAL, |
| 6261 | /* Force a chipset shutdown from the power button through EC */ |
| 6262 | CHIPSET_SHUTDOWN_BUTTON, |
| 6263 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6264 | CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6265 | }; |
| 6266 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6267 | struct ec_response_uptime_info { |
| 6268 | /* |
| 6269 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 6270 | * typically do not restart the EC's time_since_boot epoch. |
| 6271 | * |
| 6272 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 6273 | * sense of time, in both phase and frequency. This timebase is similar |
| 6274 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 6275 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6276 | uint32_t time_since_ec_boot_ms; |
| 6277 | |
| 6278 | /* |
| 6279 | * Number of times the AP was reset by the EC since the last EC boot. |
| 6280 | * Note that the AP may be held in reset by the EC during the initial |
| 6281 | * boot sequence, such that the very first AP boot may count as more |
| 6282 | * than one here. |
| 6283 | */ |
| 6284 | uint32_t ap_resets_since_ec_boot; |
| 6285 | |
| 6286 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6287 | * The set of flags which describe the EC's most recent reset. |
| 6288 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6289 | */ |
| 6290 | uint32_t ec_reset_flags; |
| 6291 | |
| 6292 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 6293 | struct ap_reset_log_entry { |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6294 | /* See enum chipset_{reset,shutdown}_reason for details. */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6295 | uint16_t reset_cause; |
| 6296 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6297 | /* Reserved for protocol growth. */ |
| 6298 | uint16_t reserved; |
| 6299 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6300 | /* |
| 6301 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6302 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 6303 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6304 | */ |
| 6305 | uint32_t reset_time_ms; |
| 6306 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6307 | } __ec_align4; |
| 6308 | |
| 6309 | /* |
| 6310 | * Add entropy to the device secret (stored in the rollback region). |
| 6311 | * |
| 6312 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 6313 | * flash), so the commands are asynchronous. |
| 6314 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6315 | #define EC_CMD_ADD_ENTROPY 0x0122 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6316 | |
| 6317 | enum add_entropy_action { |
| 6318 | /* Add entropy to the current secret. */ |
| 6319 | ADD_ENTROPY_ASYNC = 0, |
| 6320 | /* |
| 6321 | * Add entropy, and also make sure that the previous secret is erased. |
| 6322 | * (this can be implemented by adding entropy multiple times until |
| 6323 | * all rolback blocks have been overwritten). |
| 6324 | */ |
| 6325 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 6326 | /* Read back result from the previous operation. */ |
| 6327 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6328 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6329 | |
| 6330 | struct ec_params_rollback_add_entropy { |
| 6331 | uint8_t action; |
| 6332 | } __ec_align1; |
| 6333 | |
| 6334 | /* |
| 6335 | * Perform a single read of a given ADC channel. |
| 6336 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6337 | #define EC_CMD_ADC_READ 0x0123 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6338 | |
| 6339 | struct ec_params_adc_read { |
| 6340 | uint8_t adc_channel; |
| 6341 | } __ec_align1; |
| 6342 | |
| 6343 | struct ec_response_adc_read { |
| 6344 | int32_t adc_value; |
| 6345 | } __ec_align4; |
| 6346 | |
| 6347 | /* |
| 6348 | * Read back rollback info |
| 6349 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6350 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6351 | |
| 6352 | struct ec_response_rollback_info { |
| 6353 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 6354 | int32_t rollback_min_version; |
| 6355 | int32_t rw_rollback_version; |
| 6356 | } __ec_align4; |
| 6357 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6358 | /* Issue AP reset */ |
| 6359 | #define EC_CMD_AP_RESET 0x0125 |
| 6360 | |
| 6361 | /*****************************************************************************/ |
| 6362 | /* Locate peripheral chips |
| 6363 | * |
| 6364 | * Return values: |
| 6365 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 6366 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 6367 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 6368 | */ |
| 6369 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 6370 | |
| 6371 | enum ec_chip_type { |
| 6372 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 6373 | EC_CHIP_TYPE_TCPC = 1, |
| 6374 | EC_CHIP_TYPE_COUNT, |
| 6375 | EC_CHIP_TYPE_MAX = 0xFF, |
| 6376 | }; |
| 6377 | |
| 6378 | enum ec_bus_type { |
| 6379 | EC_BUS_TYPE_I2C = 0, |
| 6380 | EC_BUS_TYPE_EMBEDDED = 1, |
| 6381 | EC_BUS_TYPE_COUNT, |
| 6382 | EC_BUS_TYPE_MAX = 0xFF, |
| 6383 | }; |
| 6384 | |
| 6385 | struct ec_i2c_info { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6386 | uint16_t port; /* Physical port for device */ |
| 6387 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6388 | }; |
| 6389 | |
| 6390 | struct ec_params_locate_chip { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6391 | uint8_t type; /* enum ec_chip_type */ |
| 6392 | uint8_t index; /* Specifies one instance of chip type */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6393 | /* Used for type specific parameters in future */ |
| 6394 | union { |
| 6395 | uint16_t reserved; |
| 6396 | }; |
| 6397 | } __ec_align2; |
| 6398 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6399 | struct ec_response_locate_chip { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6400 | uint8_t bus_type; /* enum ec_bus_type */ |
| 6401 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6402 | union { |
| 6403 | struct ec_i2c_info i2c_info; |
| 6404 | }; |
| 6405 | } __ec_align2; |
| 6406 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6407 | /* |
| 6408 | * Reboot AP on G3 |
| 6409 | * |
| 6410 | * This command is used for validation purpose, where the AP needs to be |
| 6411 | * 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] | 6412 | * wake events. |
| 6413 | * - With command version 0: |
| 6414 | * AP reboots immediately from G3 |
| 6415 | * command usage: ectool reboot_ap_on_g3 && shutdown -h now |
| 6416 | * - With command version 1: |
| 6417 | * AP reboots after the user specified delay |
| 6418 | * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6419 | */ |
| 6420 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 6421 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6422 | struct ec_params_reboot_ap_on_g3_v1 { |
| 6423 | /* configurable delay in seconds in G3 state */ |
| 6424 | uint32_t reboot_ap_at_g3_delay; |
| 6425 | } __ec_align4; |
| 6426 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6427 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6428 | /* Get PD port capabilities |
| 6429 | * |
| 6430 | * Returns the following static *capabilities* of the given port: |
| 6431 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 6432 | * future CrOS devices would ever be only a source, so the options are |
| 6433 | * sink or dual. |
| 6434 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 6435 | * believe any CrOS device would support Try.SNK, so this would be source |
| 6436 | * or none). |
| 6437 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 6438 | * for CrOS devices. |
| 6439 | */ |
| 6440 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 6441 | |
| 6442 | enum ec_pd_power_role_caps { |
| 6443 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 6444 | EC_PD_POWER_ROLE_SINK = 1, |
| 6445 | EC_PD_POWER_ROLE_DUAL = 2, |
| 6446 | }; |
| 6447 | |
| 6448 | enum ec_pd_try_power_role_caps { |
| 6449 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 6450 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 6451 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 6452 | }; |
| 6453 | |
| 6454 | enum ec_pd_data_role_caps { |
| 6455 | EC_PD_DATA_ROLE_DFP = 0, |
| 6456 | EC_PD_DATA_ROLE_UFP = 1, |
| 6457 | EC_PD_DATA_ROLE_DUAL = 2, |
| 6458 | }; |
| 6459 | |
| 6460 | /* From: power_manager/power_supply_properties.proto */ |
| 6461 | enum ec_pd_port_location { |
| 6462 | /* The location of the port is unknown, or there's only one port. */ |
| 6463 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 6464 | |
| 6465 | /* |
| 6466 | * Various positions on the device. The first word describes the side of |
| 6467 | * the device where the port is located while the second clarifies the |
| 6468 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 6469 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 6470 | * device. |
| 6471 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6472 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 6473 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 6474 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6475 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6476 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6477 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6478 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6479 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6480 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6481 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6482 | }; |
| 6483 | |
| 6484 | struct ec_params_get_pd_port_caps { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6485 | uint8_t port; /* Which port to interrogate */ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6486 | } __ec_align1; |
| 6487 | |
| 6488 | struct ec_response_get_pd_port_caps { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6489 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6490 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6491 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6492 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 6493 | } __ec_align1; |
| 6494 | |
| 6495 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6496 | /* |
| 6497 | * Button press simulation |
| 6498 | * |
| 6499 | * This command is used to simulate a button press. |
| 6500 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6501 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6502 | * |
| 6503 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6504 | */ |
| 6505 | #define EC_CMD_BUTTON 0x0129 |
| 6506 | |
| 6507 | struct ec_params_button { |
| 6508 | /* Button mask aligned to enum keyboard_button_type */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6509 | uint32_t btn_mask; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6510 | |
| 6511 | /* Duration in milliseconds button needs to be pressed */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6512 | uint32_t press_ms; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6513 | } __ec_align1; |
| 6514 | |
| 6515 | enum keyboard_button_type { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6516 | KEYBOARD_BUTTON_POWER = 0, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6517 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6518 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6519 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6520 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6521 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6522 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6523 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6524 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6525 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6526 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6527 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6528 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6529 | KEYBOARD_BUTTON_COUNT, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6530 | }; |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6531 | |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6532 | /*****************************************************************************/ |
| 6533 | /* |
| 6534 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6535 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6536 | * Additionally, capability to send function codes for the same keys is |
| 6537 | * optional and acceptable. |
| 6538 | * |
| 6539 | * Note: If the top row can generate both function and action codes by |
| 6540 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6541 | * "function" or "action" codes by default. In both cases, the response |
| 6542 | * for this command will look the same. |
| 6543 | */ |
| 6544 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6545 | |
| 6546 | /* Possible values for the top row keys */ |
| 6547 | enum action_key { |
| 6548 | TK_ABSENT = 0, |
| 6549 | TK_BACK = 1, |
| 6550 | TK_FORWARD = 2, |
| 6551 | TK_REFRESH = 3, |
| 6552 | TK_FULLSCREEN = 4, |
| 6553 | TK_OVERVIEW = 5, |
| 6554 | TK_BRIGHTNESS_DOWN = 6, |
| 6555 | TK_BRIGHTNESS_UP = 7, |
| 6556 | TK_VOL_MUTE = 8, |
| 6557 | TK_VOL_DOWN = 9, |
| 6558 | TK_VOL_UP = 10, |
| 6559 | TK_SNAPSHOT = 11, |
| 6560 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6561 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6562 | TK_KBD_BKLIGHT_UP = 14, |
| 6563 | TK_PLAY_PAUSE = 15, |
| 6564 | TK_NEXT_TRACK = 16, |
| 6565 | TK_PREV_TRACK = 17, |
Scott Chao | 18141d8c | 2021-07-30 10:40:57 +0800 | [diff] [blame] | 6566 | TK_KBD_BKLIGHT_TOGGLE = 18, |
| 6567 | TK_MICMUTE = 19, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6568 | TK_MENU = 20, |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6569 | }; |
| 6570 | |
| 6571 | /* |
| 6572 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6573 | * If this needs to change, please create a new version of the command. |
| 6574 | */ |
| 6575 | #define MAX_TOP_ROW_KEYS 15 |
| 6576 | #define MIN_TOP_ROW_KEYS 10 |
| 6577 | |
| 6578 | /* |
| 6579 | * Is the keyboard capable of sending function keys *in addition to* |
| 6580 | * action keys. This is possible for e.g. if the keyboard has a |
| 6581 | * dedicated Fn key. |
| 6582 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6583 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6584 | /* |
| 6585 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6586 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6587 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6588 | /* |
| 6589 | * Whether the keyboard has a screenlock key. |
| 6590 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6591 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6592 | |
| 6593 | struct ec_response_keybd_config { |
| 6594 | /* |
| 6595 | * Number of top row keys, excluding Esc and Screenlock. |
| 6596 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6597 | * (i.e. does not expose any tables to the kernel). |
| 6598 | */ |
| 6599 | uint8_t num_top_row_keys; |
| 6600 | |
| 6601 | /* |
| 6602 | * The action keys in the top row, in order from left to right. |
| 6603 | * The values are filled from enum action_key. Esc and Screenlock |
| 6604 | * keys are not considered part of top row keys. |
| 6605 | */ |
| 6606 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6607 | |
| 6608 | /* Capability flags */ |
| 6609 | uint8_t capabilities; |
| 6610 | |
| 6611 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6612 | |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6613 | /* |
| 6614 | * Configure smart discharge |
| 6615 | */ |
| 6616 | #define EC_CMD_SMART_DISCHARGE 0x012B |
| 6617 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6618 | #define EC_SMART_DISCHARGE_FLAGS_SET BIT(0) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6619 | |
| 6620 | /* Discharge rates when the system is in cutoff or hibernation. */ |
| 6621 | struct discharge_rate { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6622 | uint16_t cutoff; /* Discharge rate (uA) in cutoff */ |
| 6623 | uint16_t hibern; /* Discharge rate (uA) in hibernation */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6624 | }; |
| 6625 | |
| 6626 | struct smart_discharge_zone { |
| 6627 | /* When the capacity (mAh) goes below this, EC cuts off the battery. */ |
| 6628 | int cutoff; |
| 6629 | /* When the capacity (mAh) is below this, EC stays up. */ |
| 6630 | int stayup; |
| 6631 | }; |
| 6632 | |
| 6633 | struct ec_params_smart_discharge { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6634 | uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6635 | /* |
| 6636 | * Desired hours for the battery to survive before reaching 0%. Set to |
| 6637 | * zero to disable smart discharging. That is, the system hibernates as |
| 6638 | * soon as the G3 idle timer expires. |
| 6639 | */ |
| 6640 | uint16_t hours_to_zero; |
| 6641 | /* Set both to zero to keep the current rates. */ |
| 6642 | struct discharge_rate drate; |
| 6643 | }; |
| 6644 | |
| 6645 | struct ec_response_smart_discharge { |
| 6646 | uint16_t hours_to_zero; |
| 6647 | struct discharge_rate drate; |
| 6648 | struct smart_discharge_zone dzone; |
| 6649 | }; |
| 6650 | |
| 6651 | /*****************************************************************************/ |
| 6652 | /* Voltage regulator controls */ |
| 6653 | |
| 6654 | /* |
| 6655 | * Get basic info of voltage regulator for given index. |
| 6656 | * |
| 6657 | * Returns the regulator name and supported voltage list in mV. |
| 6658 | */ |
| 6659 | #define EC_CMD_REGULATOR_GET_INFO 0x012C |
| 6660 | |
| 6661 | /* Maximum length of regulator name */ |
| 6662 | #define EC_REGULATOR_NAME_MAX_LEN 16 |
| 6663 | |
| 6664 | /* Maximum length of the supported voltage list. */ |
| 6665 | #define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 |
| 6666 | |
| 6667 | struct ec_params_regulator_get_info { |
| 6668 | uint32_t index; |
| 6669 | } __ec_align4; |
| 6670 | |
| 6671 | struct ec_response_regulator_get_info { |
| 6672 | char name[EC_REGULATOR_NAME_MAX_LEN]; |
| 6673 | uint16_t num_voltages; |
| 6674 | uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; |
| 6675 | } __ec_align2; |
| 6676 | |
| 6677 | /* |
| 6678 | * Configure the regulator as enabled / disabled. |
| 6679 | */ |
| 6680 | #define EC_CMD_REGULATOR_ENABLE 0x012D |
| 6681 | |
| 6682 | struct ec_params_regulator_enable { |
| 6683 | uint32_t index; |
| 6684 | uint8_t enable; |
| 6685 | } __ec_align4; |
| 6686 | |
| 6687 | /* |
| 6688 | * Query if the regulator is enabled. |
| 6689 | * |
| 6690 | * Returns 1 if the regulator is enabled, 0 if not. |
| 6691 | */ |
| 6692 | #define EC_CMD_REGULATOR_IS_ENABLED 0x012E |
| 6693 | |
| 6694 | struct ec_params_regulator_is_enabled { |
| 6695 | uint32_t index; |
| 6696 | } __ec_align4; |
| 6697 | |
| 6698 | struct ec_response_regulator_is_enabled { |
| 6699 | uint8_t enabled; |
| 6700 | } __ec_align1; |
| 6701 | |
| 6702 | /* |
| 6703 | * Set voltage for the voltage regulator within the range specified. |
| 6704 | * |
| 6705 | * The driver should select the voltage in range closest to min_mv. |
| 6706 | * |
| 6707 | * Also note that this might be called before the regulator is enabled, and the |
| 6708 | * setting should be in effect after the regulator is enabled. |
| 6709 | */ |
| 6710 | #define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F |
| 6711 | |
| 6712 | struct ec_params_regulator_set_voltage { |
| 6713 | uint32_t index; |
| 6714 | uint32_t min_mv; |
| 6715 | uint32_t max_mv; |
| 6716 | } __ec_align4; |
| 6717 | |
| 6718 | /* |
| 6719 | * Get the currently configured voltage for the voltage regulator. |
| 6720 | * |
| 6721 | * Note that this might be called before the regulator is enabled, and this |
| 6722 | * should return the configured output voltage if the regulator is enabled. |
| 6723 | */ |
| 6724 | #define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 |
| 6725 | |
| 6726 | struct ec_params_regulator_get_voltage { |
| 6727 | uint32_t index; |
| 6728 | } __ec_align4; |
| 6729 | |
| 6730 | struct ec_response_regulator_get_voltage { |
| 6731 | uint32_t voltage_mv; |
| 6732 | } __ec_align4; |
| 6733 | |
| 6734 | /* |
| 6735 | * Gather all discovery information for the given port and partner type. |
| 6736 | * |
| 6737 | * Note that if discovery has not yet completed, only the currently completed |
| 6738 | * responses will be filled in. If the discovery data structures are changed |
| 6739 | * in the process of the command running, BUSY will be returned. |
| 6740 | * |
| 6741 | * VDO field sizes are set to the maximum possible number of VDOs a VDM may |
| 6742 | * contain, while the number of SVIDs here is selected to fit within the PROTO2 |
| 6743 | * maximum parameter size. |
| 6744 | */ |
| 6745 | #define EC_CMD_TYPEC_DISCOVERY 0x0131 |
| 6746 | |
| 6747 | enum typec_partner_type { |
| 6748 | TYPEC_PARTNER_SOP = 0, |
| 6749 | TYPEC_PARTNER_SOP_PRIME = 1, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6750 | TYPEC_PARTNER_SOP_PRIME_PRIME = 2, |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6751 | }; |
| 6752 | |
| 6753 | struct ec_params_typec_discovery { |
| 6754 | uint8_t port; |
| 6755 | uint8_t partner_type; /* enum typec_partner_type */ |
| 6756 | } __ec_align1; |
| 6757 | |
| 6758 | struct svid_mode_info { |
| 6759 | uint16_t svid; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6760 | uint16_t mode_count; /* Number of modes partner sent */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6761 | uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6762 | }; |
| 6763 | |
| 6764 | struct ec_response_typec_discovery { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6765 | uint8_t identity_count; /* Number of identity VDOs partner sent */ |
| 6766 | uint8_t svid_count; /* Number of SVIDs partner sent */ |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 6767 | uint16_t reserved; |
| 6768 | uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */ |
| 6769 | struct svid_mode_info svids[0]; |
| 6770 | } __ec_align1; |
| 6771 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6772 | /* USB Type-C commands for AP-controlled device policy. */ |
| 6773 | #define EC_CMD_TYPEC_CONTROL 0x0132 |
| 6774 | |
| 6775 | enum typec_control_command { |
| 6776 | TYPEC_CONTROL_COMMAND_EXIT_MODES, |
| 6777 | TYPEC_CONTROL_COMMAND_CLEAR_EVENTS, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6778 | TYPEC_CONTROL_COMMAND_ENTER_MODE, |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6779 | TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6780 | TYPEC_CONTROL_COMMAND_USB_MUX_SET, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6781 | TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE, |
| 6782 | TYPEC_CONTROL_COMMAND_SEND_VDM_REQ, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6783 | }; |
| 6784 | |
| 6785 | /* Modes (USB or alternate) that a type-C port may enter. */ |
| 6786 | enum typec_mode { |
| 6787 | TYPEC_MODE_DP, |
| 6788 | TYPEC_MODE_TBT, |
| 6789 | TYPEC_MODE_USB4, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6790 | }; |
| 6791 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6792 | /* Replies the AP may specify to the TBT EnterMode command as a UFP */ |
| 6793 | enum typec_tbt_ufp_reply { |
| 6794 | TYPEC_TBT_UFP_REPLY_NAK, |
| 6795 | TYPEC_TBT_UFP_REPLY_ACK, |
| 6796 | }; |
| 6797 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6798 | #define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF |
| 6799 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6800 | struct typec_usb_mux_set { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6801 | /* Index of the mux to set in the chain */ |
| 6802 | uint8_t mux_index; |
| 6803 | |
| 6804 | /* USB_PD_MUX_*-encoded USB mux state to set */ |
| 6805 | uint8_t mux_flags; |
| 6806 | } __ec_align1; |
| 6807 | |
| 6808 | #define VDO_MAX_SIZE 7 |
| 6809 | |
| 6810 | struct typec_vdm_req { |
| 6811 | /* VDM data, including VDM header */ |
| 6812 | uint32_t vdm_data[VDO_MAX_SIZE]; |
| 6813 | /* Number of 32-bit fields filled in */ |
| 6814 | uint8_t vdm_data_objects; |
| 6815 | /* Partner to address - see enum typec_partner_type */ |
| 6816 | uint8_t partner_type; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6817 | } __ec_align1; |
| 6818 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6819 | struct ec_params_typec_control { |
| 6820 | uint8_t port; |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6821 | uint8_t command; /* enum typec_control_command */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6822 | uint16_t reserved; |
| 6823 | |
| 6824 | /* |
| 6825 | * This section will be interpreted based on |command|. Define a |
| 6826 | * placeholder structure to avoid having to increase the size and bump |
| 6827 | * the command version when adding new sub-commands. |
| 6828 | */ |
| 6829 | union { |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6830 | /* Used for CLEAR_EVENTS */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6831 | uint32_t clear_events_mask; |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 6832 | /* Used for ENTER_MODE - enum typec_mode */ |
| 6833 | uint8_t mode_to_enter; |
| 6834 | /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */ |
| 6835 | uint8_t tbt_ufp_reply; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 6836 | /* Used for USB_MUX_SET */ |
| 6837 | struct typec_usb_mux_set mux_params; |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6838 | /* Used for BIST_SHARE_MODE */ |
| 6839 | uint8_t bist_share_mode; |
| 6840 | /* Used for VMD_REQ */ |
| 6841 | struct typec_vdm_req vdm_req_params; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6842 | uint8_t placeholder[128]; |
| 6843 | }; |
| 6844 | } __ec_align1; |
| 6845 | |
| 6846 | /* |
| 6847 | * Gather all status information for a port. |
| 6848 | * |
| 6849 | * Note: this covers many of the return fields from the deprecated |
| 6850 | * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the |
| 6851 | * discovery data. The "enum pd_cc_states" is defined with the deprecated |
| 6852 | * EC_CMD_USB_PD_CONTROL command. |
| 6853 | * |
| 6854 | * This also combines in the EC_CMD_USB_PD_MUX_INFO flags. |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6855 | */ |
| 6856 | #define EC_CMD_TYPEC_STATUS 0x0133 |
| 6857 | |
| 6858 | /* |
| 6859 | * Power role. |
| 6860 | * |
| 6861 | * Note this is also used for PD header creation, and values align to those in |
| 6862 | * the Power Delivery Specification Revision 3.0 (See |
| 6863 | * 6.2.1.1.4 Port Power Role). |
| 6864 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6865 | enum pd_power_role { |
| 6866 | PD_ROLE_SINK = 0, |
| 6867 | PD_ROLE_SOURCE = 1, |
| 6868 | }; |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6869 | |
| 6870 | /* |
| 6871 | * Data role. |
| 6872 | * |
| 6873 | * Note this is also used for PD header creation, and the first two values |
| 6874 | * align to those in the Power Delivery Specification Revision 3.0 (See |
| 6875 | * 6.2.1.1.6 Port Data Role). |
| 6876 | */ |
| 6877 | enum pd_data_role { |
| 6878 | PD_ROLE_UFP = 0, |
| 6879 | PD_ROLE_DFP = 1, |
| 6880 | PD_ROLE_DISCONNECTED = 2, |
| 6881 | }; |
| 6882 | |
| 6883 | enum pd_vconn_role { |
| 6884 | PD_ROLE_VCONN_OFF = 0, |
| 6885 | PD_ROLE_VCONN_SRC = 1, |
| 6886 | }; |
| 6887 | |
| 6888 | /* |
| 6889 | * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2, |
| 6890 | * regardless of whether a debug accessory is connected. |
| 6891 | */ |
| 6892 | enum tcpc_cc_polarity { |
| 6893 | /* |
| 6894 | * _CCx: is used to indicate the polarity while not connected to |
| 6895 | * a Debug Accessory. Only one CC line will assert a resistor and |
| 6896 | * the other will be open. |
| 6897 | */ |
| 6898 | POLARITY_CC1 = 0, |
| 6899 | POLARITY_CC2 = 1, |
| 6900 | |
| 6901 | /* |
| 6902 | * _CCx_DTS is used to indicate the polarity while connected to a |
| 6903 | * SRC Debug Accessory. Assert resistors on both lines. |
| 6904 | */ |
| 6905 | POLARITY_CC1_DTS = 2, |
| 6906 | POLARITY_CC2_DTS = 3, |
| 6907 | |
| 6908 | /* |
| 6909 | * The current TCPC code relies on these specific POLARITY values. |
| 6910 | * Adding in a check to verify if the list grows for any reason |
| 6911 | * that this will give a hint that other places need to be |
| 6912 | * adjusted. |
| 6913 | */ |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6914 | POLARITY_COUNT, |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6915 | }; |
| 6916 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6917 | #define MODE_DP_PIN_A BIT(0) |
| 6918 | #define MODE_DP_PIN_B BIT(1) |
| 6919 | #define MODE_DP_PIN_C BIT(2) |
| 6920 | #define MODE_DP_PIN_D BIT(3) |
| 6921 | #define MODE_DP_PIN_E BIT(4) |
| 6922 | #define MODE_DP_PIN_F BIT(5) |
| 6923 | #define MODE_DP_PIN_ALL GENMASK(5, 0) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6924 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6925 | #define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0) |
| 6926 | #define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1) |
| 6927 | #define PD_STATUS_EVENT_HARD_RESET BIT(2) |
| 6928 | #define PD_STATUS_EVENT_DISCONNECTED BIT(3) |
| 6929 | #define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4) |
| 6930 | #define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5) |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6931 | #define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6) |
| 6932 | #define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7) |
| 6933 | #define PD_STATUS_EVENT_VDM_ATTENTION BIT(8) |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 6934 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6935 | /* |
| 6936 | * Encode and decode for BCD revision response |
| 6937 | * |
| 6938 | * Note: the major revision set is written assuming that the value given is the |
| 6939 | * Specification Revision from the PD header, which currently only maps to PD |
| 6940 | * 1.0-3.0 with the major revision being one greater than the binary value. |
| 6941 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6942 | #define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12) |
| 6943 | #define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF) |
| 6944 | #define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6945 | |
| 6946 | /* |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 6947 | * Encode revision from partner RMDO |
| 6948 | * |
| 6949 | * Unlike the specification revision given in the PD header, specification and |
| 6950 | * version information returned in the revision message data object (RMDO) is |
| 6951 | * not offset. |
| 6952 | */ |
| 6953 | #define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12) |
| 6954 | #define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8) |
| 6955 | #define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4) |
| 6956 | #define PD_STATUS_RMDO_VER_SET_MINOR(r) (r) |
| 6957 | |
| 6958 | /* |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6959 | * Decode helpers for Source and Sink Capability PDOs |
| 6960 | * |
| 6961 | * Note: The Power Delivery Specification should be considered the ultimate |
| 6962 | * source of truth on the decoding of these PDOs |
| 6963 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6964 | #define PDO_TYPE_FIXED (0 << 30) |
| 6965 | #define PDO_TYPE_BATTERY (1 << 30) |
| 6966 | #define PDO_TYPE_VARIABLE (2 << 30) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6967 | #define PDO_TYPE_AUGMENTED (3 << 30) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6968 | #define PDO_TYPE_MASK (3 << 30) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6969 | |
| 6970 | /* |
| 6971 | * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0 |
| 6972 | * |
| 6973 | * <31:30> : Fixed Supply |
| 6974 | * <29> : Dual-Role Power |
| 6975 | * <28> : SNK/SRC dependent |
| 6976 | * <27> : Unconstrained Power |
| 6977 | * <26> : USB Communications Capable |
| 6978 | * <25> : Dual-Role Data |
| 6979 | * <24:20> : SNK/SRC dependent |
| 6980 | * <19:10> : Voltage in 50mV Units |
| 6981 | * <9:0> : Maximum Current in 10mA units |
| 6982 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6983 | #define PDO_FIXED_DUAL_ROLE BIT(29) |
| 6984 | #define PDO_FIXED_UNCONSTRAINED BIT(27) |
| 6985 | #define PDO_FIXED_COMM_CAP BIT(26) |
| 6986 | #define PDO_FIXED_DATA_SWAP BIT(25) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6987 | #define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6988 | #define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 6989 | #define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 6990 | |
| 6991 | /* |
| 6992 | * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0 |
| 6993 | * |
| 6994 | * <31:30> : Battery |
| 6995 | * <29:20> : Maximum Voltage in 50mV units |
| 6996 | * <19:10> : Minimum Voltage in 50mV units |
| 6997 | * <9:0> : Maximum Allowable Power in 250mW units |
| 6998 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 6999 | #define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 7000 | #define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7001 | #define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7002 | |
| 7003 | /* |
| 7004 | * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0 |
| 7005 | * |
| 7006 | * <31:30> : Variable Supply (non-Battery) |
| 7007 | * <29:20> : Maximum Voltage in 50mV units |
| 7008 | * <19:10> : Minimum Voltage in 50mV units |
| 7009 | * <9:0> : Operational Current in 10mA units |
| 7010 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7011 | #define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50) |
| 7012 | #define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50) |
| 7013 | #define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7014 | |
| 7015 | /* |
| 7016 | * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0 |
| 7017 | * |
| 7018 | * Note this type is reserved in PD 2.0, and only one type of APDO is |
| 7019 | * supported as of the cited version. |
| 7020 | * |
| 7021 | * <31:30> : Augmented Power Data Object |
| 7022 | * <29:28> : Programmable Power Supply |
| 7023 | * <27> : PPS Power Limited |
| 7024 | * <26:25> : Reserved |
| 7025 | * <24:17> : Maximum Voltage in 100mV increments |
| 7026 | * <16> : Reserved |
| 7027 | * <15:8> : Minimum Voltage in 100mV increments |
| 7028 | * <7> : Reserved |
| 7029 | * <6:0> : Maximum Current in 50mA increments |
| 7030 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7031 | #define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100) |
| 7032 | #define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100) |
| 7033 | #define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50) |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7034 | |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7035 | struct ec_params_typec_status { |
| 7036 | uint8_t port; |
| 7037 | } __ec_align1; |
| 7038 | |
| 7039 | struct ec_response_typec_status { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7040 | uint8_t pd_enabled; /* PD communication enabled - bool */ |
| 7041 | uint8_t dev_connected; /* Device connected - bool */ |
| 7042 | uint8_t sop_connected; /* Device is SOP PD capable - bool */ |
| 7043 | uint8_t source_cap_count; /* Number of Source Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7044 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7045 | uint8_t power_role; /* enum pd_power_role */ |
| 7046 | uint8_t data_role; /* enum pd_data_role */ |
| 7047 | uint8_t vconn_role; /* enum pd_vconn_role */ |
| 7048 | uint8_t sink_cap_count; /* Number of Sink Cap PDOs */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7049 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7050 | uint8_t polarity; /* enum tcpc_cc_polarity */ |
| 7051 | uint8_t cc_state; /* enum pd_cc_states */ |
| 7052 | uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */ |
| 7053 | uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7054 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7055 | char tc_state[32]; /* TC state name */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7056 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7057 | uint32_t events; /* PD_STATUS_EVENT bitmask */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7058 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7059 | /* |
| 7060 | * BCD PD revisions for partners |
| 7061 | * |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7062 | * The format has the PD major revision in the upper nibble, and the PD |
| 7063 | * minor revision in the next nibble. The following two nibbles hold the |
| 7064 | * major and minor specification version. If a partner does not support |
| 7065 | * the Revision message, only the major revision will be given. |
| 7066 | * 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] | 7067 | * |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7068 | * 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] | 7069 | */ |
| 7070 | uint16_t sop_revision; |
| 7071 | uint16_t sop_prime_revision; |
| 7072 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7073 | 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] | 7074 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7075 | uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */ |
Tim Wawrzynczak | 7c80de6 | 2020-10-01 13:00:00 -0600 | [diff] [blame] | 7076 | } __ec_align1; |
| 7077 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7078 | /** |
| 7079 | * Get the number of peripheral charge ports |
| 7080 | */ |
| 7081 | #define EC_CMD_PCHG_COUNT 0x0134 |
| 7082 | |
| 7083 | #define EC_PCHG_MAX_PORTS 8 |
| 7084 | |
| 7085 | struct ec_response_pchg_count { |
| 7086 | uint8_t port_count; |
| 7087 | } __ec_align1; |
| 7088 | |
| 7089 | /** |
| 7090 | * Get the status of a peripheral charge port |
| 7091 | */ |
| 7092 | #define EC_CMD_PCHG 0x0135 |
| 7093 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7094 | /* For v1 and v2 */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7095 | struct ec_params_pchg { |
| 7096 | uint8_t port; |
| 7097 | } __ec_align1; |
| 7098 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7099 | struct ec_params_pchg_v3 { |
| 7100 | uint8_t port; |
| 7101 | /* Below are new in v3. */ |
| 7102 | uint8_t reserved1; |
| 7103 | uint8_t reserved2; |
| 7104 | uint8_t reserved3; |
| 7105 | /* Errors acked by the host (thus to be cleared) */ |
| 7106 | uint32_t error; |
| 7107 | } __ec_align1; |
| 7108 | |
| 7109 | /* For v1 */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7110 | struct ec_response_pchg { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7111 | uint32_t error; /* enum pchg_error */ |
| 7112 | uint8_t state; /* enum pchg_state state */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7113 | uint8_t battery_percentage; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7114 | uint8_t unused0; |
| 7115 | uint8_t unused1; |
| 7116 | /* Fields added in version 1 */ |
| 7117 | uint32_t fw_version; |
| 7118 | uint32_t dropped_event_count; |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7119 | } __ec_align4; |
| 7120 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7121 | /* For v2 and v3 */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7122 | struct ec_response_pchg_v2 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7123 | uint32_t error; /* enum pchg_error */ |
| 7124 | uint8_t state; /* enum pchg_state state */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7125 | uint8_t battery_percentage; |
| 7126 | uint8_t unused0; |
| 7127 | uint8_t unused1; |
| 7128 | /* Fields added in version 1 */ |
| 7129 | uint32_t fw_version; |
| 7130 | uint32_t dropped_event_count; |
| 7131 | /* Fields added in version 2 */ |
| 7132 | uint32_t dropped_host_event_count; |
| 7133 | } __ec_align4; |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7134 | |
| 7135 | enum pchg_state { |
| 7136 | /* Charger is reset and not initialized. */ |
| 7137 | PCHG_STATE_RESET = 0, |
| 7138 | /* Charger is initialized or disabled. */ |
| 7139 | PCHG_STATE_INITIALIZED, |
| 7140 | /* Charger is enabled and ready to detect a device. */ |
| 7141 | PCHG_STATE_ENABLED, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7142 | /* Device is in proximity. */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7143 | PCHG_STATE_DETECTED, |
| 7144 | /* Device is being charged. */ |
| 7145 | PCHG_STATE_CHARGING, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7146 | /* Device is fully charged. It implies DETECTED (& not charging). */ |
| 7147 | PCHG_STATE_FULL, |
| 7148 | /* In download (a.k.a. firmware update) mode */ |
| 7149 | PCHG_STATE_DOWNLOAD, |
| 7150 | /* In download mode. Ready for receiving data. */ |
| 7151 | PCHG_STATE_DOWNLOADING, |
| 7152 | /* Device is ready for data communication. */ |
| 7153 | PCHG_STATE_CONNECTED, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7154 | /* Charger is in Built-In Self Test mode. */ |
| 7155 | PCHG_STATE_BIST, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7156 | /* Put no more entry below */ |
| 7157 | PCHG_STATE_COUNT, |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7158 | }; |
| 7159 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7160 | /* clang-format off */ |
| 7161 | #define EC_PCHG_STATE_TEXT \ |
| 7162 | { \ |
| 7163 | [PCHG_STATE_RESET] = "RESET", \ |
| 7164 | [PCHG_STATE_INITIALIZED] = "INITIALIZED", \ |
| 7165 | [PCHG_STATE_ENABLED] = "ENABLED", \ |
| 7166 | [PCHG_STATE_DETECTED] = "DETECTED", \ |
| 7167 | [PCHG_STATE_CHARGING] = "CHARGING", \ |
| 7168 | [PCHG_STATE_FULL] = "FULL", \ |
| 7169 | [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \ |
| 7170 | [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \ |
| 7171 | [PCHG_STATE_CONNECTED] = "CONNECTED", \ |
| 7172 | [PCHG_STATE_BIST] = "BIST", \ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7173 | } |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7174 | /* clang-format on */ |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7175 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7176 | /** |
| 7177 | * Update firmware of peripheral chip |
| 7178 | */ |
| 7179 | #define EC_CMD_PCHG_UPDATE 0x0136 |
| 7180 | |
| 7181 | /* Port number is encoded in bit[28:31]. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7182 | #define EC_MKBP_PCHG_PORT_SHIFT 28 |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7183 | /* Utility macros for converting MKBP event <-> port number. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7184 | #define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf) |
| 7185 | #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] | 7186 | /* Utility macro for extracting event bits. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7187 | #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] | 7188 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7189 | #define EC_MKBP_PCHG_UPDATE_OPENED BIT(0) |
| 7190 | #define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1) |
| 7191 | #define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2) |
| 7192 | #define EC_MKBP_PCHG_UPDATE_ERROR BIT(3) |
| 7193 | #define EC_MKBP_PCHG_DEVICE_EVENT BIT(4) |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7194 | |
| 7195 | enum ec_pchg_update_cmd { |
| 7196 | /* Reset chip to normal mode. */ |
| 7197 | EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0, |
| 7198 | /* Reset and put a chip in update (a.k.a. download) mode. */ |
| 7199 | EC_PCHG_UPDATE_CMD_OPEN, |
| 7200 | /* Write a block of data containing FW image. */ |
| 7201 | EC_PCHG_UPDATE_CMD_WRITE, |
| 7202 | /* Close update session. */ |
| 7203 | EC_PCHG_UPDATE_CMD_CLOSE, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7204 | /* Reset chip (without mode change). */ |
| 7205 | EC_PCHG_UPDATE_CMD_RESET, |
| 7206 | /* Enable pass-through mode. */ |
| 7207 | EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU, |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7208 | /* End of commands */ |
| 7209 | EC_PCHG_UPDATE_CMD_COUNT, |
| 7210 | }; |
| 7211 | |
| 7212 | struct ec_params_pchg_update { |
| 7213 | /* PCHG port number */ |
| 7214 | uint8_t port; |
| 7215 | /* enum ec_pchg_update_cmd */ |
| 7216 | uint8_t cmd; |
| 7217 | /* Padding */ |
| 7218 | uint8_t reserved0; |
| 7219 | uint8_t reserved1; |
| 7220 | /* Version of new firmware */ |
| 7221 | uint32_t version; |
| 7222 | /* CRC32 of new firmware */ |
| 7223 | uint32_t crc32; |
| 7224 | /* Address in chip memory where <data> is written to */ |
| 7225 | uint32_t addr; |
| 7226 | /* Size of <data> */ |
| 7227 | uint32_t size; |
| 7228 | /* Partial data of new firmware */ |
| 7229 | uint8_t data[]; |
| 7230 | } __ec_align4; |
| 7231 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7232 | BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT < |
| 7233 | BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8)); |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7234 | |
| 7235 | struct ec_response_pchg_update { |
| 7236 | /* Block size */ |
| 7237 | uint32_t block_size; |
| 7238 | } __ec_align4; |
| 7239 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7240 | #define EC_CMD_DISPLAY_SOC 0x0137 |
| 7241 | |
| 7242 | struct ec_response_display_soc { |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7243 | /* Display charge in 10ths of a % (1000=100.0%) */ |
| 7244 | int16_t display_soc; |
| 7245 | /* Full factor in 10ths of a % (1000=100.0%) */ |
| 7246 | int16_t full_factor; |
| 7247 | /* Shutdown SoC in 10ths of a % (1000=100.0%) */ |
| 7248 | int16_t shutdown_soc; |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7249 | } __ec_align2; |
| 7250 | |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7251 | #define EC_CMD_SET_BASE_STATE 0x0138 |
| 7252 | |
| 7253 | struct ec_params_set_base_state { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7254 | uint8_t cmd; /* enum ec_set_base_state_cmd */ |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7255 | } __ec_align1; |
| 7256 | |
| 7257 | enum ec_set_base_state_cmd { |
| 7258 | EC_SET_BASE_STATE_DETACH = 0, |
| 7259 | EC_SET_BASE_STATE_ATTACH, |
| 7260 | EC_SET_BASE_STATE_RESET, |
| 7261 | }; |
| 7262 | |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7263 | #define EC_CMD_I2C_CONTROL 0x0139 |
| 7264 | |
| 7265 | /* Subcommands for I2C control */ |
| 7266 | |
| 7267 | enum ec_i2c_control_command { |
| 7268 | EC_I2C_CONTROL_GET_SPEED, |
| 7269 | EC_I2C_CONTROL_SET_SPEED, |
| 7270 | }; |
| 7271 | |
| 7272 | #define EC_I2C_CONTROL_SPEED_UNKNOWN 0 |
| 7273 | |
| 7274 | struct ec_params_i2c_control { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7275 | uint8_t port; /* I2C port number */ |
| 7276 | uint8_t cmd; /* enum ec_i2c_control_command */ |
Boris Mittelberg | 0c3b7f5 | 2022-02-15 14:57:55 -0800 | [diff] [blame] | 7277 | union { |
| 7278 | uint16_t speed_khz; |
| 7279 | } cmd_params; |
| 7280 | } __ec_align_size1; |
| 7281 | |
| 7282 | struct ec_response_i2c_control { |
| 7283 | union { |
| 7284 | uint16_t speed_khz; |
| 7285 | } cmd_response; |
| 7286 | } __ec_align_size1; |
| 7287 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7288 | #define EC_CMD_RGBKBD_SET_COLOR 0x013A |
| 7289 | #define EC_CMD_RGBKBD 0x013B |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7290 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7291 | #define EC_RGBKBD_MAX_KEY_COUNT 128 |
| 7292 | #define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF |
| 7293 | #define EC_RGBKBD_MAX_SCALE 0xFF |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7294 | |
| 7295 | enum rgbkbd_state { |
| 7296 | /* RGB keyboard is reset and not initialized. */ |
| 7297 | RGBKBD_STATE_RESET = 0, |
| 7298 | /* RGB keyboard is initialized but not enabled. */ |
| 7299 | RGBKBD_STATE_INITIALIZED, |
| 7300 | /* RGB keyboard is disabled. */ |
| 7301 | RGBKBD_STATE_DISABLED, |
| 7302 | /* RGB keyboard is enabled and ready to receive a command. */ |
| 7303 | RGBKBD_STATE_ENABLED, |
| 7304 | |
| 7305 | /* Put no more entry below */ |
| 7306 | RGBKBD_STATE_COUNT, |
| 7307 | }; |
| 7308 | |
| 7309 | enum ec_rgbkbd_subcmd { |
| 7310 | EC_RGBKBD_SUBCMD_CLEAR = 1, |
| 7311 | EC_RGBKBD_SUBCMD_DEMO = 2, |
| 7312 | EC_RGBKBD_SUBCMD_SET_SCALE = 3, |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7313 | EC_RGBKBD_SUBCMD_GET_CONFIG = 4, |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7314 | EC_RGBKBD_SUBCMD_COUNT |
| 7315 | }; |
| 7316 | |
| 7317 | enum ec_rgbkbd_demo { |
| 7318 | EC_RGBKBD_DEMO_OFF = 0, |
| 7319 | EC_RGBKBD_DEMO_FLOW = 1, |
| 7320 | EC_RGBKBD_DEMO_DOT = 2, |
| 7321 | EC_RGBKBD_DEMO_COUNT, |
| 7322 | }; |
| 7323 | |
| 7324 | BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255); |
| 7325 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7326 | enum ec_rgbkbd_type { |
| 7327 | EC_RGBKBD_TYPE_UNKNOWN = 0, |
| 7328 | EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */ |
| 7329 | EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */ |
| 7330 | EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */ |
| 7331 | EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */ |
| 7332 | EC_RGBKBD_TYPE_COUNT, |
| 7333 | }; |
| 7334 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7335 | struct ec_rgbkbd_set_scale { |
| 7336 | uint8_t key; |
| 7337 | struct rgb_s scale; |
| 7338 | }; |
| 7339 | |
| 7340 | struct ec_params_rgbkbd { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7341 | uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7342 | union { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7343 | struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */ |
| 7344 | uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */ |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7345 | struct ec_rgbkbd_set_scale set_scale; |
| 7346 | }; |
| 7347 | } __ec_align1; |
| 7348 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7349 | struct ec_response_rgbkbd { |
| 7350 | /* |
| 7351 | * RGBKBD type supported by the device. |
| 7352 | */ |
| 7353 | |
| 7354 | uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */ |
| 7355 | } __ec_align1; |
| 7356 | |
Yu-Ping Wu | 3fa36f6 | 2022-06-28 16:12:41 +0800 | [diff] [blame] | 7357 | struct ec_params_rgbkbd_set_color { |
| 7358 | /* Specifies the starting key ID whose color is being changed. */ |
| 7359 | uint8_t start_key; |
| 7360 | /* Specifies # of elements in <color>. */ |
| 7361 | uint8_t length; |
| 7362 | /* RGB color data array of length up to MAX_KEY_COUNT. */ |
| 7363 | struct rgb_s color[]; |
| 7364 | } __ec_align1; |
| 7365 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7366 | /* |
| 7367 | * Gather the response to the most recent VDM REQ from the AP, as well |
| 7368 | * as popping the oldest VDM:Attention from the DPM queue |
| 7369 | */ |
| 7370 | #define EC_CMD_TYPEC_VDM_RESPONSE 0x013C |
| 7371 | |
| 7372 | struct ec_params_typec_vdm_response { |
| 7373 | uint8_t port; |
| 7374 | } __ec_align1; |
| 7375 | |
| 7376 | struct ec_response_typec_vdm_response { |
| 7377 | /* Number of 32-bit fields filled in */ |
| 7378 | uint8_t vdm_data_objects; |
| 7379 | /* Partner to address - see enum typec_partner_type */ |
| 7380 | uint8_t partner_type; |
| 7381 | /* enum ec_status describing VDM response */ |
| 7382 | uint16_t vdm_response_err; |
| 7383 | /* VDM data, including VDM header */ |
| 7384 | uint32_t vdm_response[VDO_MAX_SIZE]; |
| 7385 | /* Number of 32-bit Attention fields filled in */ |
| 7386 | uint8_t vdm_attention_objects; |
| 7387 | /* Number of remaining messages to consume */ |
| 7388 | uint8_t vdm_attention_left; |
| 7389 | /* Reserved */ |
| 7390 | uint16_t reserved1; |
| 7391 | /* VDM:Attention contents */ |
| 7392 | uint32_t vdm_attention[2]; |
| 7393 | } __ec_align1; |
| 7394 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 7395 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7396 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7397 | |
| 7398 | /*****************************************************************************/ |
| 7399 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7400 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7401 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7402 | #define EC_CMD_CR51_BASE 0x0300 |
| 7403 | #define EC_CMD_CR51_LAST 0x03FF |
| 7404 | |
| 7405 | /*****************************************************************************/ |
| 7406 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 7407 | |
| 7408 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 7409 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 7410 | |
| 7411 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 7412 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7413 | struct ec_params_fp_passthru { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7414 | uint16_t len; /* Number of bytes to write then read */ |
| 7415 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 7416 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7417 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7418 | |
| 7419 | /* Configure the Fingerprint MCU behavior */ |
| 7420 | #define EC_CMD_FP_MODE 0x0402 |
| 7421 | |
| 7422 | /* Put the sensor in its lowest power mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7423 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7424 | /* Wait to see a finger on the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7425 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7426 | /* Poll until the finger has left the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7427 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7428 | /* Capture the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7429 | #define FP_MODE_CAPTURE BIT(3) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7430 | /* Finger enrollment session on-going */ |
| 7431 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 7432 | /* Enroll the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7433 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7434 | /* Try to match the current finger image */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7435 | #define FP_MODE_MATCH BIT(6) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7436 | /* Reset and re-initialize the sensor. */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7437 | #define FP_MODE_RESET_SENSOR BIT(7) |
Yidi Lin | 42f7959 | 2020-09-21 18:04:10 +0800 | [diff] [blame] | 7438 | /* Sensor maintenance for dead pixels. */ |
| 7439 | #define FP_MODE_SENSOR_MAINTENANCE BIT(8) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7440 | /* special value: don't change anything just read back current mode */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7441 | #define FP_MODE_DONT_CHANGE BIT(31) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7442 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7443 | #define FP_VALID_MODES \ |
| 7444 | (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \ |
| 7445 | FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \ |
| 7446 | FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \ |
| 7447 | FP_MODE_DONT_CHANGE) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7448 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7449 | /* Capture types defined in bits [30..28] */ |
| 7450 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7451 | #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] | 7452 | /** |
| 7453 | * enum fp_capture_type - Specifies the "mode" when capturing images. |
| 7454 | * |
| 7455 | * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality |
| 7456 | * image (produces 'frame_size' bytes) |
| 7457 | * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x |
| 7458 | * bpp bits) |
| 7459 | * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard) |
| 7460 | * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard) |
| 7461 | * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast |
| 7462 | * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test |
| 7463 | * @FP_CAPTURE_TYPE_MAX: End of enum |
| 7464 | * |
| 7465 | * @note This enum must remain ordered, if you add new values you must ensure |
| 7466 | * that FP_CAPTURE_TYPE_MAX is still the last one. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7467 | */ |
| 7468 | enum fp_capture_type { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7469 | FP_CAPTURE_VENDOR_FORMAT = 0, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7470 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7471 | FP_CAPTURE_PATTERN0 = 2, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7472 | FP_CAPTURE_PATTERN1 = 3, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7473 | FP_CAPTURE_QUALITY_TEST = 4, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7474 | FP_CAPTURE_RESET_TEST = 5, |
| 7475 | FP_CAPTURE_TYPE_MAX, |
| 7476 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7477 | /* Extracts the capture type from the sensor 'mode' word */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7478 | #define FP_CAPTURE_TYPE(mode) \ |
| 7479 | (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7480 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7481 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7482 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7483 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7484 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7485 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7486 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7487 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7488 | |
| 7489 | /* Retrieve Fingerprint sensor information */ |
| 7490 | #define EC_CMD_FP_INFO 0x0403 |
| 7491 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7492 | /* Number of dead pixels detected on the last maintenance */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7493 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7494 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 7495 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7496 | /* No interrupt from the sensor */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7497 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7498 | /* SPI communication error */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7499 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7500 | /* Invalid sensor Hardware ID */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7501 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7502 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7503 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7504 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7505 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7506 | /* Sensor identification */ |
| 7507 | uint32_t vendor_id; |
| 7508 | uint32_t product_id; |
| 7509 | uint32_t model_id; |
| 7510 | uint32_t version; |
| 7511 | /* Image frame characteristics */ |
| 7512 | uint32_t frame_size; |
| 7513 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7514 | uint16_t width; |
| 7515 | uint16_t height; |
| 7516 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7517 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7518 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7519 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7520 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7521 | /* Sensor identification */ |
| 7522 | uint32_t vendor_id; |
| 7523 | uint32_t product_id; |
| 7524 | uint32_t model_id; |
| 7525 | uint32_t version; |
| 7526 | /* Image frame characteristics */ |
| 7527 | uint32_t frame_size; |
| 7528 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 7529 | uint16_t width; |
| 7530 | uint16_t height; |
| 7531 | uint16_t bpp; |
| 7532 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 7533 | /* Template/finger current information */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7534 | uint32_t template_size; /* max template size in bytes */ |
| 7535 | uint16_t template_max; /* maximum number of fingers/templates */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7536 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 7537 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7538 | uint32_t template_version; /* version of the template format */ |
| 7539 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7540 | |
| 7541 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7542 | #define EC_CMD_FP_FRAME 0x0404 |
| 7543 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7544 | /* constants defining the 'offset' field which also contains the frame index */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7545 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7546 | /* Frame buffer where the captured image is stored */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7547 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7548 | /* First frame buffer holding a template */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7549 | #define FP_FRAME_INDEX_TEMPLATE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7550 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7551 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7552 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7553 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7554 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7555 | |
| 7556 | /* Constants for encryption parameters */ |
| 7557 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 7558 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 7559 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7560 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7561 | #define FP_CONTEXT_TPM_BYTES 32 |
| 7562 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7563 | /* Constants for positive match parameters. */ |
| 7564 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 7565 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7566 | struct ec_fp_template_encryption_metadata { |
| 7567 | /* |
| 7568 | * Version of the structure format (N=3). |
| 7569 | */ |
| 7570 | uint16_t struct_version; |
| 7571 | /* Reserved bytes, set to 0. */ |
| 7572 | uint16_t reserved; |
| 7573 | /* |
| 7574 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 7575 | * a different one is used for every message. |
| 7576 | */ |
| 7577 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7578 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7579 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 7580 | }; |
| 7581 | |
| 7582 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7583 | /* |
| 7584 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 7585 | * in the high nibble, and the real offset within the frame in |
| 7586 | * FP_FRAME_OFFSET_MASK. |
| 7587 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7588 | uint32_t offset; |
| 7589 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7590 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7591 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7592 | /* Load a template into the MCU */ |
| 7593 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 7594 | |
| 7595 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 7596 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 7597 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7598 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7599 | uint32_t offset; |
| 7600 | uint32_t size; |
| 7601 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7602 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7603 | |
| 7604 | /* Clear the current fingerprint user context and set a new one */ |
| 7605 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 7606 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7607 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7608 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7609 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7610 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7611 | enum fp_context_action { |
| 7612 | FP_CONTEXT_ASYNC = 0, |
| 7613 | FP_CONTEXT_GET_RESULT = 1, |
| 7614 | }; |
| 7615 | |
| 7616 | /* Version 1 of the command is "asynchronous". */ |
| 7617 | struct ec_params_fp_context_v1 { |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7618 | uint8_t action; /**< enum fp_context_action */ |
| 7619 | uint8_t reserved[3]; /**< padding for alignment */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7620 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 7621 | } __ec_align4; |
| 7622 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7623 | #define EC_CMD_FP_STATS 0x0407 |
| 7624 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7625 | #define FPSTATS_CAPTURE_INV BIT(0) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7626 | #define FPSTATS_MATCHING_INV BIT(1) |
| 7627 | |
| 7628 | struct ec_response_fp_stats { |
| 7629 | uint32_t capture_time_us; |
| 7630 | uint32_t matching_time_us; |
| 7631 | uint32_t overall_time_us; |
| 7632 | struct { |
| 7633 | uint32_t lo; |
| 7634 | uint32_t hi; |
| 7635 | } overall_t0; |
| 7636 | uint8_t timestamps_invalid; |
| 7637 | int8_t template_matched; |
| 7638 | } __ec_align2; |
| 7639 | |
| 7640 | #define EC_CMD_FP_SEED 0x0408 |
| 7641 | struct ec_params_fp_seed { |
| 7642 | /* |
| 7643 | * Version of the structure format (N=3). |
| 7644 | */ |
| 7645 | uint16_t struct_version; |
| 7646 | /* Reserved bytes, set to 0. */ |
| 7647 | uint16_t reserved; |
| 7648 | /* Seed from the TPM. */ |
| 7649 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 7650 | } __ec_align4; |
| 7651 | |
| 7652 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 7653 | |
| 7654 | /* FP TPM seed has been set or not */ |
| 7655 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 7656 | |
| 7657 | struct ec_response_fp_encryption_status { |
| 7658 | /* Used bits in encryption engine status */ |
| 7659 | uint32_t valid_flags; |
| 7660 | /* Encryption engine status */ |
| 7661 | uint32_t status; |
| 7662 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7663 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 7664 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 7665 | struct ec_params_fp_read_match_secret { |
| 7666 | uint16_t fgr; |
| 7667 | } __ec_align4; |
| 7668 | |
| 7669 | /* The positive match secret has the length of the SHA256 digest. */ |
| 7670 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 7671 | struct ec_response_fp_read_match_secret { |
| 7672 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 7673 | } __ec_align4; |
| 7674 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7675 | /*****************************************************************************/ |
| 7676 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 7677 | |
| 7678 | /* Perform touchpad self test */ |
| 7679 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 7680 | |
| 7681 | /* Get number of frame types, and the size of each type */ |
| 7682 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 7683 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7684 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7685 | uint32_t n_frames; |
| 7686 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7687 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7688 | |
| 7689 | /* Create a snapshot of current frame readings */ |
| 7690 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 7691 | |
| 7692 | /* Read the frame */ |
| 7693 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 7694 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7695 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7696 | uint32_t frame_index; |
| 7697 | uint32_t offset; |
| 7698 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7699 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7700 | |
| 7701 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7702 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 7703 | |
| 7704 | #define EC_COMM_TEXT_MAX 8 |
| 7705 | |
| 7706 | /* |
| 7707 | * Get battery static information, i.e. information that never changes, or |
| 7708 | * very infrequently. |
| 7709 | */ |
| 7710 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 7711 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7712 | /** |
| 7713 | * struct ec_params_battery_static_info - Battery static info parameters |
| 7714 | * @index: Battery index. |
| 7715 | */ |
| 7716 | struct ec_params_battery_static_info { |
| 7717 | uint8_t index; |
| 7718 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7719 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7720 | /** |
| 7721 | * struct ec_response_battery_static_info - Battery static info response |
| 7722 | * @design_capacity: Battery Design Capacity (mAh) |
| 7723 | * @design_voltage: Battery Design Voltage (mV) |
| 7724 | * @manufacturer: Battery Manufacturer String |
| 7725 | * @model: Battery Model Number String |
| 7726 | * @serial: Battery Serial Number String |
| 7727 | * @type: Battery Type String |
| 7728 | * @cycle_count: Battery Cycle Count |
| 7729 | */ |
| 7730 | struct ec_response_battery_static_info { |
| 7731 | uint16_t design_capacity; |
| 7732 | uint16_t design_voltage; |
| 7733 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 7734 | char model[EC_COMM_TEXT_MAX]; |
| 7735 | char serial[EC_COMM_TEXT_MAX]; |
| 7736 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7737 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7738 | uint32_t cycle_count; |
| 7739 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7740 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7741 | /** |
| 7742 | * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info |
| 7743 | * Equivalent to struct ec_response_battery_static_info, but with longer |
| 7744 | * strings. |
| 7745 | * @design_capacity: battery design capacity (in mAh) |
| 7746 | * @design_voltage: battery design voltage (in mV) |
| 7747 | * @cycle_count: battery cycle count |
| 7748 | * @manufacturer_ext: battery manufacturer string |
| 7749 | * @model_ext: battery model string |
| 7750 | * @serial_ext: battery serial number string |
| 7751 | * @type_ext: battery type string |
| 7752 | */ |
| 7753 | struct ec_response_battery_static_info_v1 { |
| 7754 | uint16_t design_capacity; |
| 7755 | uint16_t design_voltage; |
| 7756 | uint32_t cycle_count; |
| 7757 | char manufacturer_ext[12]; |
| 7758 | char model_ext[12]; |
| 7759 | char serial_ext[12]; |
| 7760 | char type_ext[12]; |
| 7761 | } __ec_align4; |
| 7762 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7763 | /** |
| 7764 | * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info |
| 7765 | * |
| 7766 | * Equivalent to struct ec_response_battery_static_info, but with strings |
| 7767 | * further lengthened (relative to v1) to accommodate the maximum string length |
| 7768 | * permitted by the Smart Battery Data Specification revision 1.1 and fields |
| 7769 | * renamed to better match that specification. |
| 7770 | * |
| 7771 | * @design_capacity: battery design capacity (in mAh) |
| 7772 | * @design_voltage: battery design voltage (in mV) |
| 7773 | * @cycle_count: battery cycle count |
| 7774 | * @manufacturer: battery manufacturer string |
| 7775 | * @device_name: battery model string |
| 7776 | * @serial: battery serial number string |
| 7777 | * @chemistry: battery type string |
| 7778 | */ |
| 7779 | struct ec_response_battery_static_info_v2 { |
| 7780 | uint16_t design_capacity; |
| 7781 | uint16_t design_voltage; |
| 7782 | uint32_t cycle_count; |
| 7783 | char manufacturer[32]; |
| 7784 | char device_name[32]; |
| 7785 | char serial[32]; |
| 7786 | char chemistry[32]; |
| 7787 | } __ec_align4; |
| 7788 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7789 | /* |
| 7790 | * Get battery dynamic information, i.e. information that is likely to change |
| 7791 | * every time it is read. |
| 7792 | */ |
| 7793 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 7794 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7795 | /** |
| 7796 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 7797 | * @index: Battery index. |
| 7798 | */ |
| 7799 | struct ec_params_battery_dynamic_info { |
| 7800 | uint8_t index; |
| 7801 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7802 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7803 | /** |
| 7804 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 7805 | * @actual_voltage: Battery voltage (mV) |
| 7806 | * @actual_current: Battery current (mA); negative=discharging |
| 7807 | * @remaining_capacity: Remaining capacity (mAh) |
| 7808 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 7809 | * @flags: Flags, see EC_BATT_FLAG_* |
| 7810 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 7811 | * @desired_current: Charging current desired by battery (mA) |
| 7812 | */ |
| 7813 | struct ec_response_battery_dynamic_info { |
| 7814 | int16_t actual_voltage; |
| 7815 | int16_t actual_current; |
| 7816 | int16_t remaining_capacity; |
| 7817 | int16_t full_capacity; |
| 7818 | int16_t flags; |
| 7819 | int16_t desired_voltage; |
| 7820 | int16_t desired_current; |
| 7821 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7822 | |
| 7823 | /* |
Rob Barnes | 8bc5fa9 | 2021-06-28 09:32:28 -0600 | [diff] [blame] | 7824 | * Control charger chip. Used to control charger chip on the peripheral. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7825 | */ |
| 7826 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 7827 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7828 | /** |
| 7829 | * struct ec_params_charger_control - Charger control parameters |
| 7830 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 7831 | * max_current and (possibly) charge battery, negative to request current |
| 7832 | * from base (OTG). |
| 7833 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 7834 | * >= 0. |
| 7835 | * @allow_charging: Allow base battery charging (only makes sense if |
| 7836 | * max_current > 0). |
| 7837 | */ |
| 7838 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7839 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7840 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7841 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7842 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7843 | |
Yu-Ping Wu | 9ff7823 | 2021-01-06 18:13:36 +0800 | [diff] [blame] | 7844 | /* Get ACK from the USB-C SS muxes */ |
| 7845 | #define EC_CMD_USB_PD_MUX_ACK 0x0603 |
| 7846 | |
| 7847 | struct ec_params_usb_pd_mux_ack { |
| 7848 | uint8_t port; /* USB-C port number */ |
| 7849 | } __ec_align1; |
| 7850 | |
Caveh Jalali | 6bd733b | 2023-01-30 17:06:31 -0800 | [diff] [blame^] | 7851 | /* Get boot time */ |
| 7852 | #define EC_CMD_GET_BOOT_TIME 0x0604 |
| 7853 | |
| 7854 | enum boot_time_param { |
| 7855 | ARAIL = 0, |
| 7856 | RSMRST, |
| 7857 | ESPIRST, |
| 7858 | PLTRST_LOW, |
| 7859 | PLTRST_HIGH, |
| 7860 | EC_CUR_TIME, |
| 7861 | RESET_CNT, |
| 7862 | }; |
| 7863 | |
| 7864 | struct ec_response_get_boot_time { |
| 7865 | uint64_t timestamp[RESET_CNT]; |
| 7866 | uint16_t cnt; |
| 7867 | } __ec_align4; |
| 7868 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 7869 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7870 | /* |
| 7871 | * Reserve a range of host commands for board-specific, experimental, or |
| 7872 | * special purpose features. These can be (re)used without updating this file. |
| 7873 | * |
| 7874 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 7875 | * their EC commands for easier development, testing, debugging, and support. |
| 7876 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7877 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 7878 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 7879 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7880 | * In your experimental code, you may want to do something like this: |
| 7881 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7882 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 7883 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 7884 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 7885 | * |
| 7886 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 7887 | * EC_VER_MASK(0); |
| 7888 | * |
| 7889 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 7890 | * EC_VER_MASK(0); |
| 7891 | * |
| 7892 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 7893 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 7894 | */ |
| 7895 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 7896 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 7897 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7898 | /* |
| 7899 | * Given the private host command offset, calculate the true private host |
| 7900 | * command value. |
| 7901 | */ |
| 7902 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 7903 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 7904 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7905 | /*****************************************************************************/ |
| 7906 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 7907 | * Passthru commands |
| 7908 | * |
| 7909 | * Some platforms have sub-processors chained to each other. For example. |
| 7910 | * |
| 7911 | * AP <--> EC <--> PD MCU |
| 7912 | * |
| 7913 | * The top 2 bits of the command number are used to indicate which device the |
| 7914 | * command is intended for. Device 0 is always the device receiving the |
| 7915 | * command; other device mapping is board-specific. |
| 7916 | * |
| 7917 | * When a device receives a command to be passed to a sub-processor, it passes |
| 7918 | * it on with the device number set back to 0. This allows the sub-processor |
| 7919 | * to remain blissfully unaware of whether the command originated on the next |
| 7920 | * device up the chain, or was passed through from the AP. |
| 7921 | * |
| 7922 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 7923 | * AP sends command 0x4002 to the EC |
| 7924 | * EC sends command 0x0002 to the PD MCU |
| 7925 | * EC forwards PD MCU response back to the AP |
| 7926 | */ |
| 7927 | |
| 7928 | /* Offset and max command number for sub-device n */ |
| 7929 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 7930 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 7931 | |
| 7932 | /*****************************************************************************/ |
| 7933 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7934 | * Deprecated constants. These constants have been renamed for clarity. The |
| 7935 | * meaning and size has not changed. Programs that use the old names should |
| 7936 | * switch to the new names soon, as the old names may not be carried forward |
| 7937 | * forever. |
| 7938 | */ |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7939 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 7940 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 7941 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 7942 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7943 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 7944 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 7945 | #ifdef __cplusplus |
| 7946 | } |
| 7947 | #endif |
| 7948 | |
Caveh Jalali | 024ffe3 | 2023-01-30 14:35:19 -0800 | [diff] [blame] | 7949 | #endif /* __CROS_EC_EC_COMMANDS_H */ |