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 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 16 | #ifdef CHROMIUM_EC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 17 | /* |
| 18 | * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository. |
| 19 | * It is used to not include macros that may cause conflicts in foreign |
| 20 | * projects (refer to crbug.com/984623). |
| 21 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 22 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This |
| 25 | * generates more efficient code for accessing request/response structures on |
| 26 | * ARM Cortex-M if the structures are guaranteed 32-bit aligned. |
| 27 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 28 | #include "common.h" |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 29 | #include "compile_time_macros.h" |
| 30 | |
| 31 | #else |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 32 | #define BUILD_ASSERT(_cond) |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 33 | #endif /* CHROMIUM_EC */ |
| 34 | |
| 35 | #ifdef __KERNEL__ |
| 36 | #include <linux/limits.h> |
| 37 | #else |
| 38 | /* |
| 39 | * Defines macros that may be needed but are for sure defined by the linux |
| 40 | * kernel. This section is removed when cros_ec_commands.h is generated (by |
| 41 | * util/make_linux_ec_commands_h.sh). |
| 42 | * cros_ec_commands.h looks more integrated to the kernel. |
| 43 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 44 | |
| 45 | #ifndef BIT |
| 46 | #define BIT(nr) (1UL << (nr)) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 47 | #endif |
| 48 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 49 | #ifndef BIT_ULL |
| 50 | #define BIT_ULL(nr) (1ULL << (nr)) |
| 51 | #endif |
| 52 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 53 | #endif /* __KERNEL__ */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 54 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 55 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 56 | * Current version of this protocol |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 57 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 58 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 59 | * determined in other ways. Remove this once the kernel code no longer |
| 60 | * depends on it. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 61 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 62 | #define EC_PROTO_VERSION 0x00000002 |
| 63 | |
| 64 | /* Command version mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 65 | #define EC_VER_MASK(version) BIT(version) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 66 | |
| 67 | /* I/O addresses for ACPI commands */ |
| 68 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 69 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
| 70 | |
| 71 | /* I/O addresses for host command */ |
| 72 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 73 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
| 74 | |
| 75 | /* I/O addresses for host command args and params */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 76 | /* Protocol version 2 */ |
| 77 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
| 78 | #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 79 | * EC_PROTO2_MAX_PARAM_SIZE |
| 80 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 81 | /* Protocol version 3 */ |
| 82 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 83 | #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] | 84 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 85 | /* |
| 86 | * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 87 | * and they tell the kernel that so we have to think of it as two parts. |
| 88 | */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 89 | #define EC_HOST_CMD_REGION0 0x800 |
| 90 | #define EC_HOST_CMD_REGION1 0x880 |
| 91 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
| 92 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 93 | /* EC command register bit functions */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 94 | #define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */ |
| 95 | #define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */ |
| 96 | #define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */ |
| 97 | #define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */ |
| 98 | #define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */ |
| 99 | #define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */ |
| 100 | #define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 101 | |
| 102 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 103 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 104 | #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ |
| 105 | |
| 106 | /* The offset address of each type of data in mapped memory. */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 107 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 108 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 109 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 110 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 111 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 112 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 113 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
| 114 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
| 115 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 116 | #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ |
| 117 | /* Unused 0x28 - 0x2f */ |
| 118 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
| 119 | /* Unused 0x31 - 0x33 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 120 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */ |
| 121 | /* Battery values are all 32 bits, unless otherwise noted. */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 122 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 123 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 124 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 125 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */ |
| 126 | #define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */ |
| 127 | #define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */ |
| 128 | /* Unused 0x4f */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 129 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 130 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 131 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 132 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 133 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 134 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 135 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 136 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 137 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 138 | #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ |
| 139 | /* Unused 0x84 - 0x8f */ |
| 140 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
| 141 | /* Unused 0x91 */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 142 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */ |
| 143 | /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */ |
| 144 | /* 0x94 - 0x99: 1st Accelerometer */ |
| 145 | /* 0x9a - 0x9f: 2nd Accelerometer */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 146 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 147 | /* Unused 0xa6 - 0xdf */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 148 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 149 | /* |
| 150 | * ACPI is unable to access memory mapped data at or above this offset due to |
| 151 | * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe |
| 152 | * which might be needed by ACPI. |
| 153 | */ |
| 154 | #define EC_MEMMAP_NO_ACPI 0xe0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 155 | |
| 156 | /* Define the format of the accelerometer mapped memory status byte. */ |
| 157 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 158 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4) |
| 159 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 160 | |
| 161 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
| 162 | #define EC_TEMP_SENSOR_ENTRIES 16 |
| 163 | /* |
| 164 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 165 | * |
| 166 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 167 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 168 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 169 | |
| 170 | /* Special values for mapped temperature sensors */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 171 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 172 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 173 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
| 174 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 175 | /* |
| 176 | * The offset of temperature value stored in mapped memory. This allows |
| 177 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 178 | */ |
| 179 | #define EC_TEMP_SENSOR_OFFSET 200 |
| 180 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 181 | /* |
| 182 | * Number of ALS readings at EC_MEMMAP_ALS |
| 183 | */ |
| 184 | #define EC_ALS_ENTRIES 2 |
| 185 | |
| 186 | /* |
| 187 | * The default value a temperature sensor will return when it is present but |
| 188 | * has not been read this boot. This is a reasonable number to avoid |
| 189 | * triggering alarms on the host. |
| 190 | */ |
| 191 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
| 192 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 193 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 194 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
| 195 | #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ |
| 196 | |
| 197 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
| 198 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
| 199 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
| 200 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 201 | #define EC_BATT_FLAG_CHARGING 0x08 |
| 202 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 203 | /* Set if some of the static/dynamic data is invalid (or outdated). */ |
| 204 | #define EC_BATT_FLAG_INVALID_DATA 0x20 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 205 | |
| 206 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
| 207 | #define EC_SWITCH_LID_OPEN 0x01 |
| 208 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
| 209 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 210 | /* Was recovery requested via keyboard; now unused. */ |
| 211 | #define EC_SWITCH_IGNORE1 0x08 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 212 | /* Recovery requested via dedicated signal (from servo board) */ |
| 213 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
| 214 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
| 215 | #define EC_SWITCH_IGNORE0 0x20 |
| 216 | |
| 217 | /* Host command interface flags */ |
| 218 | /* Host command interface supports LPC args (LPC interface only) */ |
| 219 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 220 | /* Host command interface supports version 3 protocol */ |
| 221 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 222 | |
| 223 | /* Wireless switch flags */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 224 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 225 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 226 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 227 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 228 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 229 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 230 | /*****************************************************************************/ |
| 231 | /* |
| 232 | * ACPI commands |
| 233 | * |
| 234 | * These are valid ONLY on the ACPI command/data port. |
| 235 | */ |
| 236 | |
| 237 | /* |
| 238 | * ACPI Read Embedded Controller |
| 239 | * |
| 240 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 241 | * |
| 242 | * Use the following sequence: |
| 243 | * |
| 244 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 245 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 246 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 247 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 248 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 249 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 250 | #define EC_CMD_ACPI_READ 0x0080 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 251 | |
| 252 | /* |
| 253 | * ACPI Write Embedded Controller |
| 254 | * |
| 255 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 256 | * |
| 257 | * Use the following sequence: |
| 258 | * |
| 259 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 260 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 261 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 262 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 263 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 264 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 265 | #define EC_CMD_ACPI_WRITE 0x0081 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 266 | |
| 267 | /* |
| 268 | * ACPI Burst Enable Embedded Controller |
| 269 | * |
| 270 | * This enables burst mode on the EC to allow the host to issue several |
| 271 | * commands back-to-back. While in this mode, writes to mapped multi-byte |
| 272 | * data are locked out to ensure data consistency. |
| 273 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 274 | #define EC_CMD_ACPI_BURST_ENABLE 0x0082 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * ACPI Burst Disable Embedded Controller |
| 278 | * |
| 279 | * This disables burst mode on the EC and stops preventing EC writes to mapped |
| 280 | * multi-byte data. |
| 281 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 282 | #define EC_CMD_ACPI_BURST_DISABLE 0x0083 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 283 | |
| 284 | /* |
| 285 | * ACPI Query Embedded Controller |
| 286 | * |
| 287 | * This clears the lowest-order bit in the currently pending host events, and |
| 288 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 289 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 290 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 291 | #define EC_CMD_ACPI_QUERY_EVENT 0x0084 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 292 | |
| 293 | /* Valid addresses in ACPI memory space, for read/write commands */ |
| 294 | |
| 295 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
| 296 | #define EC_ACPI_MEM_VERSION 0x00 |
| 297 | /* |
| 298 | * Test location; writing value here updates test compliment byte to (0xff - |
| 299 | * value). |
| 300 | */ |
| 301 | #define EC_ACPI_MEM_TEST 0x01 |
| 302 | /* Test compliment; writes here are ignored. */ |
| 303 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
| 304 | |
| 305 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 306 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
| 307 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
| 308 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
| 309 | |
| 310 | /* |
| 311 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 312 | * independent thresholds attached to them. The current value of the ID |
| 313 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 314 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 315 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 316 | * |
| 317 | * The spec does not mandate any way to read back the threshold settings |
| 318 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 319 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 320 | * returns one sensor ID that has crossed one of its threshold (in either |
| 321 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 322 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 323 | * the unread event count for that sensor. |
| 324 | */ |
| 325 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 326 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 327 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
| 328 | /* |
| 329 | * Here are the bits for the COMMIT register: |
| 330 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 331 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 332 | * Each write to the commit register affects one threshold. |
| 333 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 334 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0) |
| 335 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 336 | /* |
| 337 | * Example: |
| 338 | * |
| 339 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 340 | * write 2 to [0x05] -- select temp sensor 2 |
| 341 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 342 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 343 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 344 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 345 | * |
| 346 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 347 | * write 2 to [0x05] -- select temp sensor 2 |
| 348 | * write 0x1 to [0x07] -- disable threshold 1 |
| 349 | */ |
| 350 | |
| 351 | /* DPTF battery charging current limit */ |
| 352 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
| 353 | |
| 354 | /* Charging limit is specified in 64 mA steps */ |
| 355 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
| 356 | /* Value to disable DPTF battery charging limit */ |
| 357 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 358 | |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 359 | /* |
| 360 | * Report device orientation |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 361 | * Bits Definition |
| 362 | * 3:1 Device DPTF Profile Number (DDPN) |
| 363 | * 0 = Reserved for backward compatibility (indicates no valid |
| 364 | * profile number. Host should fall back to using TBMD). |
| 365 | * 1..7 = DPTF Profile number to indicate to host which table needs |
| 366 | * to be loaded. |
| 367 | * 0 Tablet Mode Device Indicator (TBMD) |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 368 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 369 | #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 370 | #define EC_ACPI_MEM_TBMD_SHIFT 0 |
| 371 | #define EC_ACPI_MEM_TBMD_MASK 0x1 |
| 372 | #define EC_ACPI_MEM_DDPN_SHIFT 1 |
| 373 | #define EC_ACPI_MEM_DDPN_MASK 0x7 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 374 | |
| 375 | /* |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 376 | * Report device features. Uses the same format as the host command, except: |
| 377 | * |
| 378 | * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set |
| 379 | * of features", which is of limited interest when the system is already |
| 380 | * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since |
| 381 | * these are supported, it defaults to 0. |
| 382 | * This allows detecting the presence of this field since older versions of |
| 383 | * the EC codebase would simply return 0xff to that unknown address. Check |
| 384 | * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits |
| 385 | * are valid. |
| 386 | */ |
| 387 | #define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a |
| 388 | #define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b |
| 389 | #define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c |
| 390 | #define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d |
| 391 | #define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e |
| 392 | #define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f |
| 393 | #define EC_ACPI_MEM_DEVICE_FEATURES6 0x10 |
| 394 | #define EC_ACPI_MEM_DEVICE_FEATURES7 0x11 |
| 395 | |
| 396 | #define EC_ACPI_MEM_BATTERY_INDEX 0x12 |
| 397 | |
| 398 | /* |
| 399 | * USB Port Power. Each bit indicates whether the corresponding USB ports' power |
| 400 | * is enabled (1) or disabled (0). |
| 401 | * bit 0 USB port ID 0 |
| 402 | * ... |
| 403 | * bit 7 USB port ID 7 |
| 404 | */ |
| 405 | #define EC_ACPI_MEM_USB_PORT_POWER 0x13 |
| 406 | |
| 407 | /* |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 408 | * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data |
| 409 | * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2. |
| 410 | */ |
| 411 | #define EC_ACPI_MEM_MAPPED_BEGIN 0x20 |
| 412 | #define EC_ACPI_MEM_MAPPED_SIZE 0xe0 |
| 413 | |
| 414 | /* Current version of ACPI memory address space */ |
| 415 | #define EC_ACPI_MEM_VERSION_CURRENT 2 |
| 416 | |
| 417 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 418 | /* |
| 419 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 420 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 421 | * handle actual C code so keep it separate. |
| 422 | */ |
| 423 | #ifndef __ACPI__ |
| 424 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 425 | #ifndef __KERNEL__ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 426 | /* |
| 427 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 428 | * checking prefers __packed over __attribute__((packed)). |
| 429 | */ |
| 430 | #ifndef __packed |
| 431 | #define __packed __attribute__((packed)) |
| 432 | #endif |
| 433 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 434 | #ifndef __aligned |
| 435 | #define __aligned(x) __attribute__((aligned(x))) |
| 436 | #endif |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 437 | #endif /* __KERNEL__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 438 | |
| 439 | /* |
| 440 | * Attributes for EC request and response packets. Just defining __packed |
| 441 | * results in inefficient assembly code on ARM, if the structure is actually |
| 442 | * 32-bit aligned, as it should be for all buffers. |
| 443 | * |
| 444 | * Be very careful when adding these to existing structures. They will round |
| 445 | * up the structure size to the specified boundary. |
| 446 | * |
| 447 | * Also be very careful to make that if a structure is included in some other |
| 448 | * parent structure that the alignment will still be true given the packing of |
| 449 | * the parent structure. This is particularly important if the sub-structure |
| 450 | * 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] | 451 | * not know about the misalignment caused by the parent structure's packing. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 452 | * |
| 453 | * Also be very careful using __packed - particularly when nesting non-packed |
| 454 | * structures inside packed ones. In fact, DO NOT use __packed directly; |
| 455 | * always use one of these attributes. |
| 456 | * |
| 457 | * Once everything is annotated properly, the following search strings should |
| 458 | * not return ANY matches in this file other than right here: |
| 459 | * |
| 460 | * "__packed" - generates inefficient code; all sub-structs must also be packed |
| 461 | * |
| 462 | * "struct [^_]" - all structs should be annotated, except for structs that are |
| 463 | * members of other structs/unions (and their original declarations should be |
| 464 | * annotated). |
| 465 | */ |
| 466 | #ifdef CONFIG_HOSTCMD_ALIGNED |
| 467 | |
| 468 | /* |
| 469 | * Packed structures where offset and size are always aligned to 1, 2, or 4 |
| 470 | * byte boundary. |
| 471 | */ |
| 472 | #define __ec_align1 __packed |
| 473 | #define __ec_align2 __packed __aligned(2) |
| 474 | #define __ec_align4 __packed __aligned(4) |
| 475 | |
| 476 | /* |
| 477 | * Packed structure which must be under-aligned, because its size is not a |
| 478 | * 4-byte multiple. This is sub-optimal because it forces byte-wise access |
| 479 | * of all multi-byte fields in it, even though they are themselves aligned. |
| 480 | * |
| 481 | * In theory, we could duplicate the structure with __aligned(4) for accessing |
| 482 | * its members, but use the __packed version for sizeof(). |
| 483 | */ |
| 484 | #define __ec_align_size1 __packed |
| 485 | |
| 486 | /* |
| 487 | * Packed structure which must be under-aligned, because its offset inside a |
| 488 | * parent structure is not a 4-byte multiple. |
| 489 | */ |
| 490 | #define __ec_align_offset1 __packed |
| 491 | #define __ec_align_offset2 __packed __aligned(2) |
| 492 | |
| 493 | /* |
| 494 | * Structures which are complicated enough that I'm skipping them on the first |
| 495 | * pass. They are effectively unchanged from their previous definitions. |
| 496 | * |
| 497 | * TODO(rspangler): Figure out what to do with these. It's likely necessary |
| 498 | * to work out the size and offset of each member and add explicit padding to |
| 499 | * maintain those. |
| 500 | */ |
| 501 | #define __ec_todo_packed __packed |
| 502 | #define __ec_todo_unpacked |
| 503 | |
| 504 | #else /* !CONFIG_HOSTCMD_ALIGNED */ |
| 505 | |
| 506 | /* |
| 507 | * Packed structures make no assumption about alignment, so they do inefficient |
| 508 | * byte-wise reads. |
| 509 | */ |
| 510 | #define __ec_align1 __packed |
| 511 | #define __ec_align2 __packed |
| 512 | #define __ec_align4 __packed |
| 513 | #define __ec_align_size1 __packed |
| 514 | #define __ec_align_offset1 __packed |
| 515 | #define __ec_align_offset2 __packed |
| 516 | #define __ec_todo_packed __packed |
| 517 | #define __ec_todo_unpacked |
| 518 | |
| 519 | #endif /* !CONFIG_HOSTCMD_ALIGNED */ |
| 520 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 521 | /* LPC command status byte masks */ |
| 522 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 523 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 524 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 525 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 526 | /* EC is processing a command */ |
| 527 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 528 | /* Last write to EC was a command, not data */ |
| 529 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 530 | /* EC is in burst mode */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 531 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 532 | /* SCI event is pending (requesting SCI query) */ |
| 533 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 534 | /* SMI event is pending (requesting SMI query) */ |
| 535 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 536 | /* (reserved) */ |
| 537 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 538 | |
| 539 | /* |
| 540 | * EC is busy. This covers both the EC processing a command, and the host has |
| 541 | * written a new command but the EC hasn't picked it up yet. |
| 542 | */ |
| 543 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 544 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 545 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 546 | /* |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 547 | * Host command response codes (16-bit). |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 548 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 549 | enum ec_status { |
| 550 | EC_RES_SUCCESS = 0, |
| 551 | EC_RES_INVALID_COMMAND = 1, |
| 552 | EC_RES_ERROR = 2, |
| 553 | EC_RES_INVALID_PARAM = 3, |
| 554 | EC_RES_ACCESS_DENIED = 4, |
| 555 | EC_RES_INVALID_RESPONSE = 5, |
| 556 | EC_RES_INVALID_VERSION = 6, |
| 557 | EC_RES_INVALID_CHECKSUM = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 558 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 559 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 560 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 561 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 562 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 563 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 564 | EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 565 | EC_RES_BUS_ERROR = 15, /* Communications bus error */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 566 | EC_RES_BUSY = 16, /* Up but too busy. Should retry */ |
| 567 | EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */ |
| 568 | EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */ |
| 569 | EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */ |
| 570 | EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 571 | |
| 572 | EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */ |
| 573 | } __packed; |
| 574 | BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t)); |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 575 | |
| 576 | /* |
| 577 | * Host event codes. Note these are 1-based, not 0-based, because ACPI query |
| 578 | * EC command uses code 0 to mean "no event pending". We explicitly specify |
| 579 | * each value in the enum listing so they won't change if we delete/insert an |
| 580 | * item or rearrange the list (it needs to be stable across platforms, not |
| 581 | * just within a single compiled instance). |
| 582 | */ |
| 583 | enum host_event_code { |
| 584 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 585 | EC_HOST_EVENT_LID_OPEN = 2, |
| 586 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 587 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 588 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 589 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 590 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 591 | EC_HOST_EVENT_BATTERY = 8, |
| 592 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 593 | /* Event generated by a device attached to the EC */ |
| 594 | EC_HOST_EVENT_DEVICE = 10, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 595 | EC_HOST_EVENT_THERMAL = 11, |
| 596 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 597 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 598 | /* |
| 599 | * EC has finished initializing the host interface. The host can check |
| 600 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 601 | * determine when the EC is ready to accept subsequent commands. |
| 602 | */ |
| 603 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 604 | /* Keyboard recovery combo has been pressed */ |
| 605 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 606 | |
| 607 | /* Shutdown due to thermal overload */ |
| 608 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 609 | /* Shutdown due to battery level too low */ |
| 610 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 611 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 612 | /* Suggest that the AP throttle itself */ |
| 613 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 614 | /* Suggest that the AP resume normal speed */ |
| 615 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
Duncan Laurie | d338b46 | 2013-07-31 15:30:41 -0700 | [diff] [blame] | 616 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 617 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 618 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 619 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 620 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 621 | |
| 622 | /* PD MCU triggering host event */ |
Shawn Nematbakhsh | 98cc94c | 2014-08-28 11:33:41 -0700 | [diff] [blame] | 623 | EC_HOST_EVENT_PD_MCU = 22, |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 624 | |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 625 | /* Battery Status flags have changed */ |
| 626 | EC_HOST_EVENT_BATTERY_STATUS = 23, |
| 627 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 628 | /* EC encountered a panic, triggering a reset */ |
Shawn Nematbakhsh | 555f711 | 2015-02-23 15:14:54 -0800 | [diff] [blame] | 629 | EC_HOST_EVENT_PANIC = 24, |
| 630 | |
Furquan Shaikh | 066cc85 | 2015-06-20 15:53:03 -0700 | [diff] [blame] | 631 | /* Keyboard fastboot combo has been pressed */ |
| 632 | EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25, |
| 633 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 634 | /* EC RTC event occurred */ |
| 635 | EC_HOST_EVENT_RTC = 26, |
| 636 | |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 637 | /* Emulate MKBP event */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 638 | EC_HOST_EVENT_MKBP = 27, |
Gwendal Grignou | 95b7a6c | 2016-05-03 23:53:23 -0700 | [diff] [blame] | 639 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 640 | /* EC desires to change state of host-controlled USB mux */ |
| 641 | EC_HOST_EVENT_USB_MUX = 28, |
| 642 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 643 | /* |
| 644 | * The device has changed "modes". This can be one of the following: |
| 645 | * |
| 646 | * - TABLET/LAPTOP mode |
| 647 | * - detachable base attach/detach event |
| 648 | */ |
jiazi Yang | 51fc93f | 2016-07-28 05:15:01 -0400 | [diff] [blame] | 649 | EC_HOST_EVENT_MODE_CHANGE = 29, |
| 650 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 651 | /* Keyboard recovery combo with hardware reinitialization */ |
| 652 | EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30, |
| 653 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 654 | /* WoV */ |
| 655 | EC_HOST_EVENT_WOV = 31, |
| 656 | |
Furquan Shaikh | 2afc4e7 | 2016-11-06 00:12:23 -0700 | [diff] [blame] | 657 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 658 | * The high bit of the event mask is not used as a host event code. If |
| 659 | * it reads back as set, then the entire event mask should be |
| 660 | * considered invalid by the host. This can happen when reading the |
| 661 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 662 | * not initialized on the EC, or improperly configured on the host. |
| 663 | */ |
| 664 | EC_HOST_EVENT_INVALID = 32 |
| 665 | }; |
| 666 | /* Host event mask */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 667 | #define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 668 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 669 | /** |
| 670 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 671 | * @flags: The host argument flags. |
| 672 | * @command_version: Command version. |
| 673 | * @data_size: The length of data. |
| 674 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 675 | * all params/response data bytes. |
| 676 | */ |
| 677 | struct ec_lpc_host_args { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 678 | uint8_t flags; |
| 679 | uint8_t command_version; |
| 680 | uint8_t data_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 681 | uint8_t checksum; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 682 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 683 | |
| 684 | /* Flags for ec_lpc_host_args.flags */ |
| 685 | /* |
| 686 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 687 | * params. |
| 688 | * |
| 689 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 690 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 691 | * unknown length. EC must respond with an old-style response (that is, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 692 | * without setting EC_HOST_ARGS_FLAG_TO_HOST). |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 693 | */ |
| 694 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 695 | /* |
| 696 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 697 | * |
| 698 | * If EC responds to a command and this flag is not set, this is an old-style |
| 699 | * response. Command version is 0 and response data from EC is at |
| 700 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 701 | */ |
| 702 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 703 | |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 704 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 705 | /* |
| 706 | * Byte codes returned by EC over SPI interface. |
| 707 | * |
| 708 | * These can be used by the AP to debug the EC interface, and to determine |
| 709 | * when the EC is not in a state where it will ever get around to responding |
| 710 | * to the AP. |
| 711 | * |
| 712 | * Example of sequence of bytes read from EC for a current good transfer: |
| 713 | * 1. - - AP asserts chip select (CS#) |
| 714 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 715 | * 3. - - EC starts handling CS# interrupt |
| 716 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 717 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 718 | * bytes looking for EC_SPI_FRAME_START |
| 719 | * 6. - - EC finishes processing and sets up response |
| 720 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 721 | * 8. (response packet) - AP reads response packet |
| 722 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 723 | * 10 - - AP deasserts chip select |
| 724 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 725 | * next request |
| 726 | * |
| 727 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 728 | * the following byte values: |
| 729 | * EC_SPI_OLD_READY |
| 730 | * EC_SPI_RX_READY |
| 731 | * EC_SPI_RECEIVING |
| 732 | * EC_SPI_PROCESSING |
| 733 | * |
| 734 | * Then the EC found an error in the request, or was not ready for the request |
| 735 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 736 | * because the EC is unable to tell when the AP is done sending its request. |
| 737 | */ |
| 738 | |
| 739 | /* |
| 740 | * Framing byte which precedes a response packet from the EC. After sending a |
| 741 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 742 | * clock in the response packet. |
| 743 | */ |
| 744 | #define EC_SPI_FRAME_START 0xec |
| 745 | |
| 746 | /* |
| 747 | * Padding bytes which are clocked out after the end of a response packet. |
| 748 | */ |
| 749 | #define EC_SPI_PAST_END 0xed |
| 750 | |
| 751 | /* |
| 752 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 753 | * that the AP will send a valid packet header (starting with |
| 754 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 755 | */ |
| 756 | #define EC_SPI_RX_READY 0xf8 |
| 757 | |
| 758 | /* |
| 759 | * EC has started receiving the request from the AP, but hasn't started |
| 760 | * processing it yet. |
| 761 | */ |
| 762 | #define EC_SPI_RECEIVING 0xf9 |
| 763 | |
| 764 | /* EC has received the entire request from the AP and is processing it. */ |
| 765 | #define EC_SPI_PROCESSING 0xfa |
| 766 | |
| 767 | /* |
| 768 | * EC received bad data from the AP, such as a packet header with an invalid |
| 769 | * length. EC will ignore all data until chip select deasserts. |
| 770 | */ |
| 771 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 772 | |
| 773 | /* |
| 774 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 775 | * chip select and started clocking data before the EC was ready to receive it. |
| 776 | * EC will ignore all data until chip select deasserts. |
| 777 | */ |
| 778 | #define EC_SPI_NOT_READY 0xfc |
| 779 | |
| 780 | /* |
| 781 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 782 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 783 | * a fully received packet but is not ready to respond yet. |
| 784 | */ |
| 785 | #define EC_SPI_OLD_READY 0xfd |
| 786 | |
| 787 | /*****************************************************************************/ |
| 788 | |
| 789 | /* |
| 790 | * Protocol version 2 for I2C and SPI send a request this way: |
| 791 | * |
| 792 | * 0 EC_CMD_VERSION0 + (command version) |
| 793 | * 1 Command number |
| 794 | * 2 Length of params = N |
| 795 | * 3..N+2 Params, if any |
| 796 | * N+3 8-bit checksum of bytes 0..N+2 |
| 797 | * |
| 798 | * The corresponding response is: |
| 799 | * |
| 800 | * 0 Result code (EC_RES_*) |
| 801 | * 1 Length of params = M |
| 802 | * 2..M+1 Params, if any |
| 803 | * M+2 8-bit checksum of bytes 0..M+1 |
| 804 | */ |
| 805 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 806 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 807 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 808 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 809 | |
| 810 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 811 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 812 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 813 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 814 | |
| 815 | /* Parameter length was limited by the LPC interface */ |
| 816 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 817 | |
| 818 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 819 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 820 | EC_PROTO2_MAX_PARAM_SIZE) |
| 821 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 822 | EC_PROTO2_MAX_PARAM_SIZE) |
| 823 | |
| 824 | /*****************************************************************************/ |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 825 | |
| 826 | /* |
| 827 | * Value written to legacy command port / prefix byte to indicate protocol |
| 828 | * 3+ structs are being used. Usage is bus-dependent. |
| 829 | */ |
| 830 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 831 | |
| 832 | #define EC_HOST_REQUEST_VERSION 3 |
| 833 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 834 | /** |
| 835 | * struct ec_host_request - Version 3 request from host. |
| 836 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 837 | * receives a header with a version it doesn't know how to |
| 838 | * parse. |
| 839 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 840 | * should total to 0. |
| 841 | * @command: Command to send (EC_CMD_...) |
| 842 | * @command_version: Command version. |
| 843 | * @reserved: Unused byte in current protocol version; set to 0. |
| 844 | * @data_len: Length of data which follows this header. |
| 845 | */ |
| 846 | struct ec_host_request { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 847 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 848 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 849 | uint16_t command; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 850 | uint8_t command_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 851 | uint8_t reserved; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 852 | uint16_t data_len; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 853 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 854 | |
| 855 | #define EC_HOST_RESPONSE_VERSION 3 |
| 856 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 857 | /** |
| 858 | * struct ec_host_response - Version 3 response from EC. |
| 859 | * @struct_version: Struct version (=3). |
| 860 | * @checksum: Checksum of response and data; sum of all bytes including |
| 861 | * checksum should total to 0. |
| 862 | * @result: EC's response to the command (separate from communication failure) |
| 863 | * @data_len: Length of data which follows this header. |
| 864 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 865 | */ |
| 866 | struct ec_host_response { |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 867 | uint8_t struct_version; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 868 | uint8_t checksum; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 869 | uint16_t result; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 870 | uint16_t data_len; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 871 | uint16_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 872 | } __ec_align4; |
Hung-Te Lin | ce7a5a7 | 2013-06-20 18:57:04 +0800 | [diff] [blame] | 873 | |
| 874 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 875 | |
| 876 | /* |
| 877 | * Host command protocol V4. |
| 878 | * |
| 879 | * Packets always start with a request or response header. They are followed |
| 880 | * by data_len bytes of data. If the data_crc_present flag is set, the data |
| 881 | * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1 |
| 882 | * polynomial. |
| 883 | * |
| 884 | * Host algorithm when sending a request q: |
| 885 | * |
| 886 | * 101) tries_left=(some value, e.g. 3); |
| 887 | * 102) q.seq_num++ |
| 888 | * 103) q.seq_dup=0 |
| 889 | * 104) Calculate q.header_crc. |
| 890 | * 105) Send request q to EC. |
| 891 | * 106) Wait for response r. Go to 201 if received or 301 if timeout. |
| 892 | * |
| 893 | * 201) If r.struct_version != 4, go to 301. |
| 894 | * 202) If r.header_crc mismatches calculated CRC for r header, go to 301. |
| 895 | * 203) If r.data_crc_present and r.data_crc mismatches, go to 301. |
| 896 | * 204) If r.seq_num != q.seq_num, go to 301. |
| 897 | * 205) If r.seq_dup == q.seq_dup, return success. |
| 898 | * 207) If r.seq_dup == 1, go to 301. |
| 899 | * 208) Return error. |
| 900 | * |
| 901 | * 301) If --tries_left <= 0, return error. |
| 902 | * 302) If q.seq_dup == 1, go to 105. |
| 903 | * 303) q.seq_dup = 1 |
| 904 | * 304) Go to 104. |
| 905 | * |
| 906 | * EC algorithm when receiving a request q. |
| 907 | * EC has response buffer r, error buffer e. |
| 908 | * |
| 909 | * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION |
| 910 | * and go to 301 |
| 911 | * 102) If q.header_crc mismatches calculated CRC, set e.result = |
| 912 | * EC_RES_INVALID_HEADER_CRC and go to 301 |
| 913 | * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC |
| 914 | * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC |
| 915 | * and go to 301. |
| 916 | * 104) If q.seq_dup == 0, go to 201. |
| 917 | * 105) If q.seq_num != r.seq_num, go to 201. |
| 918 | * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203. |
| 919 | * |
| 920 | * 201) Process request q into response r. |
| 921 | * 202) r.seq_num = q.seq_num |
| 922 | * 203) r.seq_dup = q.seq_dup |
| 923 | * 204) Calculate r.header_crc |
| 924 | * 205) If r.data_len > 0 and data is no longer available, set e.result = |
| 925 | * EC_RES_DUP_UNAVAILABLE and go to 301. |
| 926 | * 206) Send response r. |
| 927 | * |
| 928 | * 301) e.seq_num = q.seq_num |
| 929 | * 302) e.seq_dup = q.seq_dup |
| 930 | * 303) Calculate e.header_crc. |
| 931 | * 304) Send error response e. |
| 932 | */ |
| 933 | |
| 934 | /* Version 4 request from host */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 935 | struct ec_host_request4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 936 | /* |
| 937 | * bits 0-3: struct_version: Structure version (=4) |
| 938 | * bit 4: is_response: Is response (=0) |
| 939 | * bits 5-6: seq_num: Sequence number |
| 940 | * bit 7: seq_dup: Sequence duplicate flag |
| 941 | */ |
| 942 | uint8_t fields0; |
| 943 | |
| 944 | /* |
| 945 | * bits 0-4: command_version: Command version |
| 946 | * bits 5-6: Reserved (set 0, ignore on read) |
| 947 | * bit 7: data_crc_present: Is data CRC present after data |
| 948 | */ |
| 949 | uint8_t fields1; |
| 950 | |
| 951 | /* Command code (EC_CMD_*) */ |
| 952 | uint16_t command; |
| 953 | |
| 954 | /* Length of data which follows this header (not including data CRC) */ |
| 955 | uint16_t data_len; |
| 956 | |
| 957 | /* Reserved (set 0, ignore on read) */ |
| 958 | uint8_t reserved; |
| 959 | |
| 960 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 961 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 962 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 963 | |
| 964 | /* Version 4 response from EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 965 | struct ec_host_response4 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 966 | /* |
| 967 | * bits 0-3: struct_version: Structure version (=4) |
| 968 | * bit 4: is_response: Is response (=1) |
| 969 | * bits 5-6: seq_num: Sequence number |
| 970 | * bit 7: seq_dup: Sequence duplicate flag |
| 971 | */ |
| 972 | uint8_t fields0; |
| 973 | |
| 974 | /* |
| 975 | * bits 0-6: Reserved (set 0, ignore on read) |
| 976 | * bit 7: data_crc_present: Is data CRC present after data |
| 977 | */ |
| 978 | uint8_t fields1; |
| 979 | |
| 980 | /* Result code (EC_RES_*) */ |
| 981 | uint16_t result; |
| 982 | |
| 983 | /* Length of data which follows this header (not including data CRC) */ |
| 984 | uint16_t data_len; |
| 985 | |
| 986 | /* Reserved (set 0, ignore on read) */ |
| 987 | uint8_t reserved; |
| 988 | |
| 989 | /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */ |
| 990 | uint8_t header_crc; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 991 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 992 | |
| 993 | /* Fields in fields0 byte */ |
| 994 | #define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f |
| 995 | #define EC_PACKET4_0_IS_RESPONSE_MASK 0x10 |
| 996 | #define EC_PACKET4_0_SEQ_NUM_SHIFT 5 |
| 997 | #define EC_PACKET4_0_SEQ_NUM_MASK 0x60 |
| 998 | #define EC_PACKET4_0_SEQ_DUP_MASK 0x80 |
| 999 | |
| 1000 | /* Fields in fields1 byte */ |
| 1001 | #define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */ |
| 1002 | #define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80 |
| 1003 | |
| 1004 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1005 | /* |
| 1006 | * Notes on commands: |
| 1007 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 1008 | * 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] | 1009 | * return response data specify structures for that data. If no structure is |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1010 | * specified, the command does not input or output data, respectively. |
| 1011 | * Parameter/response length is implicit in the structs. Some underlying |
| 1012 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 1013 | * those are implementation-dependent and not defined here. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1014 | * |
| 1015 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 1016 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1017 | */ |
| 1018 | |
| 1019 | /*****************************************************************************/ |
| 1020 | /* General / test commands */ |
| 1021 | |
| 1022 | /* |
| 1023 | * Get protocol version, used to deal with non-backward compatible protocol |
| 1024 | * changes. |
| 1025 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1026 | #define EC_CMD_PROTO_VERSION 0x0000 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1027 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1028 | /** |
| 1029 | * struct ec_response_proto_version - Response to the proto version command. |
| 1030 | * @version: The protocol version. |
| 1031 | */ |
| 1032 | struct ec_response_proto_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1033 | uint32_t version; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1034 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1035 | |
| 1036 | /* |
| 1037 | * Hello. This is a simple command to test the EC is responsive to |
| 1038 | * commands. |
| 1039 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1040 | #define EC_CMD_HELLO 0x0001 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1041 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1042 | /** |
| 1043 | * struct ec_params_hello - Parameters to the hello command. |
| 1044 | * @in_data: Pass anything here. |
| 1045 | */ |
| 1046 | struct ec_params_hello { |
| 1047 | uint32_t in_data; |
| 1048 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1049 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1050 | /** |
| 1051 | * struct ec_response_hello - Response to the hello command. |
| 1052 | * @out_data: Output will be in_data + 0x01020304. |
| 1053 | */ |
| 1054 | struct ec_response_hello { |
| 1055 | uint32_t out_data; |
| 1056 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1057 | |
| 1058 | /* Get version number */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1059 | #define EC_CMD_GET_VERSION 0x0002 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1060 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1061 | #if !defined(CHROMIUM_EC) && !defined(__KERNEL__) |
| 1062 | /* |
| 1063 | * enum ec_current_image is deprecated and replaced by enum ec_image. This |
| 1064 | * macro exists for backwards compatibility of external projects until they |
| 1065 | * have been updated: b/149987779. |
| 1066 | */ |
| 1067 | #define ec_current_image ec_image |
| 1068 | #endif |
| 1069 | |
| 1070 | enum ec_image { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1071 | EC_IMAGE_UNKNOWN = 0, |
| 1072 | EC_IMAGE_RO, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1073 | EC_IMAGE_RW, |
| 1074 | EC_IMAGE_RW_A = EC_IMAGE_RW, |
| 1075 | EC_IMAGE_RO_B, |
| 1076 | EC_IMAGE_RW_B |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1077 | }; |
| 1078 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1079 | /** |
| 1080 | * struct ec_response_get_version - Response to the get version command. |
| 1081 | * @version_string_ro: Null-terminated RO firmware version string. |
| 1082 | * @version_string_rw: Null-terminated RW firmware version string. |
| 1083 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1084 | * @current_image: One of ec_image. |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1085 | */ |
| 1086 | struct ec_response_get_version { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1087 | char version_string_ro[32]; |
| 1088 | char version_string_rw[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1089 | char reserved[32]; |
| 1090 | uint32_t current_image; |
| 1091 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1092 | |
| 1093 | /* Read test */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1094 | #define EC_CMD_READ_TEST 0x0003 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1095 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1096 | /** |
| 1097 | * struct ec_params_read_test - Parameters for the read test command. |
| 1098 | * @offset: Starting value for read buffer. |
| 1099 | * @size: Size to read in bytes. |
| 1100 | */ |
| 1101 | struct ec_params_read_test { |
| 1102 | uint32_t offset; |
| 1103 | uint32_t size; |
| 1104 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1105 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1106 | /** |
| 1107 | * struct ec_response_read_test - Response to the read test command. |
| 1108 | * @data: Data returned by the read test command. |
| 1109 | */ |
| 1110 | struct ec_response_read_test { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1111 | uint32_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1112 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1113 | |
| 1114 | /* |
| 1115 | * Get build information |
| 1116 | * |
| 1117 | * Response is null-terminated string. |
| 1118 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1119 | #define EC_CMD_GET_BUILD_INFO 0x0004 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1120 | |
| 1121 | /* Get chip info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1122 | #define EC_CMD_GET_CHIP_INFO 0x0005 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1123 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1124 | /** |
| 1125 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 1126 | * @vendor: Null-terminated string for chip vendor. |
| 1127 | * @name: Null-terminated string for chip name. |
| 1128 | * @revision: Null-terminated string for chip mask version. |
| 1129 | */ |
| 1130 | struct ec_response_get_chip_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1131 | char vendor[32]; |
| 1132 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1133 | char revision[32]; |
| 1134 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1135 | |
| 1136 | /* Get board HW version */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1137 | #define EC_CMD_GET_BOARD_VERSION 0x0006 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1138 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1139 | /** |
| 1140 | * struct ec_response_board_version - Response to the board version command. |
| 1141 | * @board_version: A monotonously incrementing number. |
| 1142 | */ |
| 1143 | struct ec_response_board_version { |
| 1144 | uint16_t board_version; |
| 1145 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1146 | |
| 1147 | /* |
| 1148 | * Read memory-mapped data. |
| 1149 | * |
| 1150 | * This is an alternate interface to memory-mapped data for bus protocols |
| 1151 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 1152 | * |
| 1153 | * Response is params.size bytes of data. |
| 1154 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1155 | #define EC_CMD_READ_MEMMAP 0x0007 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1156 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1157 | /** |
| 1158 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 1159 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 1160 | * @size: Size to read in bytes. |
| 1161 | */ |
| 1162 | struct ec_params_read_memmap { |
| 1163 | uint8_t offset; |
| 1164 | uint8_t size; |
| 1165 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1166 | |
| 1167 | /* Read versions supported for a command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1168 | #define EC_CMD_GET_CMD_VERSIONS 0x0008 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1169 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1170 | /** |
| 1171 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 1172 | * @cmd: Command to check. |
| 1173 | */ |
| 1174 | struct ec_params_get_cmd_versions { |
| 1175 | uint8_t cmd; |
| 1176 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1177 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1178 | /** |
| 1179 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 1180 | * versions (v1) |
| 1181 | * @cmd: Command to check. |
| 1182 | */ |
| 1183 | struct ec_params_get_cmd_versions_v1 { |
| 1184 | uint16_t cmd; |
| 1185 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1186 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1187 | /** |
| 1188 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 1189 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 1190 | * a desired version. |
| 1191 | */ |
| 1192 | struct ec_response_get_cmd_versions { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1193 | uint32_t version_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1194 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1195 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1196 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1197 | * 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] | 1198 | * on lpc since it has its own out-of-band busy indicator. |
| 1199 | * |
| 1200 | * lpc must read the status from the command register. Attempting this on |
| 1201 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 1202 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1203 | #define EC_CMD_GET_COMMS_STATUS 0x0009 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1204 | |
| 1205 | /* Avoid using ec_status which is for return values */ |
| 1206 | enum ec_comms_status { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1207 | EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1208 | }; |
| 1209 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1210 | /** |
| 1211 | * struct ec_response_get_comms_status - Response to the get comms status |
| 1212 | * command. |
| 1213 | * @flags: Mask of enum ec_comms_status. |
| 1214 | */ |
| 1215 | struct ec_response_get_comms_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1216 | uint32_t flags; /* Mask of enum ec_comms_status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1217 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1218 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1219 | /* Fake a variety of responses, purely for testing purposes. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1220 | #define EC_CMD_TEST_PROTOCOL 0x000A |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1221 | |
| 1222 | /* Tell the EC what to send back to us. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1223 | struct ec_params_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1224 | uint32_t ec_result; |
| 1225 | uint32_t ret_len; |
| 1226 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1227 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1228 | |
| 1229 | /* Here it comes... */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1230 | struct ec_response_test_protocol { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1231 | uint8_t buf[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1232 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1233 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1234 | /* Get protocol information */ |
| 1235 | #define EC_CMD_GET_PROTOCOL_INFO 0x000B |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1236 | |
| 1237 | /* Flags for ec_response_get_protocol_info.flags */ |
| 1238 | /* 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] | 1239 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1240 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1241 | /** |
| 1242 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 1243 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 1244 | * version n). |
| 1245 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 1246 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 1247 | * @flags: see EC_PROTOCOL_INFO_* |
| 1248 | */ |
| 1249 | struct ec_response_get_protocol_info { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1250 | /* Fields which exist if at least protocol version 3 supported */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1251 | uint32_t protocol_versions; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1252 | uint16_t max_request_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1253 | uint16_t max_response_packet_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1254 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1255 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1256 | |
| 1257 | |
| 1258 | /*****************************************************************************/ |
| 1259 | /* Get/Set miscellaneous values */ |
| 1260 | |
| 1261 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 1262 | #define EC_GSV_SET 0x80000000 |
| 1263 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1264 | /* |
| 1265 | * The lower three bytes of .flags identifies the parameter, if that has |
| 1266 | * meaning for an individual command. |
| 1267 | */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1268 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 1269 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1270 | struct ec_params_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1271 | uint32_t flags; |
| 1272 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1273 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1274 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1275 | struct ec_response_get_set_value { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1276 | uint32_t flags; |
| 1277 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1278 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1279 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1280 | /* More than one command can use these structs to get/set parameters. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1281 | #define EC_CMD_GSV_PAUSE_IN_S5 0x000C |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1282 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1283 | /*****************************************************************************/ |
| 1284 | /* List the features supported by the firmware */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1285 | #define EC_CMD_GET_FEATURES 0x000D |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1286 | |
| 1287 | /* Supported features */ |
| 1288 | enum ec_feature_code { |
| 1289 | /* |
| 1290 | * This image contains a limited set of features. Another image |
| 1291 | * in RW partition may support more features. |
| 1292 | */ |
| 1293 | EC_FEATURE_LIMITED = 0, |
| 1294 | /* |
| 1295 | * Commands for probing/reading/writing/erasing the flash in the |
| 1296 | * EC are present. |
| 1297 | */ |
| 1298 | EC_FEATURE_FLASH = 1, |
| 1299 | /* |
| 1300 | * Can control the fan speed directly. |
| 1301 | */ |
| 1302 | EC_FEATURE_PWM_FAN = 2, |
| 1303 | /* |
| 1304 | * Can control the intensity of the keyboard backlight. |
| 1305 | */ |
| 1306 | EC_FEATURE_PWM_KEYB = 3, |
| 1307 | /* |
| 1308 | * Support Google lightbar, introduced on Pixel. |
| 1309 | */ |
| 1310 | EC_FEATURE_LIGHTBAR = 4, |
| 1311 | /* Control of LEDs */ |
| 1312 | EC_FEATURE_LED = 5, |
| 1313 | /* Exposes an interface to control gyro and sensors. |
| 1314 | * The host goes through the EC to access these sensors. |
| 1315 | * In addition, the EC may provide composite sensors, like lid angle. |
| 1316 | */ |
| 1317 | EC_FEATURE_MOTION_SENSE = 6, |
| 1318 | /* The keyboard is controlled by the EC */ |
| 1319 | EC_FEATURE_KEYB = 7, |
| 1320 | /* The AP can use part of the EC flash as persistent storage. */ |
| 1321 | EC_FEATURE_PSTORE = 8, |
| 1322 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 1323 | EC_FEATURE_PORT80 = 9, |
| 1324 | /* |
| 1325 | * Thermal management: include TMP specific commands. |
| 1326 | * Higher level than direct fan control. |
| 1327 | */ |
| 1328 | EC_FEATURE_THERMAL = 10, |
| 1329 | /* Can switch the screen backlight on/off */ |
| 1330 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 1331 | /* Can switch the wifi module on/off */ |
| 1332 | EC_FEATURE_WIFI_SWITCH = 12, |
| 1333 | /* Monitor host events, through for example SMI or SCI */ |
| 1334 | EC_FEATURE_HOST_EVENTS = 13, |
| 1335 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 1336 | EC_FEATURE_GPIO = 14, |
| 1337 | /* The EC can send i2c messages to downstream devices. */ |
| 1338 | EC_FEATURE_I2C = 15, |
| 1339 | /* Command to control charger are included */ |
| 1340 | EC_FEATURE_CHARGER = 16, |
| 1341 | /* Simple battery support. */ |
| 1342 | EC_FEATURE_BATTERY = 17, |
| 1343 | /* |
| 1344 | * Support Smart battery protocol |
| 1345 | * (Common Smart Battery System Interface Specification) |
| 1346 | */ |
| 1347 | EC_FEATURE_SMART_BATTERY = 18, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1348 | /* EC can detect when the host hangs. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1349 | EC_FEATURE_HANG_DETECT = 19, |
| 1350 | /* Report power information, for pit only */ |
| 1351 | EC_FEATURE_PMU = 20, |
| 1352 | /* Another Cros EC device is present downstream of this one */ |
| 1353 | EC_FEATURE_SUB_MCU = 21, |
| 1354 | /* Support USB Power delivery (PD) commands */ |
| 1355 | EC_FEATURE_USB_PD = 22, |
| 1356 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 1357 | EC_FEATURE_USB_MUX = 23, |
| 1358 | /* Motion Sensor code has an internal software FIFO */ |
| 1359 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
| 1360 | /* Support temporary secure vstore */ |
| 1361 | EC_FEATURE_VSTORE = 25, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1362 | /* EC decides on USB-C SS mux state, muxes configured by host */ |
| 1363 | EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26, |
| 1364 | /* EC has RTC feature that can be controlled by host commands */ |
| 1365 | EC_FEATURE_RTC = 27, |
| 1366 | /* The MCU exposes a Fingerprint sensor */ |
| 1367 | EC_FEATURE_FINGERPRINT = 28, |
| 1368 | /* The MCU exposes a Touchpad */ |
| 1369 | EC_FEATURE_TOUCHPAD = 29, |
| 1370 | /* The MCU has RWSIG task enabled */ |
| 1371 | EC_FEATURE_RWSIG = 30, |
| 1372 | /* EC has device events support */ |
| 1373 | EC_FEATURE_DEVICE_EVENT = 31, |
Furquan Shaikh | 1432cbc | 2017-10-13 11:31:35 -0700 | [diff] [blame] | 1374 | /* EC supports the unified wake masks for LPC/eSPI systems */ |
| 1375 | EC_FEATURE_UNIFIED_WAKE_MASKS = 32, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1376 | /* EC supports 64-bit host events */ |
| 1377 | EC_FEATURE_HOST_EVENT64 = 33, |
| 1378 | /* EC runs code in RAM (not in place, a.k.a. XIP) */ |
| 1379 | EC_FEATURE_EXEC_IN_RAM = 34, |
| 1380 | /* EC supports CEC commands */ |
| 1381 | EC_FEATURE_CEC = 35, |
| 1382 | /* EC supports tight sensor timestamping. */ |
| 1383 | EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1384 | /* |
| 1385 | * EC supports tablet mode detection aligned to Chrome and allows |
| 1386 | * setting of threshold by host command using |
| 1387 | * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. |
| 1388 | */ |
| 1389 | EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1390 | /* |
| 1391 | * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2. |
| 1392 | * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should |
| 1393 | * be sent to RO to be precise. |
| 1394 | */ |
| 1395 | EC_FEATURE_EFS2 = 38, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1396 | /* The MCU is a System Companion Processor (SCP). */ |
| 1397 | EC_FEATURE_SCP = 39, |
| 1398 | /* The MCU is an Integrated Sensor Hub */ |
| 1399 | EC_FEATURE_ISH = 40, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1400 | }; |
| 1401 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1402 | #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) |
| 1403 | #define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32) |
| 1404 | |
| 1405 | struct ec_response_get_features { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 1406 | uint32_t flags[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1407 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1408 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1409 | /*****************************************************************************/ |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1410 | /* Get the board's SKU ID from EC */ |
| 1411 | #define EC_CMD_GET_SKU_ID 0x000E |
| 1412 | |
Kevin Chiu | e2bb059 | 2017-09-12 09:13:41 +0800 | [diff] [blame] | 1413 | /* Set SKU ID from AP */ |
| 1414 | #define EC_CMD_SET_SKU_ID 0x000F |
| 1415 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1416 | struct ec_sku_id_info { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1417 | uint32_t sku_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1418 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1419 | |
| 1420 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1421 | /* Flash commands */ |
| 1422 | |
| 1423 | /* Get flash info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1424 | #define EC_CMD_FLASH_INFO 0x0010 |
| 1425 | #define EC_VER_FLASH_INFO 2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1426 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1427 | /** |
| 1428 | * struct ec_response_flash_info - Response to the flash info command. |
| 1429 | * @flash_size: Usable flash size in bytes. |
| 1430 | * @write_block_size: Write block size. Write offset and size must be a |
| 1431 | * multiple of this. |
| 1432 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1433 | * multiple of this. |
| 1434 | * @protect_block_size: Protection block size. Protection offset and size |
| 1435 | * must be a multiple of this. |
| 1436 | * |
| 1437 | * Version 0 returns these fields. |
| 1438 | */ |
| 1439 | struct ec_response_flash_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1440 | uint32_t flash_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1441 | uint32_t write_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1442 | uint32_t erase_block_size; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1443 | uint32_t protect_block_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1444 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1445 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1446 | /* |
| 1447 | * Flags for version 1+ flash info command |
| 1448 | * EC flash erases bits to 0 instead of 1. |
| 1449 | */ |
| 1450 | #define EC_FLASH_INFO_ERASE_TO_0 BIT(0) |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1451 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1452 | /* |
| 1453 | * 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] | 1454 | * be necessary on a chip where write/erase can be corrupted by other board |
| 1455 | * activity, or where the chip needs to enable some sort of programming voltage, |
| 1456 | * or where the read/write/erase operations require cleanly suspending other |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1457 | * chip functionality. |
| 1458 | */ |
| 1459 | #define EC_FLASH_INFO_SELECT_REQUIRED BIT(1) |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1460 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1461 | /** |
| 1462 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 1463 | * @flash_size: Usable flash size in bytes. |
| 1464 | * @write_block_size: Write block size. Write offset and size must be a |
| 1465 | * multiple of this. |
| 1466 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 1467 | * multiple of this. |
| 1468 | * @protect_block_size: Protection block size. Protection offset and size |
| 1469 | * must be a multiple of this. |
| 1470 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 1471 | * size is exactly this and offset is a multiple of this. |
| 1472 | * For example, an EC may have a write buffer which can do |
| 1473 | * half-page operations if data is aligned, and a slower |
| 1474 | * word-at-a-time write mode. |
| 1475 | * @flags: Flags; see EC_FLASH_INFO_* |
| 1476 | * |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1477 | * Version 1 returns the same initial fields as version 0, with additional |
| 1478 | * fields following. |
| 1479 | * |
| 1480 | * 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] | 1481 | * if they did we'd define the version 0 structure as a sub-structure of this |
| 1482 | * one. |
| 1483 | * |
| 1484 | * Version 2 supports flash banks of different sizes: |
| 1485 | * The caller specified the number of banks it has preallocated |
| 1486 | * (num_banks_desc) |
| 1487 | * The EC returns the number of banks describing the flash memory. |
| 1488 | * It adds banks descriptions up to num_banks_desc. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1489 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1490 | struct ec_response_flash_info_1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1491 | /* Version 0 fields; see above for description */ |
| 1492 | uint32_t flash_size; |
| 1493 | uint32_t write_block_size; |
| 1494 | uint32_t erase_block_size; |
| 1495 | uint32_t protect_block_size; |
| 1496 | |
| 1497 | /* Version 1 adds these fields: */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1498 | uint32_t write_ideal_size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1499 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1500 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1501 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1502 | struct ec_params_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1503 | /* Number of banks to describe */ |
| 1504 | uint16_t num_banks_desc; |
| 1505 | /* Reserved; set 0; ignore on read */ |
| 1506 | uint8_t reserved[2]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1507 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1508 | |
| 1509 | struct ec_flash_bank { |
| 1510 | /* Number of sector is in this bank. */ |
| 1511 | uint16_t count; |
| 1512 | /* Size in power of 2 of each sector (8 --> 256 bytes) */ |
| 1513 | uint8_t size_exp; |
| 1514 | /* Minimal write size for the sectors in this bank */ |
| 1515 | uint8_t write_size_exp; |
| 1516 | /* Erase size for the sectors in this bank */ |
| 1517 | uint8_t erase_size_exp; |
| 1518 | /* Size for write protection, usually identical to erase size. */ |
| 1519 | uint8_t protect_size_exp; |
| 1520 | /* Reserved; set 0; ignore on read */ |
| 1521 | uint8_t reserved[2]; |
| 1522 | }; |
| 1523 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1524 | struct ec_response_flash_info_2 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1525 | /* Total flash in the EC. */ |
| 1526 | uint32_t flash_size; |
| 1527 | /* Flags; see EC_FLASH_INFO_* */ |
| 1528 | uint32_t flags; |
| 1529 | /* Maximum size to use to send data to write to the EC. */ |
| 1530 | uint32_t write_ideal_size; |
| 1531 | /* Number of banks present in the EC. */ |
| 1532 | uint16_t num_banks_total; |
| 1533 | /* Number of banks described in banks array. */ |
| 1534 | uint16_t num_banks_desc; |
| 1535 | struct ec_flash_bank banks[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1536 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1537 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1538 | /* |
| 1539 | * Read flash |
| 1540 | * |
| 1541 | * Response is params.size bytes of data. |
| 1542 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1543 | #define EC_CMD_FLASH_READ 0x0011 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1544 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1545 | /** |
| 1546 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 1547 | * @offset: Byte offset to read. |
| 1548 | * @size: Size to read in bytes. |
| 1549 | */ |
| 1550 | struct ec_params_flash_read { |
| 1551 | uint32_t offset; |
| 1552 | uint32_t size; |
| 1553 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1554 | |
| 1555 | /* Write flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1556 | #define EC_CMD_FLASH_WRITE 0x0012 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1557 | #define EC_VER_FLASH_WRITE 1 |
| 1558 | |
| 1559 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 1560 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1561 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1562 | /** |
| 1563 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 1564 | * @offset: Byte offset to write. |
| 1565 | * @size: Size to write in bytes. |
| 1566 | */ |
| 1567 | struct ec_params_flash_write { |
| 1568 | uint32_t offset; |
| 1569 | uint32_t size; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1570 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1571 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1572 | |
| 1573 | /* Erase flash */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1574 | #define EC_CMD_FLASH_ERASE 0x0013 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1575 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1576 | /** |
| 1577 | * struct ec_params_flash_erase - Parameters for the flash erase command, v0. |
| 1578 | * @offset: Byte offset to erase. |
| 1579 | * @size: Size to erase in bytes. |
| 1580 | */ |
| 1581 | struct ec_params_flash_erase { |
| 1582 | uint32_t offset; |
| 1583 | uint32_t size; |
| 1584 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1585 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1586 | /* |
| 1587 | * v1 add async erase: |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1588 | * subcommands can returns: |
| 1589 | * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below). |
| 1590 | * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary. |
| 1591 | * EC_RES_ERROR : other errors. |
| 1592 | * EC_RES_BUSY : an existing erase operation is in progress. |
| 1593 | * EC_RES_ACCESS_DENIED: Trying to erase running image. |
| 1594 | * |
| 1595 | * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just |
| 1596 | * properly queued. The user must call ERASE_GET_RESULT subcommand to get |
| 1597 | * the proper result. |
| 1598 | * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send |
| 1599 | * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC. |
| 1600 | * ERASE_GET_RESULT command may timeout on EC where flash access is not |
| 1601 | * permitted while erasing. (For instance, STM32F4). |
| 1602 | */ |
| 1603 | enum ec_flash_erase_cmd { |
| 1604 | FLASH_ERASE_SECTOR, /* Erase and wait for result */ |
| 1605 | FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */ |
| 1606 | FLASH_ERASE_GET_RESULT, /* Ask for last erase result */ |
| 1607 | }; |
| 1608 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1609 | /** |
| 1610 | * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1. |
| 1611 | * @cmd: One of ec_flash_erase_cmd. |
| 1612 | * @reserved: Pad byte; currently always contains 0. |
| 1613 | * @flag: No flags defined yet; set to 0. |
| 1614 | * @params: Same as v0 parameters. |
| 1615 | */ |
| 1616 | struct ec_params_flash_erase_v1 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1617 | uint8_t cmd; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1618 | uint8_t reserved; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1619 | uint16_t flag; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1620 | struct ec_params_flash_erase params; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1621 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1622 | |
| 1623 | /* |
| 1624 | * Get/set flash protection. |
| 1625 | * |
| 1626 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 1627 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 1628 | * some flags require a subsequent hard reset to take effect. Check the |
| 1629 | * returned flags bits to see what actually happened. |
| 1630 | * |
| 1631 | * If mask=0, simply returns the current flags state. |
| 1632 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1633 | #define EC_CMD_FLASH_PROTECT 0x0015 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1634 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 1635 | |
| 1636 | /* Flags for flash protection */ |
| 1637 | /* RO flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1638 | #define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1639 | /* |
| 1640 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 1641 | * be changed. |
| 1642 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1643 | #define EC_FLASH_PROTECT_RO_NOW BIT(1) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1644 | /* Entire flash code protected now, until reboot. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1645 | #define EC_FLASH_PROTECT_ALL_NOW BIT(2) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1646 | /* Flash write protect GPIO is asserted now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1647 | #define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1648 | /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1649 | #define EC_FLASH_PROTECT_ERROR_STUCK BIT(4) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1650 | /* |
| 1651 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1652 | * flash which should be protected is not protected. Usually fixed by |
| 1653 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1654 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1655 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1656 | /* Entire flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1657 | #define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1658 | /* RW flash code protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1659 | #define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1660 | /* RW flash code protected now. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1661 | #define EC_FLASH_PROTECT_RW_NOW BIT(8) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1662 | /* Rollback information flash region protected when the EC boots */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1663 | #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1664 | /* Rollback information flash region protected now */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1665 | #define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10) |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1666 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1667 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1668 | /** |
| 1669 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1670 | * @mask: Bits in flags to apply. |
| 1671 | * @flags: New flags to apply. |
| 1672 | */ |
| 1673 | struct ec_params_flash_protect { |
| 1674 | uint32_t mask; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1675 | uint32_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1676 | } __ec_align4; |
| 1677 | |
| 1678 | /** |
| 1679 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1680 | * @flags: Current value of flash protect flags. |
| 1681 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1682 | * caller to distinguish between flags which aren't set vs. flags |
| 1683 | * which can't be set on this platform. |
| 1684 | * @writable_flags: Flags which can be changed given the current protection |
| 1685 | * state. |
| 1686 | */ |
| 1687 | struct ec_response_flash_protect { |
| 1688 | uint32_t flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1689 | uint32_t valid_flags; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1690 | uint32_t writable_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1691 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1692 | |
| 1693 | /* |
| 1694 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1695 | * write protect. These commands may be reused with version > 0. |
| 1696 | */ |
| 1697 | |
| 1698 | /* Get the region offset/size */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1699 | #define EC_CMD_FLASH_REGION_INFO 0x0016 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1700 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1701 | |
| 1702 | enum ec_flash_region { |
| 1703 | /* Region which holds read-only EC image */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1704 | EC_FLASH_REGION_RO = 0, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1705 | /* |
| 1706 | * Region which holds active RW image. 'Active' is different from |
| 1707 | * 'running'. Active means 'scheduled-to-run'. Since RO image always |
| 1708 | * scheduled to run, active/non-active applies only to RW images (for |
| 1709 | * the same reason 'update' applies only to RW images. It's a state of |
| 1710 | * an image on a flash. Running image can be RO, RW_A, RW_B but active |
| 1711 | * image can only be RW_A or RW_B. In recovery mode, an active RW image |
| 1712 | * doesn't enter 'running' state but it's still active on a flash. |
| 1713 | */ |
| 1714 | EC_FLASH_REGION_ACTIVE, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1715 | /* |
| 1716 | * Region which should be write-protected in the factory (a superset of |
| 1717 | * EC_FLASH_REGION_RO) |
| 1718 | */ |
| 1719 | EC_FLASH_REGION_WP_RO, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1720 | /* Region which holds updatable (non-active) RW image */ |
| 1721 | EC_FLASH_REGION_UPDATE, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1722 | /* Number of regions */ |
| 1723 | EC_FLASH_REGION_COUNT, |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1724 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1725 | /* |
| 1726 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 1727 | * so the old constant is deprecated. |
| 1728 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 1729 | #define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1730 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1731 | /** |
| 1732 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1733 | * command. |
| 1734 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1735 | */ |
| 1736 | struct ec_params_flash_region_info { |
| 1737 | uint32_t region; |
| 1738 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1739 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1740 | struct ec_response_flash_region_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1741 | uint32_t offset; |
| 1742 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1743 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1744 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1745 | /* Read/write VbNvContext */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1746 | #define EC_CMD_VBNV_CONTEXT 0x0017 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1747 | #define EC_VER_VBNV_CONTEXT 1 |
| 1748 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1749 | |
| 1750 | enum ec_vbnvcontext_op { |
| 1751 | EC_VBNV_CONTEXT_OP_READ, |
| 1752 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1753 | }; |
| 1754 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1755 | struct ec_params_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1756 | uint32_t op; |
| 1757 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1758 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1759 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1760 | struct ec_response_vbnvcontext { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1761 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1762 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1763 | |
| 1764 | |
| 1765 | /* Get SPI flash information */ |
| 1766 | #define EC_CMD_FLASH_SPI_INFO 0x0018 |
| 1767 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1768 | struct ec_response_flash_spi_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1769 | /* JEDEC info from command 0x9F (manufacturer, memory type, size) */ |
| 1770 | uint8_t jedec[3]; |
| 1771 | |
| 1772 | /* Pad byte; currently always contains 0 */ |
| 1773 | uint8_t reserved0; |
| 1774 | |
| 1775 | /* Manufacturer / device ID from command 0x90 */ |
| 1776 | uint8_t mfr_dev_id[2]; |
| 1777 | |
| 1778 | /* Status registers from command 0x05 and 0x35 */ |
| 1779 | uint8_t sr1, sr2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1780 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1781 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1782 | |
| 1783 | /* Select flash during flash operations */ |
| 1784 | #define EC_CMD_FLASH_SELECT 0x0019 |
| 1785 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1786 | /** |
| 1787 | * struct ec_params_flash_select - Parameters for the flash select command. |
| 1788 | * @select: 1 to select flash, 0 to deselect flash |
| 1789 | */ |
| 1790 | struct ec_params_flash_select { |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1791 | uint8_t select; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1792 | } __ec_align4; |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 1793 | |
| 1794 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1795 | /** |
| 1796 | * Request random numbers to be generated and returned. |
| 1797 | * Can be used to test the random number generator is truly random. |
| 1798 | * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and |
| 1799 | * https://webhome.phy.duke.edu/~rgb/General/dieharder.php. |
| 1800 | */ |
| 1801 | #define EC_CMD_RAND_NUM 0x001A |
| 1802 | #define EC_VER_RAND_NUM 0 |
| 1803 | |
| 1804 | struct ec_params_rand_num { |
| 1805 | uint16_t num_rand_bytes; /**< num random bytes to generate */ |
| 1806 | } __ec_align4; |
| 1807 | |
| 1808 | struct ec_response_rand_num { |
| 1809 | uint8_t rand[0]; /**< generated random numbers */ |
| 1810 | } __ec_align4; |
| 1811 | |
| 1812 | BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0); |
| 1813 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 1814 | /** |
| 1815 | * Get information about the key used to sign the RW firmware. |
| 1816 | * For more details on the fields, see "struct vb21_packed_key". |
| 1817 | */ |
| 1818 | #define EC_CMD_RWSIG_INFO 0x001B |
| 1819 | #define EC_VER_RWSIG_INFO 0 |
| 1820 | |
| 1821 | #define VBOOT2_KEY_ID_BYTES 20 |
| 1822 | |
| 1823 | #ifdef CHROMIUM_EC |
| 1824 | /* Don't force external projects to depend on the vboot headers. */ |
| 1825 | #include "vb21_struct.h" |
| 1826 | BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES); |
| 1827 | #endif |
| 1828 | |
| 1829 | struct ec_response_rwsig_info { |
| 1830 | /** |
| 1831 | * Signature algorithm used by the key |
| 1832 | * (enum vb2_signature_algorithm). |
| 1833 | */ |
| 1834 | uint16_t sig_alg; |
| 1835 | |
| 1836 | /** |
| 1837 | * Hash digest algorithm used with the key |
| 1838 | * (enum vb2_hash_algorithm). |
| 1839 | */ |
| 1840 | uint16_t hash_alg; |
| 1841 | |
| 1842 | /** Key version. */ |
| 1843 | uint32_t key_version; |
| 1844 | |
| 1845 | /** Key ID (struct vb2_id). */ |
| 1846 | uint8_t key_id[VBOOT2_KEY_ID_BYTES]; |
| 1847 | |
| 1848 | uint8_t key_is_valid; |
| 1849 | |
| 1850 | /** Alignment padding. */ |
| 1851 | uint8_t reserved[3]; |
| 1852 | } __ec_align4; |
| 1853 | |
| 1854 | BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32); |
| 1855 | |
| 1856 | /** |
| 1857 | * Get information about the system, such as reset flags, locked state, etc. |
| 1858 | */ |
| 1859 | #define EC_CMD_SYSINFO 0x001C |
| 1860 | #define EC_VER_SYSINFO 0 |
| 1861 | |
| 1862 | enum sysinfo_flags { |
| 1863 | SYSTEM_IS_LOCKED = BIT(0), |
| 1864 | SYSTEM_IS_FORCE_LOCKED = BIT(1), |
| 1865 | SYSTEM_JUMP_ENABLED = BIT(2), |
| 1866 | SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3), |
| 1867 | SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4) |
| 1868 | }; |
| 1869 | |
| 1870 | struct ec_response_sysinfo { |
| 1871 | uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */ |
| 1872 | uint32_t current_image; /**< enum ec_current_image */ |
| 1873 | uint32_t flags; /**< enum sysinfo_flags */ |
| 1874 | } __ec_align4; |
| 1875 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1876 | /*****************************************************************************/ |
| 1877 | /* PWM commands */ |
| 1878 | |
| 1879 | /* Get fan target RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1880 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1881 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1882 | struct ec_response_pwm_get_fan_rpm { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1883 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1884 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1885 | |
| 1886 | /* Set target fan RPM */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1887 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1888 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1889 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1890 | struct ec_params_pwm_set_fan_target_rpm_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1891 | uint32_t rpm; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1892 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1893 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1894 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1895 | struct ec_params_pwm_set_fan_target_rpm_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1896 | uint32_t rpm; |
| 1897 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1898 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1899 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1900 | /* Get keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1901 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1902 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1903 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1904 | struct ec_response_pwm_get_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1905 | uint8_t percent; |
| 1906 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1907 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1908 | |
| 1909 | /* Set keyboard backlight */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1910 | /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1911 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1912 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1913 | struct ec_params_pwm_set_keyboard_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1914 | uint8_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1915 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1916 | |
| 1917 | /* Set target fan PWM duty cycle */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1918 | #define EC_CMD_PWM_SET_FAN_DUTY 0x0024 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1919 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1920 | /* Version 0 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1921 | struct ec_params_pwm_set_fan_duty_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1922 | uint32_t percent; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1923 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1924 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1925 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1926 | struct ec_params_pwm_set_fan_duty_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1927 | uint32_t percent; |
| 1928 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1929 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 1930 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1931 | #define EC_CMD_PWM_SET_DUTY 0x0025 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1932 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 1933 | #define EC_PWM_MAX_DUTY 0xffff |
| 1934 | |
| 1935 | enum ec_pwm_type { |
| 1936 | /* All types, indexed by board-specific enum pwm_channel */ |
| 1937 | EC_PWM_TYPE_GENERIC = 0, |
| 1938 | /* Keyboard backlight */ |
| 1939 | EC_PWM_TYPE_KB_LIGHT, |
| 1940 | /* Display backlight */ |
| 1941 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 1942 | EC_PWM_TYPE_COUNT, |
| 1943 | }; |
| 1944 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1945 | struct ec_params_pwm_set_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1946 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1947 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1948 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1949 | } __ec_align4; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1950 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1951 | #define EC_CMD_PWM_GET_DUTY 0x0026 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1952 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1953 | struct ec_params_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1954 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1955 | uint8_t index; /* Type-specific index, or 0 if unique */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1956 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1957 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1958 | struct ec_response_pwm_get_duty { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1959 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1960 | } __ec_align2; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 1961 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1962 | /*****************************************************************************/ |
| 1963 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1964 | * 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] | 1965 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 1966 | * into a subcommand. We'll make separate structs for subcommands with |
| 1967 | * different input args, so that we know how much to expect. |
| 1968 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 1969 | #define EC_CMD_LIGHTBAR_CMD 0x0028 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1970 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1971 | struct rgb_s { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1972 | uint8_t r, g, b; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1973 | } __ec_todo_unpacked; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 1974 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1975 | #define LB_BATTERY_LEVELS 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1976 | |
| 1977 | /* |
| 1978 | * 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] | 1979 | * host command, but the alignment is the same regardless. Keep it that way. |
| 1980 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 1981 | struct lightbar_params_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1982 | /* Timing */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 1983 | int32_t google_ramp_up; |
| 1984 | int32_t google_ramp_down; |
| 1985 | int32_t s3s0_ramp_up; |
| 1986 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1987 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1988 | int32_t s0s3_ramp_down; |
| 1989 | int32_t s3_sleep_for; |
| 1990 | int32_t s3_ramp_up; |
| 1991 | int32_t s3_ramp_down; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 1992 | |
| 1993 | /* Oscillation */ |
| 1994 | uint8_t new_s0; |
| 1995 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1996 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1997 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1998 | |
| 1999 | /* Brightness limits based on the backlight and AC. */ |
| 2000 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2001 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2002 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2003 | |
| 2004 | /* Battery level thresholds */ |
| 2005 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2006 | |
| 2007 | /* Map [AC][battery_level] to color index */ |
| 2008 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2009 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2010 | |
| 2011 | /* Color palette */ |
| 2012 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2013 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2014 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2015 | struct lightbar_params_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2016 | /* Timing */ |
| 2017 | int32_t google_ramp_up; |
| 2018 | int32_t google_ramp_down; |
| 2019 | int32_t s3s0_ramp_up; |
| 2020 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2021 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2022 | int32_t s0s3_ramp_down; |
| 2023 | int32_t s3_sleep_for; |
| 2024 | int32_t s3_ramp_up; |
| 2025 | int32_t s3_ramp_down; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2026 | int32_t s5_ramp_up; |
| 2027 | int32_t s5_ramp_down; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2028 | int32_t tap_tick_delay; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2029 | int32_t tap_gate_delay; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2030 | int32_t tap_display_time; |
| 2031 | |
| 2032 | /* Tap-for-battery params */ |
| 2033 | uint8_t tap_pct_red; |
| 2034 | uint8_t tap_pct_green; |
| 2035 | uint8_t tap_seg_min_on; |
| 2036 | uint8_t tap_seg_max_on; |
| 2037 | uint8_t tap_seg_osc; |
| 2038 | uint8_t tap_idx[3]; |
| 2039 | |
| 2040 | /* Oscillation */ |
| 2041 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2042 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2043 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 2044 | |
| 2045 | /* Brightness limits based on the backlight and AC. */ |
| 2046 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2047 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2048 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 2049 | |
| 2050 | /* Battery level thresholds */ |
| 2051 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 2052 | |
| 2053 | /* Map [AC][battery_level] to color index */ |
| 2054 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2055 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2056 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2057 | /* s5: single color pulse on inhibited power-up */ |
| 2058 | uint8_t s5_idx; |
| 2059 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2060 | /* Color palette */ |
| 2061 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2062 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2063 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2064 | /* Lightbar command params v2 |
| 2065 | * crbug.com/467716 |
| 2066 | * |
| 2067 | * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by |
| 2068 | * logical groups to make it more manageable ( < 120 bytes). |
| 2069 | * |
| 2070 | * NOTE: Each of these groups must be less than 120 bytes. |
| 2071 | */ |
| 2072 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2073 | struct lightbar_params_v2_timing { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2074 | /* Timing */ |
| 2075 | int32_t google_ramp_up; |
| 2076 | int32_t google_ramp_down; |
| 2077 | int32_t s3s0_ramp_up; |
| 2078 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 2079 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 2080 | int32_t s0s3_ramp_down; |
| 2081 | int32_t s3_sleep_for; |
| 2082 | int32_t s3_ramp_up; |
| 2083 | int32_t s3_ramp_down; |
| 2084 | int32_t s5_ramp_up; |
| 2085 | int32_t s5_ramp_down; |
| 2086 | int32_t tap_tick_delay; |
| 2087 | int32_t tap_gate_delay; |
| 2088 | int32_t tap_display_time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2089 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2090 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2091 | struct lightbar_params_v2_tap { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2092 | /* Tap-for-battery params */ |
| 2093 | uint8_t tap_pct_red; |
| 2094 | uint8_t tap_pct_green; |
| 2095 | uint8_t tap_seg_min_on; |
| 2096 | uint8_t tap_seg_max_on; |
| 2097 | uint8_t tap_seg_osc; |
| 2098 | uint8_t tap_idx[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2099 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2100 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2101 | struct lightbar_params_v2_oscillation { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2102 | /* Oscillation */ |
| 2103 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 2104 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 2105 | uint8_t w_ofs[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2106 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2107 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2108 | struct lightbar_params_v2_brightness { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2109 | /* Brightness limits based on the backlight and AC. */ |
| 2110 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 2111 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 2112 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2113 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2114 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2115 | struct lightbar_params_v2_thresholds { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2116 | /* Battery level thresholds */ |
| 2117 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2118 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2119 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2120 | struct lightbar_params_v2_colors { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2121 | /* Map [AC][battery_level] to color index */ |
| 2122 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 2123 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 2124 | |
| 2125 | /* s5: single color pulse on inhibited power-up */ |
| 2126 | uint8_t s5_idx; |
| 2127 | |
| 2128 | /* Color palette */ |
| 2129 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2130 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2131 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2132 | /* Lightbar program. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2133 | #define EC_LB_PROG_LEN 192 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2134 | struct lightbar_program { |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2135 | uint8_t size; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2136 | uint8_t data[EC_LB_PROG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2137 | } __ec_todo_unpacked; |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2138 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2139 | struct ec_params_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2140 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 2141 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2142 | /* |
| 2143 | * The following commands have no args: |
| 2144 | * |
| 2145 | * dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
| 2146 | * version, get_brightness, get_demo, suspend, resume, |
| 2147 | * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc, |
| 2148 | * get_params_v2_bright, get_params_v2_thlds, |
| 2149 | * get_params_v2_colors |
| 2150 | * |
| 2151 | * Don't use an empty struct, because C++ hates that. |
| 2152 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2153 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2154 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2155 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2156 | } set_brightness, seq, demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2157 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2158 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2159 | uint8_t ctrl, reg, value; |
| 2160 | } reg; |
| 2161 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2162 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2163 | uint8_t led, red, green, blue; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2164 | } set_rgb; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2165 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2166 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2167 | uint8_t led; |
| 2168 | } get_rgb; |
| 2169 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2170 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2171 | uint8_t enable; |
| 2172 | } manual_suspend_ctrl; |
| 2173 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2174 | struct lightbar_params_v0 set_params_v0; |
| 2175 | struct lightbar_params_v1 set_params_v1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2176 | |
| 2177 | struct lightbar_params_v2_timing set_v2par_timing; |
| 2178 | struct lightbar_params_v2_tap set_v2par_tap; |
| 2179 | struct lightbar_params_v2_oscillation set_v2par_osc; |
| 2180 | struct lightbar_params_v2_brightness set_v2par_bright; |
| 2181 | struct lightbar_params_v2_thresholds set_v2par_thlds; |
| 2182 | struct lightbar_params_v2_colors set_v2par_colors; |
| 2183 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2184 | struct lightbar_program set_program; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2185 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2186 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2187 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2188 | struct ec_response_lightbar { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2189 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2190 | struct __ec_todo_unpacked { |
| 2191 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2192 | uint8_t reg; |
| 2193 | uint8_t ic0; |
| 2194 | uint8_t ic1; |
| 2195 | } vals[23]; |
| 2196 | } dump; |
| 2197 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2198 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2199 | uint8_t num; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2200 | } get_seq, get_brightness, get_demo; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2201 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2202 | struct lightbar_params_v0 get_params_v0; |
| 2203 | struct lightbar_params_v1 get_params_v1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2204 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2205 | |
| 2206 | struct lightbar_params_v2_timing get_params_v2_timing; |
| 2207 | struct lightbar_params_v2_tap get_params_v2_tap; |
| 2208 | struct lightbar_params_v2_oscillation get_params_v2_osc; |
| 2209 | struct lightbar_params_v2_brightness get_params_v2_bright; |
| 2210 | struct lightbar_params_v2_thresholds get_params_v2_thlds; |
| 2211 | struct lightbar_params_v2_colors get_params_v2_colors; |
| 2212 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2213 | struct __ec_todo_unpacked { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2214 | uint32_t num; |
| 2215 | uint32_t flags; |
| 2216 | } version; |
| 2217 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2218 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2219 | uint8_t red, green, blue; |
| 2220 | } get_rgb; |
| 2221 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2222 | /* |
| 2223 | * The following commands have no response: |
| 2224 | * |
| 2225 | * off, on, init, set_brightness, seq, reg, set_rgb, demo, |
| 2226 | * set_params_v0, set_params_v1, set_program, |
| 2227 | * manual_suspend_ctrl, suspend, resume, set_v2par_timing, |
| 2228 | * set_v2par_tap, set_v2par_osc, set_v2par_bright, |
| 2229 | * set_v2par_thlds, set_v2par_colors |
| 2230 | */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2231 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2232 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2233 | |
| 2234 | /* Lightbar commands */ |
| 2235 | enum lightbar_command { |
| 2236 | LIGHTBAR_CMD_DUMP = 0, |
| 2237 | LIGHTBAR_CMD_OFF = 1, |
| 2238 | LIGHTBAR_CMD_ON = 2, |
| 2239 | LIGHTBAR_CMD_INIT = 3, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2240 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2241 | LIGHTBAR_CMD_SEQ = 5, |
| 2242 | LIGHTBAR_CMD_REG = 6, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2243 | LIGHTBAR_CMD_SET_RGB = 7, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2244 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 2245 | LIGHTBAR_CMD_DEMO = 9, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2246 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 2247 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2248 | LIGHTBAR_CMD_VERSION = 12, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2249 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 2250 | LIGHTBAR_CMD_GET_RGB = 14, |
| 2251 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 2252 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 2253 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Duncan Laurie | d840118 | 2014-09-29 08:32:19 -0700 | [diff] [blame] | 2254 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2255 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 2256 | LIGHTBAR_CMD_SUSPEND = 20, |
| 2257 | LIGHTBAR_CMD_RESUME = 21, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2258 | LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22, |
| 2259 | LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23, |
| 2260 | LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24, |
| 2261 | LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25, |
| 2262 | LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26, |
| 2263 | LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27, |
| 2264 | LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28, |
| 2265 | LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29, |
| 2266 | LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30, |
| 2267 | LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31, |
| 2268 | LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32, |
| 2269 | LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33, |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2270 | LIGHTBAR_NUM_CMDS |
| 2271 | }; |
| 2272 | |
| 2273 | /*****************************************************************************/ |
| 2274 | /* LED control commands */ |
| 2275 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2276 | #define EC_CMD_LED_CONTROL 0x0029 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2277 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2278 | enum ec_led_id { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2279 | /* LED to indicate battery state of charge */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2280 | EC_LED_ID_BATTERY_LED = 0, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2281 | /* |
| 2282 | * LED to indicate system power state (on or in suspend). |
| 2283 | * May be on power button or on C-panel. |
| 2284 | */ |
| 2285 | EC_LED_ID_POWER_LED, |
| 2286 | /* LED on power adapter or its plug */ |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2287 | EC_LED_ID_ADAPTER_LED, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2288 | /* LED to indicate left side */ |
| 2289 | EC_LED_ID_LEFT_LED, |
| 2290 | /* LED to indicate right side */ |
| 2291 | EC_LED_ID_RIGHT_LED, |
| 2292 | /* LED to indicate recovery mode with HW_REINIT */ |
| 2293 | EC_LED_ID_RECOVERY_HW_REINIT_LED, |
| 2294 | /* LED to indicate sysrq debug mode. */ |
| 2295 | EC_LED_ID_SYSRQ_DEBUG_LED, |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 2296 | |
| 2297 | EC_LED_ID_COUNT |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2298 | }; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2299 | |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2300 | /* LED control flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2301 | #define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */ |
| 2302 | #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] | 2303 | |
| 2304 | enum ec_led_colors { |
| 2305 | EC_LED_COLOR_RED = 0, |
| 2306 | EC_LED_COLOR_GREEN, |
| 2307 | EC_LED_COLOR_BLUE, |
| 2308 | EC_LED_COLOR_YELLOW, |
| 2309 | EC_LED_COLOR_WHITE, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2310 | EC_LED_COLOR_AMBER, |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2311 | |
| 2312 | EC_LED_COLOR_COUNT |
| 2313 | }; |
| 2314 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2315 | struct ec_params_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2316 | uint8_t led_id; /* Which LED to control */ |
| 2317 | uint8_t flags; /* Control flags */ |
| 2318 | |
| 2319 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2320 | } __ec_align1; |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2321 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2322 | struct ec_response_led_control { |
Bill Richardson | e221aad | 2013-06-12 10:50:41 -0700 | [diff] [blame] | 2323 | /* |
| 2324 | * Available brightness value range. |
| 2325 | * |
| 2326 | * Range 0 means color channel not present. |
| 2327 | * Range 1 means on/off control. |
| 2328 | * Other values means the LED is control by PWM. |
| 2329 | */ |
| 2330 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2331 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2332 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2333 | /*****************************************************************************/ |
| 2334 | /* Verified boot commands */ |
| 2335 | |
| 2336 | /* |
| 2337 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 2338 | * reused for other purposes with version > 0. |
| 2339 | */ |
| 2340 | |
| 2341 | /* Verified boot hash command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2342 | #define EC_CMD_VBOOT_HASH 0x002A |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2343 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2344 | struct ec_params_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2345 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 2346 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2347 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 2348 | uint8_t reserved0; /* Reserved; set 0 */ |
| 2349 | uint32_t offset; /* Offset in flash to hash */ |
| 2350 | uint32_t size; /* Number of bytes to hash */ |
| 2351 | 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] | 2352 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2353 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2354 | struct ec_response_vboot_hash { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2355 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 2356 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 2357 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 2358 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 2359 | uint32_t offset; /* Offset in flash which was hashed */ |
| 2360 | uint32_t size; /* Number of bytes hashed */ |
| 2361 | uint8_t hash_digest[64]; /* Hash digest data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2362 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2363 | |
| 2364 | enum ec_vboot_hash_cmd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2365 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 2366 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 2367 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 2368 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2369 | }; |
| 2370 | |
| 2371 | enum ec_vboot_hash_type { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2372 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2373 | }; |
| 2374 | |
| 2375 | enum ec_vboot_hash_status { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2376 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 2377 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 2378 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2379 | }; |
| 2380 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2381 | /* |
| 2382 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 2383 | * If one of these is specified, the EC will automatically update offset and |
| 2384 | * size to the correct values for the specified image (RO or RW). |
| 2385 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2386 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 2387 | #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd |
| 2388 | #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc |
| 2389 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2390 | /* |
| 2391 | * 'RW' is vague if there are multiple RW images; we mean the active one, |
| 2392 | * so the old constant is deprecated. |
| 2393 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2394 | #define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 2395 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 2396 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2397 | /* |
| 2398 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 2399 | * different input args, so that we know how much to expect. |
| 2400 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2401 | #define EC_CMD_MOTION_SENSE_CMD 0x002B |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2402 | |
| 2403 | /* Motion sense commands */ |
| 2404 | enum motionsense_command { |
| 2405 | /* |
| 2406 | * Dump command returns all motion sensor data including motion sense |
| 2407 | * module flags and individual sensor flags. |
| 2408 | */ |
| 2409 | MOTIONSENSE_CMD_DUMP = 0, |
| 2410 | |
| 2411 | /* |
| 2412 | * Info command returns data describing the details of a given sensor, |
| 2413 | * including enum motionsensor_type, enum motionsensor_location, and |
| 2414 | * enum motionsensor_chip. |
| 2415 | */ |
| 2416 | MOTIONSENSE_CMD_INFO = 1, |
| 2417 | |
| 2418 | /* |
| 2419 | * 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] | 2420 | * in milliseconds. |
| 2421 | * It is per sensor, the EC run sample task at the minimum of all |
| 2422 | * sensors EC_RATE. |
| 2423 | * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR |
| 2424 | * to collect all the sensor samples. |
| 2425 | * For sensor with hardware FIFO, EC_RATE is used as the maximal delay |
| 2426 | * to process of all motion sensors in milliseconds. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2427 | */ |
| 2428 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 2429 | |
| 2430 | /* |
| 2431 | * Sensor ODR command is a setter/getter command for the output data |
| 2432 | * rate of a specific motion sensor in millihertz. |
| 2433 | */ |
| 2434 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 2435 | |
| 2436 | /* |
| 2437 | * Sensor range command is a setter/getter command for the range of |
| 2438 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 2439 | */ |
| 2440 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 2441 | |
| 2442 | /* |
| 2443 | * Setter/getter command for the keyboard wake angle. When the lid |
| 2444 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 2445 | * and when the lid angle goes less than this value, keyboard wake is |
| 2446 | * enabled. Note, the lid angle measurement is an approximate, |
| 2447 | * un-calibrated value, hence the wake angle isn't exact. |
| 2448 | */ |
| 2449 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 2450 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2451 | /* |
| 2452 | * Returns a single sensor data. |
| 2453 | */ |
| 2454 | MOTIONSENSE_CMD_DATA = 6, |
| 2455 | |
| 2456 | /* |
| 2457 | * Return sensor fifo info. |
| 2458 | */ |
| 2459 | MOTIONSENSE_CMD_FIFO_INFO = 7, |
| 2460 | |
| 2461 | /* |
| 2462 | * Insert a flush element in the fifo and return sensor fifo info. |
| 2463 | * The host can use that element to synchronize its operation. |
| 2464 | */ |
| 2465 | MOTIONSENSE_CMD_FIFO_FLUSH = 8, |
| 2466 | |
| 2467 | /* |
| 2468 | * Return a portion of the fifo. |
| 2469 | */ |
| 2470 | MOTIONSENSE_CMD_FIFO_READ = 9, |
| 2471 | |
| 2472 | /* |
| 2473 | * Perform low level calibration. |
| 2474 | * On sensors that support it, ask to do offset calibration. |
| 2475 | */ |
| 2476 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 2477 | |
| 2478 | /* |
| 2479 | * Sensor Offset command is a setter/getter command for the offset |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2480 | * used for factory calibration. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2481 | * The offsets can be calculated by the host, or via |
| 2482 | * PERFORM_CALIB command. |
| 2483 | */ |
| 2484 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 2485 | |
| 2486 | /* |
| 2487 | * List available activities for a MOTION sensor. |
| 2488 | * Indicates if they are enabled or disabled. |
| 2489 | */ |
| 2490 | MOTIONSENSE_CMD_LIST_ACTIVITIES = 12, |
| 2491 | |
| 2492 | /* |
| 2493 | * Activity management |
| 2494 | * Enable/Disable activity recognition. |
| 2495 | */ |
| 2496 | MOTIONSENSE_CMD_SET_ACTIVITY = 13, |
| 2497 | |
| 2498 | /* |
| 2499 | * Lid Angle |
| 2500 | */ |
| 2501 | MOTIONSENSE_CMD_LID_ANGLE = 14, |
| 2502 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2503 | /* |
| 2504 | * Allow the FIFO to trigger interrupt via MKBP events. |
| 2505 | * By default the FIFO does not send interrupt to process the FIFO |
| 2506 | * until the AP is ready or it is coming from a wakeup sensor. |
| 2507 | */ |
| 2508 | MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15, |
| 2509 | |
| 2510 | /* |
| 2511 | * Spoof the readings of the sensors. The spoofed readings can be set |
| 2512 | * to arbitrary values, or will lock to the last read actual values. |
| 2513 | */ |
| 2514 | MOTIONSENSE_CMD_SPOOF = 16, |
| 2515 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2516 | /* Set lid angle for tablet mode detection. */ |
| 2517 | MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17, |
| 2518 | |
| 2519 | /* |
| 2520 | * Sensor Scale command is a setter/getter command for the calibration |
| 2521 | * scale. |
| 2522 | */ |
| 2523 | MOTIONSENSE_CMD_SENSOR_SCALE = 18, |
| 2524 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2525 | /* |
| 2526 | * Read the current online calibration values (if available). |
| 2527 | */ |
| 2528 | MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19, |
| 2529 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2530 | /* Number of motionsense sub-commands. */ |
| 2531 | MOTIONSENSE_NUM_CMDS |
| 2532 | }; |
| 2533 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2534 | /* List of motion sensor types. */ |
| 2535 | enum motionsensor_type { |
| 2536 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 2537 | MOTIONSENSE_TYPE_GYRO = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2538 | MOTIONSENSE_TYPE_MAG = 2, |
| 2539 | MOTIONSENSE_TYPE_PROX = 3, |
| 2540 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 2541 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2542 | MOTIONSENSE_TYPE_BARO = 6, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2543 | MOTIONSENSE_TYPE_SYNC = 7, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2544 | MOTIONSENSE_TYPE_LIGHT_RGB = 8, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2545 | MOTIONSENSE_TYPE_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2546 | }; |
| 2547 | |
| 2548 | /* List of motion sensor locations. */ |
| 2549 | enum motionsensor_location { |
| 2550 | MOTIONSENSE_LOC_BASE = 0, |
| 2551 | MOTIONSENSE_LOC_LID = 1, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2552 | MOTIONSENSE_LOC_CAMERA = 2, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2553 | MOTIONSENSE_LOC_MAX, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2554 | }; |
| 2555 | |
| 2556 | /* List of motion sensor chips. */ |
| 2557 | enum motionsensor_chip { |
| 2558 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 2559 | MOTIONSENSE_CHIP_LSM6DS0 = 1, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2560 | MOTIONSENSE_CHIP_BMI160 = 2, |
| 2561 | MOTIONSENSE_CHIP_SI1141 = 3, |
| 2562 | MOTIONSENSE_CHIP_SI1142 = 4, |
| 2563 | MOTIONSENSE_CHIP_SI1143 = 5, |
| 2564 | MOTIONSENSE_CHIP_KX022 = 6, |
| 2565 | MOTIONSENSE_CHIP_L3GD20H = 7, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 2566 | MOTIONSENSE_CHIP_BMA255 = 8, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2567 | MOTIONSENSE_CHIP_BMP280 = 9, |
| 2568 | MOTIONSENSE_CHIP_OPT3001 = 10, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2569 | MOTIONSENSE_CHIP_BH1730 = 11, |
| 2570 | MOTIONSENSE_CHIP_GPIO = 12, |
| 2571 | MOTIONSENSE_CHIP_LIS2DH = 13, |
| 2572 | MOTIONSENSE_CHIP_LSM6DSM = 14, |
| 2573 | MOTIONSENSE_CHIP_LIS2DE = 15, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2574 | MOTIONSENSE_CHIP_LIS2MDL = 16, |
| 2575 | MOTIONSENSE_CHIP_LSM6DS3 = 17, |
| 2576 | MOTIONSENSE_CHIP_LSM6DSO = 18, |
| 2577 | MOTIONSENSE_CHIP_LNG2DM = 19, |
| 2578 | MOTIONSENSE_CHIP_TCS3400 = 20, |
| 2579 | MOTIONSENSE_CHIP_LIS2DW12 = 21, |
| 2580 | MOTIONSENSE_CHIP_LIS2DWL = 22, |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2581 | MOTIONSENSE_CHIP_LIS2DS = 23, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2582 | MOTIONSENSE_CHIP_MAX, |
| 2583 | }; |
| 2584 | |
| 2585 | /* List of orientation positions */ |
| 2586 | enum motionsensor_orientation { |
| 2587 | MOTIONSENSE_ORIENTATION_LANDSCAPE = 0, |
| 2588 | MOTIONSENSE_ORIENTATION_PORTRAIT = 1, |
| 2589 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2, |
| 2590 | MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3, |
| 2591 | MOTIONSENSE_ORIENTATION_UNKNOWN = 4, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2592 | }; |
| 2593 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2594 | struct ec_response_motion_sensor_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2595 | /* Flags for each sensor. */ |
| 2596 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2597 | /* Sensor number the data comes from. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2598 | uint8_t sensor_num; |
| 2599 | /* Each sensor is up to 3-axis. */ |
| 2600 | union { |
| 2601 | int16_t data[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2602 | struct __ec_todo_packed { |
| 2603 | uint16_t reserved; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2604 | uint32_t timestamp; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2605 | }; |
| 2606 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2607 | uint8_t activity; /* motionsensor_activity */ |
| 2608 | uint8_t state; |
| 2609 | int16_t add_info[2]; |
| 2610 | }; |
| 2611 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2612 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2613 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2614 | /* Response to AP reporting calibration data for a given sensor. */ |
| 2615 | struct ec_response_online_calibration_data { |
| 2616 | /** The calibration values. */ |
| 2617 | int16_t data[3]; |
| 2618 | }; |
| 2619 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2620 | /* Note: used in ec_response_get_next_data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2621 | struct ec_response_motion_sense_fifo_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2622 | /* Size of the fifo */ |
| 2623 | uint16_t size; |
| 2624 | /* Amount of space used in the fifo */ |
| 2625 | uint16_t count; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2626 | /* Timestamp recorded in us. |
| 2627 | * aka accurate timestamp when host event was triggered. |
| 2628 | */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2629 | uint32_t timestamp; |
| 2630 | /* Total amount of vector lost */ |
| 2631 | uint16_t total_lost; |
| 2632 | /* Lost events since the last fifo_info, per sensors */ |
| 2633 | uint16_t lost[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2634 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2635 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2636 | struct ec_response_motion_sense_fifo_data { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2637 | uint32_t number_data; |
| 2638 | struct ec_response_motion_sensor_data data[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2639 | } __ec_todo_packed; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2640 | |
| 2641 | /* List supported activity recognition */ |
| 2642 | enum motionsensor_activity { |
| 2643 | MOTIONSENSE_ACTIVITY_RESERVED = 0, |
| 2644 | MOTIONSENSE_ACTIVITY_SIG_MOTION = 1, |
| 2645 | MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2646 | MOTIONSENSE_ACTIVITY_ORIENTATION = 3, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2647 | }; |
| 2648 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2649 | struct ec_motion_sense_activity { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2650 | uint8_t sensor_num; |
| 2651 | uint8_t activity; /* one of enum motionsensor_activity */ |
| 2652 | uint8_t enable; /* 1: enable, 0: disable */ |
| 2653 | uint8_t reserved; |
| 2654 | uint16_t parameters[3]; /* activity dependent parameters */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2655 | } __ec_todo_unpacked; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2656 | |
| 2657 | /* Module flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2658 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2659 | |
| 2660 | /* Sensor flag masks used for the dump sub-command. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2661 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2662 | |
| 2663 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2664 | * Flush entry for synchronization. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2665 | * data contains time stamp |
| 2666 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2667 | #define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0) |
| 2668 | #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1) |
| 2669 | #define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2) |
| 2670 | #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3) |
| 2671 | #define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2672 | |
| 2673 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2674 | * Send this value for the data element to only perform a read. If you |
| 2675 | * send any other value, the EC will interpret it as data to set and will |
| 2676 | * return the actual value set. |
| 2677 | */ |
| 2678 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 2679 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2680 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 2681 | |
| 2682 | /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */ |
| 2683 | /* Set Calibration information */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2684 | #define MOTION_SENSE_SET_OFFSET BIT(0) |
| 2685 | |
| 2686 | /* Default Scale value, factor 1. */ |
| 2687 | #define MOTION_SENSE_DEFAULT_SCALE BIT(15) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2688 | |
| 2689 | #define LID_ANGLE_UNRELIABLE 500 |
| 2690 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2691 | enum motionsense_spoof_mode { |
| 2692 | /* Disable spoof mode. */ |
| 2693 | MOTIONSENSE_SPOOF_MODE_DISABLE = 0, |
| 2694 | |
| 2695 | /* Enable spoof mode, but use provided component values. */ |
| 2696 | MOTIONSENSE_SPOOF_MODE_CUSTOM, |
| 2697 | |
| 2698 | /* Enable spoof mode, but use the current sensor values. */ |
| 2699 | MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT, |
| 2700 | |
| 2701 | /* Query the current spoof mode status for the sensor. */ |
| 2702 | MOTIONSENSE_SPOOF_MODE_QUERY, |
| 2703 | }; |
| 2704 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2705 | struct ec_params_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2706 | uint8_t cmd; |
| 2707 | union { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2708 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2709 | struct __ec_todo_unpacked { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2710 | /* |
| 2711 | * Maximal number of sensor the host is expecting. |
| 2712 | * 0 means the host is only interested in the number |
| 2713 | * of sensors controlled by the EC. |
| 2714 | */ |
| 2715 | uint8_t max_sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2716 | } dump; |
| 2717 | |
| 2718 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2719 | * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2720 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2721 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2722 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. |
| 2723 | * kb_wake_angle: angle to wakup AP. |
| 2724 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2725 | int16_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2726 | } kb_wake_angle; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2727 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2728 | /* |
| 2729 | * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA |
| 2730 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2731 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2732 | uint8_t sensor_num; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2733 | } info, info_3, info_4, data, fifo_flush, list_activities; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2734 | |
| 2735 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2736 | * Used for MOTIONSENSE_CMD_PERFORM_CALIB: |
| 2737 | * Allow entering/exiting the calibration mode. |
| 2738 | */ |
| 2739 | struct __ec_todo_unpacked { |
| 2740 | uint8_t sensor_num; |
| 2741 | uint8_t enable; |
| 2742 | } perform_calib; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2743 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2744 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2745 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR |
| 2746 | * and MOTIONSENSE_CMD_SENSOR_RANGE. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2747 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2748 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2749 | uint8_t sensor_num; |
| 2750 | |
| 2751 | /* Rounding flag, true for round-up, false for down. */ |
| 2752 | uint8_t roundup; |
| 2753 | |
| 2754 | uint16_t reserved; |
| 2755 | |
| 2756 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 2757 | int32_t data; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2758 | } ec_rate, sensor_odr, sensor_range; |
| 2759 | |
| 2760 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2761 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2762 | uint8_t sensor_num; |
| 2763 | |
| 2764 | /* |
| 2765 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2766 | * the calibration information in the EC. |
| 2767 | * If unset, just retrieve calibration information. |
| 2768 | */ |
| 2769 | uint16_t flags; |
| 2770 | |
| 2771 | /* |
| 2772 | * Temperature at calibration, in units of 0.01 C |
| 2773 | * 0x8000: invalid / unknown. |
| 2774 | * 0x0: 0C |
| 2775 | * 0x7fff: +327.67C |
| 2776 | */ |
| 2777 | int16_t temp; |
| 2778 | |
| 2779 | /* |
| 2780 | * Offset for calibration. |
| 2781 | * Unit: |
| 2782 | * Accelerometer: 1/1024 g |
| 2783 | * Gyro: 1/1024 deg/s |
| 2784 | * Compass: 1/16 uT |
| 2785 | */ |
| 2786 | int16_t offset[3]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2787 | } sensor_offset; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2788 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2789 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2790 | struct __ec_todo_packed { |
| 2791 | uint8_t sensor_num; |
| 2792 | |
| 2793 | /* |
| 2794 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 2795 | * the calibration information in the EC. |
| 2796 | * If unset, just retrieve calibration information. |
| 2797 | */ |
| 2798 | uint16_t flags; |
| 2799 | |
| 2800 | /* |
| 2801 | * Temperature at calibration, in units of 0.01 C |
| 2802 | * 0x8000: invalid / unknown. |
| 2803 | * 0x0: 0C |
| 2804 | * 0x7fff: +327.67C |
| 2805 | */ |
| 2806 | int16_t temp; |
| 2807 | |
| 2808 | /* |
| 2809 | * Scale for calibration: |
| 2810 | * By default scale is 1, it is encoded on 16bits: |
| 2811 | * 1 = BIT(15) |
| 2812 | * ~2 = 0xFFFF |
| 2813 | * ~0 = 0. |
| 2814 | */ |
| 2815 | uint16_t scale[3]; |
| 2816 | } sensor_scale; |
| 2817 | |
| 2818 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2819 | /* Used for MOTIONSENSE_CMD_FIFO_INFO */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2820 | /* (no params) */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2821 | |
| 2822 | /* Used for MOTIONSENSE_CMD_FIFO_READ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2823 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2824 | /* |
| 2825 | * Number of expected vector to return. |
| 2826 | * EC may return less or 0 if none available. |
| 2827 | */ |
| 2828 | uint32_t max_data_vector; |
| 2829 | } fifo_read; |
| 2830 | |
| 2831 | struct ec_motion_sense_activity set_activity; |
| 2832 | |
| 2833 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 2834 | /* (no params) */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2835 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2836 | /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */ |
| 2837 | struct __ec_todo_unpacked { |
| 2838 | /* |
| 2839 | * 1: enable, 0 disable fifo, |
| 2840 | * EC_MOTION_SENSE_NO_VALUE return value. |
| 2841 | */ |
| 2842 | int8_t enable; |
| 2843 | } fifo_int_enable; |
| 2844 | |
| 2845 | /* Used for MOTIONSENSE_CMD_SPOOF */ |
| 2846 | struct __ec_todo_packed { |
| 2847 | uint8_t sensor_id; |
| 2848 | |
| 2849 | /* See enum motionsense_spoof_mode. */ |
| 2850 | uint8_t spoof_enable; |
| 2851 | |
| 2852 | /* Ignored, used for alignment. */ |
| 2853 | uint8_t reserved; |
| 2854 | |
| 2855 | /* Individual component values to spoof. */ |
| 2856 | int16_t components[3]; |
| 2857 | } spoof; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2858 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2859 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 2860 | struct __ec_todo_unpacked { |
| 2861 | /* |
| 2862 | * Lid angle threshold for switching between tablet and |
| 2863 | * clamshell mode. |
| 2864 | */ |
| 2865 | int16_t lid_angle; |
| 2866 | |
| 2867 | /* |
| 2868 | * Hysteresis degree to prevent fluctuations between |
| 2869 | * clamshell and tablet mode if lid angle keeps |
| 2870 | * changing around the threshold. Lid motion driver will |
| 2871 | * use lid_angle + hys_degree to trigger tablet mode and |
| 2872 | * lid_angle - hys_degree to trigger clamshell mode. |
| 2873 | */ |
| 2874 | int16_t hys_degree; |
| 2875 | } tablet_mode_threshold; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 2876 | |
| 2877 | /* |
| 2878 | * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ: |
| 2879 | * Allow reading a single sensor's online calibration value. |
| 2880 | */ |
| 2881 | struct __ec_todo_unpacked { |
| 2882 | uint8_t sensor_num; |
| 2883 | } online_calib_read; |
| 2884 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2885 | }; |
| 2886 | } __ec_todo_packed; |
| 2887 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 2888 | enum motion_sense_cmd_info_flags { |
| 2889 | /* The sensor supports online calibration */ |
| 2890 | MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0), |
| 2891 | }; |
| 2892 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2893 | struct ec_response_motion_sense { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2894 | union { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2895 | /* Used for MOTIONSENSE_CMD_DUMP */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2896 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2897 | /* Flags representing the motion sensor module. */ |
| 2898 | uint8_t module_flags; |
| 2899 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2900 | /* Number of sensors managed directly by the EC. */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2901 | uint8_t sensor_count; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2902 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2903 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2904 | * Sensor data is truncated if response_max is too small |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 2905 | * for holding all the data. |
| 2906 | */ |
| 2907 | struct ec_response_motion_sensor_data sensor[0]; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2908 | } dump; |
| 2909 | |
| 2910 | /* Used for MOTIONSENSE_CMD_INFO. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2911 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2912 | /* Should be element of enum motionsensor_type. */ |
| 2913 | uint8_t type; |
| 2914 | |
| 2915 | /* Should be element of enum motionsensor_location. */ |
| 2916 | uint8_t location; |
| 2917 | |
| 2918 | /* Should be element of enum motionsensor_chip. */ |
| 2919 | uint8_t chip; |
| 2920 | } info; |
| 2921 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2922 | /* Used for MOTIONSENSE_CMD_INFO version 3 */ |
| 2923 | struct __ec_todo_unpacked { |
| 2924 | /* Should be element of enum motionsensor_type. */ |
| 2925 | uint8_t type; |
| 2926 | |
| 2927 | /* Should be element of enum motionsensor_location. */ |
| 2928 | uint8_t location; |
| 2929 | |
| 2930 | /* Should be element of enum motionsensor_chip. */ |
| 2931 | uint8_t chip; |
| 2932 | |
| 2933 | /* Minimum sensor sampling frequency */ |
| 2934 | uint32_t min_frequency; |
| 2935 | |
| 2936 | /* Maximum sensor sampling frequency */ |
| 2937 | uint32_t max_frequency; |
| 2938 | |
| 2939 | /* Max number of sensor events that could be in fifo */ |
| 2940 | uint32_t fifo_max_event_count; |
| 2941 | } info_3; |
| 2942 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 2943 | /* Used for MOTIONSENSE_CMD_INFO version 4 */ |
| 2944 | struct __ec_align4 { |
| 2945 | /* Should be element of enum motionsensor_type. */ |
| 2946 | uint8_t type; |
| 2947 | |
| 2948 | /* Should be element of enum motionsensor_location. */ |
| 2949 | uint8_t location; |
| 2950 | |
| 2951 | /* Should be element of enum motionsensor_chip. */ |
| 2952 | uint8_t chip; |
| 2953 | |
| 2954 | /* Minimum sensor sampling frequency */ |
| 2955 | uint32_t min_frequency; |
| 2956 | |
| 2957 | /* Maximum sensor sampling frequency */ |
| 2958 | uint32_t max_frequency; |
| 2959 | |
| 2960 | /* Max number of sensor events that could be in fifo */ |
| 2961 | uint32_t fifo_max_event_count; |
| 2962 | |
| 2963 | /* |
| 2964 | * Should be elements of |
| 2965 | * enum motion_sense_cmd_info_flags |
| 2966 | */ |
| 2967 | uint32_t flags; |
| 2968 | } info_4; |
| 2969 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2970 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 2971 | struct ec_response_motion_sensor_data data; |
| 2972 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2973 | /* |
| 2974 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2975 | * MOTIONSENSE_CMD_SENSOR_RANGE, |
| 2976 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE, |
| 2977 | * MOTIONSENSE_CMD_FIFO_INT_ENABLE and |
| 2978 | * MOTIONSENSE_CMD_SPOOF. |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2979 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2980 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 2981 | /* Current value of the parameter queried. */ |
| 2982 | int32_t ret; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2983 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle, |
| 2984 | fifo_int_enable, spoof; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2985 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2986 | /* |
| 2987 | * Used for MOTIONSENSE_CMD_SENSOR_OFFSET, |
| 2988 | * PERFORM_CALIB. |
| 2989 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 2990 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 2991 | int16_t temp; |
| 2992 | int16_t offset[3]; |
| 2993 | } sensor_offset, perform_calib; |
| 2994 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 2995 | /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */ |
| 2996 | struct __ec_todo_unpacked { |
| 2997 | int16_t temp; |
| 2998 | uint16_t scale[3]; |
| 2999 | } sensor_scale; |
| 3000 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3001 | struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush; |
| 3002 | |
| 3003 | struct ec_response_motion_sense_fifo_data fifo_read; |
| 3004 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3005 | struct ec_response_online_calibration_data online_calib_read; |
| 3006 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3007 | struct __ec_todo_packed { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3008 | uint16_t reserved; |
| 3009 | uint32_t enabled; |
| 3010 | uint32_t disabled; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3011 | } list_activities; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3012 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3013 | /* No params for set activity */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3014 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3015 | /* Used for MOTIONSENSE_CMD_LID_ANGLE */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3016 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3017 | /* |
| 3018 | * Angle between 0 and 360 degree if available, |
| 3019 | * LID_ANGLE_UNRELIABLE otherwise. |
| 3020 | */ |
| 3021 | uint16_t value; |
| 3022 | } lid_angle; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3023 | |
| 3024 | /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */ |
| 3025 | struct __ec_todo_unpacked { |
| 3026 | /* |
| 3027 | * Lid angle threshold for switching between tablet and |
| 3028 | * clamshell mode. |
| 3029 | */ |
| 3030 | uint16_t lid_angle; |
| 3031 | |
| 3032 | /* Hysteresis degree. */ |
| 3033 | uint16_t hys_degree; |
| 3034 | } tablet_mode_threshold; |
| 3035 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3036 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3037 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3038 | |
| 3039 | /*****************************************************************************/ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3040 | /* Force lid open command */ |
| 3041 | |
| 3042 | /* Make lid event always open */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3043 | #define EC_CMD_FORCE_LID_OPEN 0x002C |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3044 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3045 | struct ec_params_force_lid_open { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3046 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3047 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3048 | |
| 3049 | /*****************************************************************************/ |
| 3050 | /* Configure the behavior of the power button */ |
| 3051 | #define EC_CMD_CONFIG_POWER_BUTTON 0x002D |
| 3052 | |
| 3053 | enum ec_config_power_button_flags { |
| 3054 | /* Enable/Disable power button pulses for x86 devices */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3055 | EC_POWER_BUTTON_ENABLE_PULSE = BIT(0), |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3056 | }; |
| 3057 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3058 | struct ec_params_config_power_button { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3059 | /* See enum ec_config_power_button_flags */ |
| 3060 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3061 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3062 | |
| 3063 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3064 | /* USB charging control commands */ |
| 3065 | |
| 3066 | /* Set USB port charging mode */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3067 | #define EC_CMD_USB_CHARGE_SET_MODE 0x0030 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3068 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3069 | enum usb_charge_mode { |
| 3070 | /* Disable USB port. */ |
| 3071 | USB_CHARGE_MODE_DISABLED, |
| 3072 | /* Set USB port to Standard Downstream Port, USB 2.0 mode. */ |
| 3073 | USB_CHARGE_MODE_SDP2, |
| 3074 | /* Set USB port to Charging Downstream Port, BC 1.2. */ |
| 3075 | USB_CHARGE_MODE_CDP, |
| 3076 | /* Set USB port to Dedicated Charging Port, BC 1.2. */ |
| 3077 | USB_CHARGE_MODE_DCP_SHORT, |
| 3078 | /* Enable USB port (for dumb ports). */ |
| 3079 | USB_CHARGE_MODE_ENABLED, |
| 3080 | /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */ |
| 3081 | USB_CHARGE_MODE_DEFAULT, |
| 3082 | |
| 3083 | USB_CHARGE_MODE_COUNT |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3084 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3085 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3086 | enum usb_suspend_charge { |
| 3087 | /* Enable charging in suspend */ |
| 3088 | USB_ALLOW_SUSPEND_CHARGE, |
| 3089 | /* Disable charging in suspend */ |
| 3090 | USB_DISALLOW_SUSPEND_CHARGE |
| 3091 | }; |
| 3092 | |
| 3093 | struct ec_params_usb_charge_set_mode { |
| 3094 | uint8_t usb_port_id; |
| 3095 | uint8_t mode:7; /* enum usb_charge_mode */ |
| 3096 | uint8_t inhibit_charge:1; /* enum usb_suspend_charge */ |
| 3097 | } __ec_align1; |
| 3098 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3099 | /*****************************************************************************/ |
| 3100 | /* Persistent storage for host */ |
| 3101 | |
| 3102 | /* Maximum bytes that can be read/written in a single command */ |
| 3103 | #define EC_PSTORE_SIZE_MAX 64 |
| 3104 | |
| 3105 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3106 | #define EC_CMD_PSTORE_INFO 0x0040 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3107 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3108 | struct ec_response_pstore_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3109 | /* Persistent storage size, in bytes */ |
| 3110 | uint32_t pstore_size; |
| 3111 | /* Access size; read/write offset and size must be a multiple of this */ |
| 3112 | uint32_t access_size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3113 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3114 | |
| 3115 | /* |
| 3116 | * Read persistent storage |
| 3117 | * |
| 3118 | * Response is params.size bytes of data. |
| 3119 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3120 | #define EC_CMD_PSTORE_READ 0x0041 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3121 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3122 | struct ec_params_pstore_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3123 | uint32_t offset; /* Byte offset to read */ |
| 3124 | uint32_t size; /* Size to read in bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3125 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3126 | |
| 3127 | /* Write persistent storage */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3128 | #define EC_CMD_PSTORE_WRITE 0x0042 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3129 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3130 | struct ec_params_pstore_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3131 | uint32_t offset; /* Byte offset to write */ |
| 3132 | uint32_t size; /* Size to write in bytes */ |
| 3133 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3134 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3135 | |
| 3136 | /*****************************************************************************/ |
| 3137 | /* Real-time clock */ |
| 3138 | |
| 3139 | /* RTC params and response structures */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3140 | struct ec_params_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3141 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3142 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3143 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3144 | struct ec_response_rtc { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3145 | uint32_t time; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3146 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3147 | |
| 3148 | /* These use ec_response_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3149 | #define EC_CMD_RTC_GET_VALUE 0x0044 |
| 3150 | #define EC_CMD_RTC_GET_ALARM 0x0045 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3151 | |
| 3152 | /* These all use ec_params_rtc */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3153 | #define EC_CMD_RTC_SET_VALUE 0x0046 |
| 3154 | #define EC_CMD_RTC_SET_ALARM 0x0047 |
| 3155 | |
| 3156 | /* Pass as time param to SET_ALARM to clear the current alarm */ |
| 3157 | #define EC_RTC_ALARM_CLEAR 0 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3158 | |
| 3159 | /*****************************************************************************/ |
| 3160 | /* Port80 log access */ |
| 3161 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3162 | /* Maximum entries that can be read/written in a single command */ |
| 3163 | #define EC_PORT80_SIZE_MAX 32 |
| 3164 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3165 | /* Get last port80 code from previous boot */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3166 | #define EC_CMD_PORT80_LAST_BOOT 0x0048 |
| 3167 | #define EC_CMD_PORT80_READ 0x0048 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3168 | |
| 3169 | enum ec_port80_subcmd { |
| 3170 | EC_PORT80_GET_INFO = 0, |
| 3171 | EC_PORT80_READ_BUFFER, |
| 3172 | }; |
| 3173 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3174 | struct ec_params_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3175 | uint16_t subcmd; |
| 3176 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3177 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3178 | uint32_t offset; |
| 3179 | uint32_t num_entries; |
| 3180 | } read_buffer; |
| 3181 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3182 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3183 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3184 | struct ec_response_port80_read { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3185 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3186 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3187 | uint32_t writes; |
| 3188 | uint32_t history_size; |
| 3189 | uint32_t last_boot; |
| 3190 | } get_info; |
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 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 3193 | } data; |
| 3194 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3195 | } __ec_todo_packed; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3196 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3197 | struct ec_response_port80_last_boot { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3198 | uint16_t code; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3199 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3200 | |
| 3201 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3202 | /* Temporary secure storage for host verified boot use */ |
| 3203 | |
| 3204 | /* Number of bytes in a vstore slot */ |
| 3205 | #define EC_VSTORE_SLOT_SIZE 64 |
| 3206 | |
| 3207 | /* Maximum number of vstore slots */ |
| 3208 | #define EC_VSTORE_SLOT_MAX 32 |
| 3209 | |
| 3210 | /* Get persistent storage info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3211 | #define EC_CMD_VSTORE_INFO 0x0049 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3212 | struct ec_response_vstore_info { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3213 | /* Indicates which slots are locked */ |
| 3214 | uint32_t slot_locked; |
| 3215 | /* Total number of slots available */ |
| 3216 | uint8_t slot_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3217 | } __ec_align_size1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3218 | |
| 3219 | /* |
| 3220 | * Read temporary secure storage |
| 3221 | * |
| 3222 | * Response is EC_VSTORE_SLOT_SIZE bytes of data. |
| 3223 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3224 | #define EC_CMD_VSTORE_READ 0x004A |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3225 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3226 | struct ec_params_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3227 | uint8_t slot; /* Slot to read from */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3228 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3229 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3230 | struct ec_response_vstore_read { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3231 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3232 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3233 | |
| 3234 | /* |
| 3235 | * Write temporary secure storage and lock it. |
| 3236 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3237 | #define EC_CMD_VSTORE_WRITE 0x004B |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3238 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3239 | struct ec_params_vstore_write { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3240 | uint8_t slot; /* Slot to write to */ |
| 3241 | uint8_t data[EC_VSTORE_SLOT_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3242 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3243 | |
| 3244 | /*****************************************************************************/ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3245 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 3246 | * reuse the command number, but the data and behavior is incompatible. |
| 3247 | * Version 0 is what originally shipped on Link. |
| 3248 | * Version 1 separates the CPU thermal limits from the fan control. |
| 3249 | */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3250 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3251 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050 |
| 3252 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3253 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3254 | /* The version 0 structs are opaque. You have to know what they are for |
| 3255 | * the get/set commands to make any sense. |
| 3256 | */ |
| 3257 | |
| 3258 | /* Version 0 - set */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3259 | struct ec_params_thermal_set_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3260 | uint8_t sensor_type; |
| 3261 | uint8_t threshold_id; |
| 3262 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3263 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3264 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3265 | /* Version 0 - get */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3266 | struct ec_params_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3267 | uint8_t sensor_type; |
| 3268 | uint8_t threshold_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3269 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3270 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3271 | struct ec_response_thermal_get_threshold { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3272 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3273 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3274 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3275 | |
| 3276 | /* The version 1 structs are visible. */ |
| 3277 | enum ec_temp_thresholds { |
| 3278 | EC_TEMP_THRESH_WARN = 0, |
| 3279 | EC_TEMP_THRESH_HIGH, |
| 3280 | EC_TEMP_THRESH_HALT, |
| 3281 | |
| 3282 | EC_TEMP_THRESH_COUNT |
| 3283 | }; |
| 3284 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3285 | /* |
| 3286 | * Thermal configuration for one temperature sensor. Temps are in degrees K. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3287 | * Zero values will be silently ignored by the thermal task. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3288 | * |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3289 | * Set 'temp_host' value allows thermal task to trigger some event with 1 degree |
| 3290 | * hysteresis. |
| 3291 | * For example, |
| 3292 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3293 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K |
| 3294 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3295 | * temperature <= 299 K. |
| 3296 | * |
| 3297 | * Set 'temp_host_release' value allows thermal task has a custom hysteresis. |
| 3298 | * For example, |
| 3299 | * temp_host[EC_TEMP_THRESH_HIGH] = 300 K |
| 3300 | * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K |
| 3301 | * EC will throttle ap when temperature >= 301 K, and release throttling when |
| 3302 | * temperature <= 294 K. |
| 3303 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3304 | * Note that this structure is a sub-structure of |
| 3305 | * ec_params_thermal_set_threshold_v1, but maintains its alignment there. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3306 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3307 | struct ec_thermal_config { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3308 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3309 | uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */ |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3310 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 3311 | uint32_t temp_fan_max; /* max active cooling needed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3312 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3313 | |
| 3314 | /* Version 1 - get config for one sensor. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3315 | struct ec_params_thermal_get_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3316 | uint32_t sensor_num; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3317 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3318 | /* This returns a struct ec_thermal_config */ |
| 3319 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3320 | /* |
| 3321 | * Version 1 - set config for one sensor. |
| 3322 | * Use read-modify-write for best results! |
| 3323 | */ |
| 3324 | struct ec_params_thermal_set_threshold_v1 { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3325 | uint32_t sensor_num; |
| 3326 | struct ec_thermal_config cfg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3327 | } __ec_align4; |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 3328 | /* This returns no data */ |
| 3329 | |
| 3330 | /****************************************************************************/ |
| 3331 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3332 | /* Toggle automatic fan control */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3333 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3334 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3335 | /* Version 1 of input params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3336 | struct ec_params_auto_fan_ctrl_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3337 | uint8_t fan_idx; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3338 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3339 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3340 | /* Get/Set TMP006 calibration data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3341 | #define EC_CMD_TMP006_GET_CALIBRATION 0x0053 |
| 3342 | #define EC_CMD_TMP006_SET_CALIBRATION 0x0054 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3343 | |
| 3344 | /* |
| 3345 | * The original TMP006 calibration only needed four params, but now we need |
| 3346 | * more. Since the algorithm is nothing but magic numbers anyway, we'll leave |
| 3347 | * the params opaque. The v1 "get" response will include the algorithm number |
| 3348 | * and how many params it requires. That way we can change the EC code without |
| 3349 | * needing to update this file. We can also use a different algorithm on each |
| 3350 | * sensor. |
| 3351 | */ |
| 3352 | |
| 3353 | /* This is the same struct for both v0 and v1. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3354 | struct ec_params_tmp006_get_calibration { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3355 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3356 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3357 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3358 | /* Version 0 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3359 | struct ec_response_tmp006_get_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3360 | float s0; |
| 3361 | float b0; |
| 3362 | float b1; |
| 3363 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3364 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3365 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3366 | struct ec_params_tmp006_set_calibration_v0 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3367 | uint8_t index; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3368 | uint8_t reserved[3]; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3369 | float s0; |
| 3370 | float b0; |
| 3371 | float b1; |
| 3372 | float b2; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3373 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3374 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3375 | /* Version 1 */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3376 | struct ec_response_tmp006_get_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3377 | uint8_t algorithm; |
| 3378 | uint8_t num_params; |
| 3379 | uint8_t reserved[2]; |
| 3380 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3381 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3382 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3383 | struct ec_params_tmp006_set_calibration_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3384 | uint8_t index; |
| 3385 | uint8_t algorithm; |
| 3386 | uint8_t num_params; |
| 3387 | uint8_t reserved; |
| 3388 | float val[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3389 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3390 | |
| 3391 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3392 | /* Read raw TMP006 data */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3393 | #define EC_CMD_TMP006_GET_RAW 0x0055 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3394 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3395 | struct ec_params_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3396 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3397 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3398 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3399 | struct ec_response_tmp006_get_raw { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3400 | int32_t t; /* In 1/100 K */ |
| 3401 | int32_t v; /* In nV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3402 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3403 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3404 | /*****************************************************************************/ |
| 3405 | /* MKBP - Matrix KeyBoard Protocol */ |
| 3406 | |
| 3407 | /* |
| 3408 | * Read key state |
| 3409 | * |
| 3410 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 3411 | * expected response size. |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3412 | * |
| 3413 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 3414 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 3415 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3416 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3417 | #define EC_CMD_MKBP_STATE 0x0060 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3418 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3419 | /* |
| 3420 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 3421 | */ |
| 3422 | #define EC_CMD_MKBP_INFO 0x0061 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3423 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3424 | struct ec_response_mkbp_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3425 | uint32_t rows; |
| 3426 | uint32_t cols; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3427 | /* Formerly "switches", which was 0. */ |
| 3428 | uint8_t reserved; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3429 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3430 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3431 | struct ec_params_mkbp_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3432 | uint8_t info_type; |
| 3433 | uint8_t event_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3434 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3435 | |
| 3436 | enum ec_mkbp_info_type { |
| 3437 | /* |
| 3438 | * Info about the keyboard matrix: number of rows and columns. |
| 3439 | * |
| 3440 | * Returns struct ec_response_mkbp_info. |
| 3441 | */ |
| 3442 | EC_MKBP_INFO_KBD = 0, |
| 3443 | |
| 3444 | /* |
| 3445 | * For buttons and switches, info about which specifically are |
| 3446 | * supported. event_type must be set to one of the values in enum |
| 3447 | * ec_mkbp_event. |
| 3448 | * |
| 3449 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 3450 | * bitmask indicating which buttons or switches are present. See the |
| 3451 | * bit inidices below. |
| 3452 | */ |
| 3453 | EC_MKBP_INFO_SUPPORTED = 1, |
| 3454 | |
| 3455 | /* |
| 3456 | * Instantaneous state of buttons and switches. |
| 3457 | * |
| 3458 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 3459 | * |
| 3460 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 3461 | * indicating the current state of the keyboard matrix. |
| 3462 | * |
| 3463 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 3464 | * event state. |
| 3465 | * |
| 3466 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 3467 | * state of supported buttons. |
| 3468 | * |
| 3469 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 3470 | * state of supported switches. |
| 3471 | */ |
| 3472 | EC_MKBP_INFO_CURRENT = 2, |
| 3473 | }; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3474 | |
| 3475 | /* Simulate key press */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3476 | #define EC_CMD_MKBP_SIMULATE_KEY 0x0062 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3477 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3478 | struct ec_params_mkbp_simulate_key { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3479 | uint8_t col; |
| 3480 | uint8_t row; |
| 3481 | uint8_t pressed; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3482 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3483 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3484 | #define EC_CMD_GET_KEYBOARD_ID 0x0063 |
| 3485 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3486 | struct ec_response_keyboard_id { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3487 | uint32_t keyboard_id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3488 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3489 | |
| 3490 | enum keyboard_id { |
| 3491 | KEYBOARD_ID_UNSUPPORTED = 0, |
| 3492 | KEYBOARD_ID_UNREADABLE = 0xffffffff, |
| 3493 | }; |
| 3494 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3495 | /* Configure keyboard scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3496 | #define EC_CMD_MKBP_SET_CONFIG 0x0064 |
| 3497 | #define EC_CMD_MKBP_GET_CONFIG 0x0065 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3498 | |
| 3499 | /* flags */ |
| 3500 | enum mkbp_config_flags { |
| 3501 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 3502 | }; |
| 3503 | |
| 3504 | enum mkbp_config_valid { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3505 | EC_MKBP_VALID_SCAN_PERIOD = BIT(0), |
| 3506 | EC_MKBP_VALID_POLL_TIMEOUT = BIT(1), |
| 3507 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3), |
| 3508 | EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4), |
| 3509 | EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5), |
| 3510 | EC_MKBP_VALID_DEBOUNCE_UP = BIT(6), |
| 3511 | EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3512 | }; |
| 3513 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3514 | /* |
| 3515 | * Configuration for our key scanning algorithm. |
| 3516 | * |
| 3517 | * Note that this is used as a sub-structure of |
| 3518 | * ec_{params/response}_mkbp_get_config. |
| 3519 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3520 | struct ec_mkbp_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3521 | uint32_t valid_mask; /* valid fields */ |
| 3522 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 3523 | uint8_t valid_flags; /* which flags are valid */ |
| 3524 | uint16_t scan_period_us; /* period between start of scans */ |
| 3525 | /* revert to interrupt mode after no activity for this long */ |
| 3526 | uint32_t poll_timeout_us; |
| 3527 | /* |
| 3528 | * minimum post-scan relax time. Once we finish a scan we check |
| 3529 | * the time until we are due to start the next one. If this time is |
| 3530 | * shorter this field, we use this instead. |
| 3531 | */ |
| 3532 | uint16_t min_post_scan_delay_us; |
| 3533 | /* delay between setting up output and waiting for it to settle */ |
| 3534 | uint16_t output_settle_us; |
| 3535 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 3536 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 3537 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 3538 | uint8_t fifo_max_depth; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3539 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3540 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3541 | struct ec_params_mkbp_set_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3542 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3543 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3544 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3545 | struct ec_response_mkbp_get_config { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3546 | struct ec_mkbp_config config; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3547 | } __ec_align_size1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3548 | |
| 3549 | /* Run the key scan emulation */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3550 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3551 | |
| 3552 | enum ec_keyscan_seq_cmd { |
| 3553 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 3554 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 3555 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 3556 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 3557 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 3558 | }; |
| 3559 | |
| 3560 | enum ec_collect_flags { |
| 3561 | /* |
| 3562 | * Indicates this scan was processed by the EC. Due to timing, some |
| 3563 | * scans may be skipped. |
| 3564 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3565 | EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0), |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3566 | }; |
| 3567 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3568 | struct ec_collect_item { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3569 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3570 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3571 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3572 | struct ec_params_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3573 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 3574 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3575 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3576 | uint8_t active; /* still active */ |
| 3577 | uint8_t num_items; /* number of items */ |
| 3578 | /* Current item being presented */ |
| 3579 | uint8_t cur_item; |
| 3580 | } status; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3581 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3582 | /* |
| 3583 | * Absolute time for this scan, measured from the |
| 3584 | * start of the sequence. |
| 3585 | */ |
| 3586 | uint32_t time_us; |
| 3587 | uint8_t scan[0]; /* keyscan data */ |
| 3588 | } add; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3589 | struct __ec_align1 { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3590 | uint8_t start_item; /* First item to return */ |
| 3591 | uint8_t num_items; /* Number of items to return */ |
| 3592 | } collect; |
| 3593 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3594 | } __ec_todo_packed; |
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_result_keyscan_seq_ctrl { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3597 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3598 | struct __ec_todo_unpacked { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3599 | uint8_t num_items; /* Number of items */ |
| 3600 | /* Data for each item */ |
| 3601 | struct ec_collect_item item[0]; |
| 3602 | } collect; |
| 3603 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3604 | } __ec_todo_packed; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 3605 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3606 | /* |
| 3607 | * Get the next pending MKBP event. |
| 3608 | * |
| 3609 | * Returns EC_RES_UNAVAILABLE if there is no event pending. |
| 3610 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3611 | #define EC_CMD_GET_NEXT_EVENT 0x0067 |
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 | #define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7 |
| 3614 | |
| 3615 | /* |
| 3616 | * We use the most significant bit of the event type to indicate to the host |
| 3617 | * that the EC has more MKBP events available to provide. |
| 3618 | */ |
| 3619 | #define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) |
| 3620 | |
| 3621 | /* The mask to apply to get the raw event type */ |
| 3622 | #define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1) |
| 3623 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3624 | enum ec_mkbp_event { |
| 3625 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 3626 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 3627 | |
| 3628 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 3629 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 3630 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3631 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 3632 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 3633 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3634 | /* The state of the non-matrixed buttons have changed. */ |
| 3635 | EC_MKBP_EVENT_BUTTON = 3, |
| 3636 | |
| 3637 | /* The state of the switches have changed. */ |
| 3638 | EC_MKBP_EVENT_SWITCH = 4, |
| 3639 | |
| 3640 | /* New Fingerprint sensor event, the event data is fp_events bitmap. */ |
| 3641 | EC_MKBP_EVENT_FINGERPRINT = 5, |
| 3642 | |
| 3643 | /* |
| 3644 | * Sysrq event: send emulated sysrq. The event data is sysrq, |
| 3645 | * corresponding to the key to be pressed. |
| 3646 | */ |
| 3647 | EC_MKBP_EVENT_SYSRQ = 6, |
| 3648 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3649 | /* |
| 3650 | * New 64-bit host event. |
| 3651 | * The event data is 8 bytes of host event flags. |
| 3652 | */ |
| 3653 | EC_MKBP_EVENT_HOST_EVENT64 = 7, |
| 3654 | |
| 3655 | /* Notify the AP that something happened on CEC */ |
| 3656 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 3657 | |
| 3658 | /* Send an incoming CEC message to the AP */ |
| 3659 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 3660 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3661 | /* We have entered DisplayPort Alternate Mode on a Type-C port. */ |
| 3662 | EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10, |
| 3663 | |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 3664 | /* New online calibration values are available. */ |
| 3665 | EC_MKBP_EVENT_ONLINE_CALIBRATION = 11, |
| 3666 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3667 | /* Number of MKBP events */ |
| 3668 | EC_MKBP_EVENT_COUNT, |
| 3669 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3670 | BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK); |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3671 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3672 | union __ec_align_offset1 ec_response_get_next_data { |
| 3673 | uint8_t key_matrix[13]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3674 | |
| 3675 | /* Unaligned */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3676 | uint32_t host_event; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3677 | uint64_t host_event64; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3678 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3679 | struct __ec_todo_unpacked { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3680 | /* For aligning the fifo_info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3681 | uint8_t reserved[3]; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3682 | struct ec_response_motion_sense_fifo_info info; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3683 | } sensor_fifo; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3684 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3685 | uint32_t buttons; |
| 3686 | |
| 3687 | uint32_t switches; |
| 3688 | |
| 3689 | uint32_t fp_events; |
| 3690 | |
| 3691 | uint32_t sysrq; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3692 | |
| 3693 | /* CEC events from enum mkbp_cec_event */ |
| 3694 | uint32_t cec_events; |
| 3695 | }; |
| 3696 | |
| 3697 | union __ec_align_offset1 ec_response_get_next_data_v1 { |
| 3698 | uint8_t key_matrix[16]; |
| 3699 | |
| 3700 | /* Unaligned */ |
| 3701 | uint32_t host_event; |
| 3702 | uint64_t host_event64; |
| 3703 | |
| 3704 | struct __ec_todo_unpacked { |
| 3705 | /* For aligning the fifo_info */ |
| 3706 | uint8_t reserved[3]; |
| 3707 | struct ec_response_motion_sense_fifo_info info; |
| 3708 | } sensor_fifo; |
| 3709 | |
| 3710 | uint32_t buttons; |
| 3711 | |
| 3712 | uint32_t switches; |
| 3713 | |
| 3714 | uint32_t fp_events; |
| 3715 | |
| 3716 | uint32_t sysrq; |
| 3717 | |
| 3718 | /* CEC events from enum mkbp_cec_event */ |
| 3719 | uint32_t cec_events; |
| 3720 | |
| 3721 | uint8_t cec_message[16]; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3722 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3723 | BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16); |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3724 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3725 | struct ec_response_get_next_event { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3726 | uint8_t event_type; |
| 3727 | /* Followed by event data if any */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 3728 | union ec_response_get_next_data data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3729 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3730 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3731 | struct ec_response_get_next_event_v1 { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3732 | uint8_t event_type; |
| 3733 | /* Followed by event data if any */ |
| 3734 | union ec_response_get_next_data_v1 data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3735 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3736 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3737 | /* Bit indices for buttons and switches.*/ |
| 3738 | /* Buttons */ |
| 3739 | #define EC_MKBP_POWER_BUTTON 0 |
| 3740 | #define EC_MKBP_VOL_UP 1 |
| 3741 | #define EC_MKBP_VOL_DOWN 2 |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 3742 | #define EC_MKBP_RECOVERY 3 |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3743 | |
| 3744 | /* Switches */ |
| 3745 | #define EC_MKBP_LID_OPEN 0 |
| 3746 | #define EC_MKBP_TABLET_MODE 1 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3747 | #define EC_MKBP_BASE_ATTACHED 2 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 3748 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3749 | /* Run keyboard factory test scanning */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3750 | #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3751 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3752 | struct ec_response_keyboard_factory_test { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3753 | uint16_t shorted; /* Keyboard pins are shorted */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3754 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3755 | |
| 3756 | /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */ |
| 3757 | #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3758 | #define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F) |
| 3759 | #define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4 |
| 3760 | #define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \ |
| 3761 | >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET) |
| 3762 | #define EC_MKBP_FP_MATCH_IDX_OFFSET 12 |
| 3763 | #define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000 |
| 3764 | #define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \ |
| 3765 | >> EC_MKBP_FP_MATCH_IDX_OFFSET) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3766 | #define EC_MKBP_FP_ENROLL BIT(27) |
| 3767 | #define EC_MKBP_FP_MATCH BIT(28) |
| 3768 | #define EC_MKBP_FP_FINGER_DOWN BIT(29) |
| 3769 | #define EC_MKBP_FP_FINGER_UP BIT(30) |
| 3770 | #define EC_MKBP_FP_IMAGE_READY BIT(31) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3771 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */ |
| 3772 | #define EC_MKBP_FP_ERR_ENROLL_OK 0 |
| 3773 | #define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1 |
| 3774 | #define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2 |
| 3775 | #define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3 |
| 3776 | #define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5 |
| 3777 | /* Can be used to detect if image was usable for enrollment or not. */ |
| 3778 | #define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1 |
| 3779 | /* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */ |
| 3780 | #define EC_MKBP_FP_ERR_MATCH_NO 0 |
| 3781 | #define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3782 | #define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7 |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3783 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2 |
| 3784 | #define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4 |
| 3785 | #define EC_MKBP_FP_ERR_MATCH_YES 1 |
| 3786 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3 |
| 3787 | #define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5 |
| 3788 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 3789 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3790 | #define EC_CMD_MKBP_WAKE_MASK 0x0069 |
| 3791 | enum ec_mkbp_event_mask_action { |
| 3792 | /* Retrieve the value of a wake mask. */ |
| 3793 | GET_WAKE_MASK = 0, |
| 3794 | |
| 3795 | /* Set the value of a wake mask. */ |
| 3796 | SET_WAKE_MASK, |
| 3797 | }; |
| 3798 | |
| 3799 | enum ec_mkbp_mask_type { |
| 3800 | /* |
| 3801 | * These are host events sent via MKBP. |
| 3802 | * |
| 3803 | * Some examples are: |
| 3804 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN) |
| 3805 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED) |
| 3806 | * |
| 3807 | * The only things that should be in this mask are: |
| 3808 | * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*) |
| 3809 | */ |
| 3810 | EC_MKBP_HOST_EVENT_WAKE_MASK = 0, |
| 3811 | |
| 3812 | /* |
| 3813 | * These are MKBP events. Some examples are: |
| 3814 | * |
| 3815 | * EC_MKBP_EVENT_KEY_MATRIX |
| 3816 | * EC_MKBP_EVENT_SWITCH |
| 3817 | * |
| 3818 | * The only things that should be in this mask are EC_MKBP_EVENT_*. |
| 3819 | */ |
| 3820 | EC_MKBP_EVENT_WAKE_MASK, |
| 3821 | }; |
| 3822 | |
| 3823 | struct ec_params_mkbp_event_wake_mask { |
| 3824 | /* One of enum ec_mkbp_event_mask_action */ |
| 3825 | uint8_t action; |
| 3826 | |
| 3827 | /* |
| 3828 | * Which MKBP mask are you interested in acting upon? This is one of |
| 3829 | * ec_mkbp_mask_type. |
| 3830 | */ |
| 3831 | uint8_t mask_type; |
| 3832 | |
| 3833 | /* If setting a new wake mask, this contains the mask to set. */ |
| 3834 | uint32_t new_wake_mask; |
| 3835 | }; |
| 3836 | |
| 3837 | struct ec_response_mkbp_event_wake_mask { |
| 3838 | uint32_t wake_mask; |
| 3839 | }; |
| 3840 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3841 | /*****************************************************************************/ |
| 3842 | /* Temperature sensor commands */ |
| 3843 | |
| 3844 | /* Read temperature sensor info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3845 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3846 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3847 | struct ec_params_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3848 | uint8_t id; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3849 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3850 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3851 | struct ec_response_temp_sensor_get_info { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3852 | char sensor_name[32]; |
| 3853 | uint8_t sensor_type; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3854 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3855 | |
| 3856 | /*****************************************************************************/ |
| 3857 | |
| 3858 | /* |
| 3859 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 3860 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 3861 | * below. |
| 3862 | */ |
| 3863 | |
| 3864 | /*****************************************************************************/ |
| 3865 | /* Host event commands */ |
| 3866 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3867 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 3868 | /* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3869 | /* |
| 3870 | * Host event mask params and response structures, shared by all of the host |
| 3871 | * event commands below. |
| 3872 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3873 | struct ec_params_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3874 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3875 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3876 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3877 | struct ec_response_host_event_mask { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3878 | uint32_t mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3879 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3880 | |
| 3881 | /* These all use ec_response_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3882 | #define EC_CMD_HOST_EVENT_GET_B 0x0087 |
| 3883 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088 |
| 3884 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089 |
| 3885 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3886 | |
| 3887 | /* These all use ec_params_host_event_mask */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3888 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A |
| 3889 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B |
| 3890 | #define EC_CMD_HOST_EVENT_CLEAR 0x008C |
| 3891 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E |
| 3892 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3893 | |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3894 | /* |
| 3895 | * Unified host event programming interface - Should be used by newer versions |
| 3896 | * of BIOS/OS to program host events and masks |
| 3897 | */ |
| 3898 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3899 | struct ec_params_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3900 | |
| 3901 | /* Action requested by host - one of enum ec_host_event_action. */ |
| 3902 | uint8_t action; |
| 3903 | |
| 3904 | /* |
| 3905 | * Mask type that the host requested the action on - one of |
| 3906 | * enum ec_host_event_mask_type. |
| 3907 | */ |
| 3908 | uint8_t mask_type; |
| 3909 | |
| 3910 | /* Set to 0, ignore on read */ |
| 3911 | uint16_t reserved; |
| 3912 | |
| 3913 | /* Value to be used in case of set operations. */ |
| 3914 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3915 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3916 | |
| 3917 | /* |
| 3918 | * Response structure returned by EC_CMD_HOST_EVENT. |
| 3919 | * Update the value on a GET request. Set to 0 on GET/CLEAR |
| 3920 | */ |
| 3921 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3922 | struct ec_response_host_event { |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3923 | |
| 3924 | /* Mask value in case of get operation */ |
| 3925 | uint64_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3926 | } __ec_align4; |
Jenny TC | 1dfc2c3 | 2017-12-14 14:24:39 +0530 | [diff] [blame] | 3927 | |
| 3928 | enum ec_host_event_action { |
| 3929 | /* |
| 3930 | * params.value is ignored. Value of mask_type populated |
| 3931 | * in response.value |
| 3932 | */ |
| 3933 | EC_HOST_EVENT_GET, |
| 3934 | |
| 3935 | /* Bits in params.value are set */ |
| 3936 | EC_HOST_EVENT_SET, |
| 3937 | |
| 3938 | /* Bits in params.value are cleared */ |
| 3939 | EC_HOST_EVENT_CLEAR, |
| 3940 | }; |
| 3941 | |
| 3942 | enum ec_host_event_mask_type { |
| 3943 | |
| 3944 | /* Main host event copy */ |
| 3945 | EC_HOST_EVENT_MAIN, |
| 3946 | |
| 3947 | /* Copy B of host events */ |
| 3948 | EC_HOST_EVENT_B, |
| 3949 | |
| 3950 | /* SCI Mask */ |
| 3951 | EC_HOST_EVENT_SCI_MASK, |
| 3952 | |
| 3953 | /* SMI Mask */ |
| 3954 | EC_HOST_EVENT_SMI_MASK, |
| 3955 | |
| 3956 | /* Mask of events that should be always reported in hostevents */ |
| 3957 | EC_HOST_EVENT_ALWAYS_REPORT_MASK, |
| 3958 | |
| 3959 | /* Active wake mask */ |
| 3960 | EC_HOST_EVENT_ACTIVE_WAKE_MASK, |
| 3961 | |
| 3962 | /* Lazy wake mask for S0ix */ |
| 3963 | EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX, |
| 3964 | |
| 3965 | /* Lazy wake mask for S3 */ |
| 3966 | EC_HOST_EVENT_LAZY_WAKE_MASK_S3, |
| 3967 | |
| 3968 | /* Lazy wake mask for S5 */ |
| 3969 | EC_HOST_EVENT_LAZY_WAKE_MASK_S5, |
| 3970 | }; |
| 3971 | |
| 3972 | #define EC_CMD_HOST_EVENT 0x00A4 |
| 3973 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3974 | /*****************************************************************************/ |
| 3975 | /* Switch commands */ |
| 3976 | |
| 3977 | /* Enable/disable LCD backlight */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3978 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3979 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3980 | struct ec_params_switch_enable_backlight { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3981 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3982 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3983 | |
| 3984 | /* Enable/disable WLAN/Bluetooth */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 3985 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3986 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3987 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3988 | /* Version 0 params; no response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3989 | struct ec_params_switch_enable_wireless_v0 { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3990 | uint8_t enabled; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3991 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 3992 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3993 | /* Version 1 params */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 3994 | struct ec_params_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 3995 | /* Flags to enable now */ |
| 3996 | uint8_t now_flags; |
| 3997 | |
| 3998 | /* Which flags to copy from now_flags */ |
| 3999 | uint8_t now_mask; |
| 4000 | |
| 4001 | /* |
| 4002 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 4003 | * transition. (Other flags will be disabled by the S0->S3 |
| 4004 | * transition.) |
| 4005 | */ |
| 4006 | uint8_t suspend_flags; |
| 4007 | |
| 4008 | /* Which flags to copy from suspend_flags */ |
| 4009 | uint8_t suspend_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4010 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4011 | |
| 4012 | /* Version 1 response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4013 | struct ec_response_switch_enable_wireless_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4014 | /* Flags to enable now */ |
| 4015 | uint8_t now_flags; |
| 4016 | |
| 4017 | /* Flags to leave enabled in S3 */ |
| 4018 | uint8_t suspend_flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4019 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4020 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4021 | /*****************************************************************************/ |
| 4022 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 4023 | |
| 4024 | /* Set GPIO output value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4025 | #define EC_CMD_GPIO_SET 0x0092 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4026 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4027 | struct ec_params_gpio_set { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4028 | char name[32]; |
| 4029 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4030 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4031 | |
| 4032 | /* Get GPIO value */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4033 | #define EC_CMD_GPIO_GET 0x0093 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4034 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4035 | /* Version 0 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4036 | struct ec_params_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4037 | char name[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4038 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4039 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4040 | struct ec_response_gpio_get { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4041 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4042 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4043 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4044 | /* Version 1 of input params and response */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4045 | struct ec_params_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4046 | uint8_t subcmd; |
| 4047 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4048 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4049 | char name[32]; |
| 4050 | } get_value_by_name; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4051 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4052 | uint8_t index; |
| 4053 | } get_info; |
| 4054 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4055 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4056 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4057 | struct ec_response_gpio_get_v1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4058 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4059 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4060 | uint8_t val; |
| 4061 | } get_value_by_name, get_count; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4062 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4063 | uint8_t val; |
| 4064 | char name[32]; |
| 4065 | uint32_t flags; |
| 4066 | } get_info; |
| 4067 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4068 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4069 | |
| 4070 | enum gpio_get_subcmd { |
| 4071 | EC_GPIO_GET_BY_NAME = 0, |
| 4072 | EC_GPIO_GET_COUNT = 1, |
| 4073 | EC_GPIO_GET_INFO = 2, |
| 4074 | }; |
| 4075 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4076 | /*****************************************************************************/ |
| 4077 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 4078 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4079 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4080 | * CAUTION: These commands are deprecated, and are not supported anymore in EC |
| 4081 | * builds >= 8398.0.0 (see crosbug.com/p/23570). |
| 4082 | * |
| 4083 | * Use EC_CMD_I2C_PASSTHRU instead. |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4084 | */ |
| 4085 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4086 | /* Read I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4087 | #define EC_CMD_I2C_READ 0x0094 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4088 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4089 | struct ec_params_i2c_read { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4090 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4091 | uint8_t read_size; /* Either 8 or 16. */ |
| 4092 | uint8_t port; |
| 4093 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4094 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4095 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4096 | struct ec_response_i2c_read { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4097 | uint16_t data; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4098 | } __ec_align2; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4099 | |
| 4100 | /* Write I2C bus */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4101 | #define EC_CMD_I2C_WRITE 0x0095 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4102 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4103 | struct ec_params_i2c_write { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4104 | uint16_t data; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4105 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4106 | uint8_t write_size; /* Either 8 or 16. */ |
| 4107 | uint8_t port; |
| 4108 | uint8_t offset; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4109 | } __ec_align_size1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4110 | |
| 4111 | /*****************************************************************************/ |
| 4112 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 4113 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4114 | /* Force charge state machine to stop charging the battery or force it to |
| 4115 | * discharge the battery. |
| 4116 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4117 | #define EC_CMD_CHARGE_CONTROL 0x0096 |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4118 | #define EC_VER_CHARGE_CONTROL 1 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4119 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4120 | enum ec_charge_control_mode { |
| 4121 | CHARGE_CONTROL_NORMAL = 0, |
| 4122 | CHARGE_CONTROL_IDLE, |
| 4123 | CHARGE_CONTROL_DISCHARGE, |
| 4124 | }; |
| 4125 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4126 | struct ec_params_charge_control { |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 4127 | uint32_t mode; /* enum charge_control_mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4128 | } __ec_align4; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4129 | |
| 4130 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4131 | |
| 4132 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4133 | #define EC_CMD_CONSOLE_SNAPSHOT 0x0097 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4134 | |
| 4135 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4136 | * Read data from the saved snapshot. If the subcmd parameter is |
| 4137 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 4138 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 4139 | * end of the previous snapshot. |
| 4140 | * |
| 4141 | * The params are only looked at in version >= 1 of this command. Prior |
| 4142 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4143 | * |
| 4144 | * Response is null-terminated string. Empty string, if there is no more |
| 4145 | * remaining output. |
| 4146 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4147 | #define EC_CMD_CONSOLE_READ 0x0098 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4148 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4149 | enum ec_console_read_subcmd { |
| 4150 | CONSOLE_READ_NEXT = 0, |
| 4151 | CONSOLE_READ_RECENT |
| 4152 | }; |
| 4153 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4154 | struct ec_params_console_read_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4155 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4156 | } __ec_align1; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4157 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 4158 | /*****************************************************************************/ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4159 | |
| 4160 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4161 | * Cut off battery power immediately or after the host has shut down. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4162 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4163 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 4164 | * EC_RES_SUCCESS if the command was successful. |
| 4165 | * EC_RES_ERROR if the cut off command failed. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4166 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4167 | #define EC_CMD_BATTERY_CUT_OFF 0x0099 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4168 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4169 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4170 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4171 | struct ec_params_battery_cutoff { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4172 | uint8_t flags; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4173 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4174 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4175 | /*****************************************************************************/ |
| 4176 | /* USB port mux control. */ |
| 4177 | |
| 4178 | /* |
| 4179 | * Switch USB mux or return to automatic switching. |
| 4180 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4181 | #define EC_CMD_USB_MUX 0x009A |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4182 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4183 | struct ec_params_usb_mux { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4184 | uint8_t mux; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4185 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4186 | |
| 4187 | /*****************************************************************************/ |
| 4188 | /* LDOs / FETs control. */ |
| 4189 | |
| 4190 | enum ec_ldo_state { |
| 4191 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 4192 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 4193 | }; |
| 4194 | |
| 4195 | /* |
| 4196 | * Switch on/off a LDO. |
| 4197 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4198 | #define EC_CMD_LDO_SET 0x009B |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4199 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4200 | struct ec_params_ldo_set { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4201 | uint8_t index; |
| 4202 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4203 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4204 | |
| 4205 | /* |
| 4206 | * Get LDO state. |
| 4207 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4208 | #define EC_CMD_LDO_GET 0x009C |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4209 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4210 | struct ec_params_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4211 | uint8_t index; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4212 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4213 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4214 | struct ec_response_ldo_get { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4215 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4216 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4217 | |
| 4218 | /*****************************************************************************/ |
| 4219 | /* Power info. */ |
| 4220 | |
| 4221 | /* |
| 4222 | * Get power info. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4223 | * |
| 4224 | * Note: v0 of this command is deprecated |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4225 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4226 | #define EC_CMD_POWER_INFO 0x009D |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4227 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4228 | /* |
| 4229 | * v1 of EC_CMD_POWER_INFO |
| 4230 | */ |
| 4231 | enum system_power_source { |
| 4232 | /* |
| 4233 | * Haven't established which power source is used yet, |
| 4234 | * or no presence signals are available |
| 4235 | */ |
| 4236 | POWER_SOURCE_UNKNOWN = 0, |
| 4237 | /* System is running on battery alone */ |
| 4238 | POWER_SOURCE_BATTERY = 1, |
| 4239 | /* System is running on A/C alone */ |
| 4240 | POWER_SOURCE_AC = 2, |
| 4241 | /* System is running on A/C and battery */ |
| 4242 | POWER_SOURCE_AC_BATTERY = 3, |
| 4243 | }; |
| 4244 | |
| 4245 | struct ec_response_power_info_v1 { |
| 4246 | /* enum system_power_source */ |
| 4247 | uint8_t system_power_source; |
| 4248 | /* Battery state-of-charge, 0-100, 0 if not present */ |
| 4249 | uint8_t battery_soc; |
| 4250 | /* AC Adapter 100% rating, Watts */ |
| 4251 | uint8_t ac_adapter_100pct; |
| 4252 | /* AC Adapter 10ms rating, Watts */ |
| 4253 | uint8_t ac_adapter_10ms; |
| 4254 | /* Battery 1C rating, derated */ |
| 4255 | uint8_t battery_1cd; |
| 4256 | /* Rest of Platform average, Watts */ |
| 4257 | uint8_t rop_avg; |
| 4258 | /* Rest of Platform peak, Watts */ |
| 4259 | uint8_t rop_peak; |
| 4260 | /* Nominal charger efficiency, % */ |
| 4261 | uint8_t nominal_charger_eff; |
| 4262 | /* Rest of Platform VR Average Efficiency, % */ |
| 4263 | uint8_t rop_avg_eff; |
| 4264 | /* Rest of Platform VR Peak Efficiency, % */ |
| 4265 | uint8_t rop_peak_eff; |
| 4266 | /* SoC VR Efficiency at Average level, % */ |
| 4267 | uint8_t soc_avg_eff; |
| 4268 | /* SoC VR Efficiency at Peak level, % */ |
| 4269 | uint8_t soc_peak_eff; |
| 4270 | /* Intel-specific items */ |
| 4271 | struct { |
| 4272 | /* Battery's level of DBPT support: 0, 2 */ |
| 4273 | uint8_t batt_dbpt_support_level; |
| 4274 | /* |
| 4275 | * Maximum peak power from battery (10ms), Watts |
| 4276 | * If DBPT is not supported, this is 0 |
| 4277 | */ |
| 4278 | uint8_t batt_dbpt_max_peak_power; |
| 4279 | /* |
| 4280 | * Sustained peak power from battery, Watts |
| 4281 | * If DBPT is not supported, this is 0 |
| 4282 | */ |
| 4283 | uint8_t batt_dbpt_sus_peak_power; |
| 4284 | } intel; |
| 4285 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4286 | |
| 4287 | /*****************************************************************************/ |
| 4288 | /* I2C passthru command */ |
| 4289 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4290 | #define EC_CMD_I2C_PASSTHRU 0x009E |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4291 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4292 | /* Read data; if not present, message is a write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4293 | #define EC_I2C_FLAG_READ BIT(15) |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4294 | |
| 4295 | /* Mask for address */ |
| 4296 | #define EC_I2C_ADDR_MASK 0x3ff |
| 4297 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4298 | #define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */ |
| 4299 | #define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4300 | |
| 4301 | /* Any error */ |
| 4302 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 4303 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4304 | struct ec_params_i2c_passthru_msg { |
| 4305 | uint16_t addr_flags; /* I2C slave address and flags */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4306 | uint16_t len; /* Number of bytes to read or write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4307 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4308 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4309 | struct ec_params_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4310 | uint8_t port; /* I2C port number */ |
| 4311 | uint8_t num_msgs; /* Number of messages */ |
| 4312 | struct ec_params_i2c_passthru_msg msg[]; |
| 4313 | /* Data to write for all messages is concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4314 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4315 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4316 | struct ec_response_i2c_passthru { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4317 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 4318 | uint8_t num_msgs; /* Number of messages processed */ |
| 4319 | uint8_t data[]; /* Data read by messages concatenated here */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4320 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4321 | |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4322 | /*****************************************************************************/ |
| 4323 | /* Power button hang detect */ |
| 4324 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4325 | #define EC_CMD_HANG_DETECT 0x009F |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4326 | |
| 4327 | /* Reasons to start hang detection timer */ |
| 4328 | /* Power button pressed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4329 | #define EC_HANG_START_ON_POWER_PRESS BIT(0) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4330 | |
| 4331 | /* Lid closed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4332 | #define EC_HANG_START_ON_LID_CLOSE BIT(1) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4333 | |
| 4334 | /* Lid opened */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4335 | #define EC_HANG_START_ON_LID_OPEN BIT(2) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4336 | |
| 4337 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4338 | #define EC_HANG_START_ON_RESUME BIT(3) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4339 | |
| 4340 | /* Reasons to cancel hang detection */ |
| 4341 | |
| 4342 | /* Power button released */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4343 | #define EC_HANG_STOP_ON_POWER_RELEASE BIT(8) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4344 | |
| 4345 | /* Any host command from AP received */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4346 | #define EC_HANG_STOP_ON_HOST_COMMAND BIT(9) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4347 | |
| 4348 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4349 | #define EC_HANG_STOP_ON_SUSPEND BIT(10) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4350 | |
| 4351 | /* |
| 4352 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 4353 | * timer is started. This provides the AP a way to start the hang timer |
| 4354 | * without reconfiguring any of the other hang detect settings. Note that |
| 4355 | * you must previously have configured the timeouts. |
| 4356 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4357 | #define EC_HANG_START_NOW BIT(30) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4358 | |
| 4359 | /* |
| 4360 | * If this flag is set, all the other fields are ignored (including |
| 4361 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 4362 | * without reconfiguring any of the other hang detect settings. |
| 4363 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4364 | #define EC_HANG_STOP_NOW BIT(31) |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4365 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4366 | struct ec_params_hang_detect { |
Duncan Laurie | e6b280e | 2014-02-10 16:21:05 -0800 | [diff] [blame] | 4367 | /* Flags; see EC_HANG_* */ |
| 4368 | uint32_t flags; |
| 4369 | |
| 4370 | /* Timeout in msec before generating host event, if enabled */ |
| 4371 | uint16_t host_event_timeout_msec; |
| 4372 | |
| 4373 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 4374 | uint16_t warm_reboot_timeout_msec; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4375 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4376 | |
| 4377 | /*****************************************************************************/ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4378 | /* Commands for battery charging */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4379 | |
| 4380 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4381 | * This is the single catch-all host command to exchange data regarding the |
| 4382 | * charge state machine (v2 and up). |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4383 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4384 | #define EC_CMD_CHARGE_STATE 0x00A0 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4385 | |
| 4386 | /* Subcommands for this host command */ |
| 4387 | enum charge_state_command { |
| 4388 | CHARGE_STATE_CMD_GET_STATE, |
| 4389 | CHARGE_STATE_CMD_GET_PARAM, |
| 4390 | CHARGE_STATE_CMD_SET_PARAM, |
| 4391 | CHARGE_STATE_NUM_CMDS |
| 4392 | }; |
| 4393 | |
| 4394 | /* |
| 4395 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 4396 | * params, which are handled by the particular implementations. |
| 4397 | */ |
| 4398 | enum charge_state_params { |
| 4399 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 4400 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 4401 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 4402 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 4403 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4404 | CS_PARAM_LIMIT_POWER, /* |
| 4405 | * Check if power is limited due to |
| 4406 | * low battery and / or a weak external |
| 4407 | * charger. READ ONLY. |
| 4408 | */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4409 | /* How many so far? */ |
| 4410 | CS_NUM_BASE_PARAMS, |
| 4411 | |
| 4412 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 4413 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 4414 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 4415 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4416 | /* Range for CONFIG_CHARGE_STATE_DEBUG params */ |
| 4417 | CS_PARAM_DEBUG_MIN = 0x20000, |
| 4418 | CS_PARAM_DEBUG_CTL_MODE = 0x20000, |
| 4419 | CS_PARAM_DEBUG_MANUAL_MODE, |
| 4420 | CS_PARAM_DEBUG_SEEMS_DEAD, |
| 4421 | CS_PARAM_DEBUG_SEEMS_DISCONNECTED, |
| 4422 | CS_PARAM_DEBUG_BATT_REMOVED, |
| 4423 | CS_PARAM_DEBUG_MANUAL_CURRENT, |
| 4424 | CS_PARAM_DEBUG_MANUAL_VOLTAGE, |
| 4425 | CS_PARAM_DEBUG_MAX = 0x2ffff, |
| 4426 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4427 | /* Other custom param ranges go here... */ |
| 4428 | }; |
| 4429 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4430 | struct ec_params_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4431 | uint8_t cmd; /* enum charge_state_command */ |
| 4432 | union { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4433 | /* get_state has no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4434 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4435 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4436 | uint32_t param; /* enum charge_state_param */ |
| 4437 | } get_param; |
| 4438 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4439 | struct __ec_todo_unpacked { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4440 | uint32_t param; /* param to set */ |
| 4441 | uint32_t value; /* value to set */ |
| 4442 | } set_param; |
| 4443 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4444 | } __ec_todo_packed; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4445 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4446 | struct ec_response_charge_state { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4447 | union { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4448 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4449 | int ac; |
| 4450 | int chg_voltage; |
| 4451 | int chg_current; |
| 4452 | int chg_input_current; |
| 4453 | int batt_state_of_charge; |
| 4454 | } get_state; |
| 4455 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4456 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4457 | uint32_t value; |
| 4458 | } get_param; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4459 | |
| 4460 | /* set_param returns no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4461 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4462 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4463 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4464 | |
| 4465 | /* |
| 4466 | * Set maximum battery charging current. |
| 4467 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4468 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4469 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4470 | struct ec_params_current_limit { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4471 | uint32_t limit; /* in mA */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4472 | } __ec_align4; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4473 | |
| 4474 | /* |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4475 | * Set maximum external voltage / current. |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4476 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4477 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4478 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4479 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4480 | struct ec_params_external_power_limit_v1 { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4481 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 4482 | 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] | 4483 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4484 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4485 | #define EC_POWER_LIMIT_NONE 0xffff |
| 4486 | |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4487 | /* |
| 4488 | * Set maximum voltage & current of a dedicated charge port |
| 4489 | */ |
| 4490 | #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3 |
| 4491 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4492 | struct ec_params_dedicated_charger_limit { |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4493 | uint16_t current_lim; /* in mA */ |
| 4494 | uint16_t voltage_lim; /* in mV */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4495 | } __ec_align2; |
Daisuke Nojiri | 93fd8fa | 2017-11-28 14:11:30 -0800 | [diff] [blame] | 4496 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4497 | /*****************************************************************************/ |
| 4498 | /* Hibernate/Deep Sleep Commands */ |
| 4499 | |
| 4500 | /* Set the delay before going into hibernation. */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4501 | #define EC_CMD_HIBERNATION_DELAY 0x00A8 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4502 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4503 | struct ec_params_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4504 | /* |
| 4505 | * Seconds to wait in G3 before hibernate. Pass in 0 to read the |
| 4506 | * current settings without changing them. |
| 4507 | */ |
| 4508 | uint32_t seconds; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4509 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4510 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4511 | struct ec_response_hibernation_delay { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4512 | /* |
| 4513 | * The current time in seconds in which the system has been in the G3 |
| 4514 | * state. This value is reset if the EC transitions out of G3. |
| 4515 | */ |
| 4516 | uint32_t time_g3; |
| 4517 | |
| 4518 | /* |
| 4519 | * The current time remaining in seconds until the EC should hibernate. |
| 4520 | * This value is also reset if the EC transitions out of G3. |
| 4521 | */ |
| 4522 | uint32_t time_remaining; |
| 4523 | |
| 4524 | /* |
| 4525 | * The current time in seconds that the EC should wait in G3 before |
| 4526 | * hibernating. |
| 4527 | */ |
| 4528 | uint32_t hibernate_delay; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4529 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4530 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4531 | /* Inform the EC when entering a sleep state */ |
| 4532 | #define EC_CMD_HOST_SLEEP_EVENT 0x00A9 |
| 4533 | |
| 4534 | enum host_sleep_event { |
| 4535 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 4536 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 4537 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4538 | HOST_SLEEP_EVENT_S0IX_RESUME = 4, |
| 4539 | /* S3 suspend with additional enabled wake sources */ |
| 4540 | HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5, |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4541 | }; |
| 4542 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4543 | struct ec_params_host_sleep_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4544 | uint8_t sleep_event; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4545 | } __ec_align1; |
| 4546 | |
| 4547 | /* |
| 4548 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 4549 | * transition failures |
| 4550 | */ |
| 4551 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 4552 | |
| 4553 | /* Disable timeout detection for this sleep transition */ |
| 4554 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 4555 | |
| 4556 | struct ec_params_host_sleep_event_v1 { |
| 4557 | /* The type of sleep being entered or exited. */ |
| 4558 | uint8_t sleep_event; |
| 4559 | |
| 4560 | /* Padding */ |
| 4561 | uint8_t reserved; |
| 4562 | union { |
| 4563 | /* Parameters that apply for suspend messages. */ |
| 4564 | struct { |
| 4565 | /* |
| 4566 | * The timeout in milliseconds between when this message |
| 4567 | * is received and when the EC will declare sleep |
| 4568 | * transition failure if the sleep signal is not |
| 4569 | * asserted. |
| 4570 | */ |
| 4571 | uint16_t sleep_timeout_ms; |
| 4572 | } suspend_params; |
| 4573 | |
| 4574 | /* No parameters for non-suspend messages. */ |
| 4575 | }; |
| 4576 | } __ec_align2; |
| 4577 | |
| 4578 | /* A timeout occurred when this bit is set */ |
| 4579 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 4580 | |
| 4581 | /* |
| 4582 | * The mask defining which bits correspond to the number of sleep transitions, |
| 4583 | * as well as the maximum number of suspend line transitions that will be |
| 4584 | * reported back to the host. |
| 4585 | */ |
| 4586 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 4587 | |
| 4588 | struct ec_response_host_sleep_event_v1 { |
| 4589 | union { |
| 4590 | /* Response fields that apply for resume messages. */ |
| 4591 | struct { |
| 4592 | /* |
| 4593 | * The number of sleep power signal transitions that |
| 4594 | * occurred since the suspend message. The high bit |
| 4595 | * indicates a timeout occurred. |
| 4596 | */ |
| 4597 | uint32_t sleep_transitions; |
| 4598 | } resume_response; |
| 4599 | |
| 4600 | /* No response fields for non-resume messages. */ |
| 4601 | }; |
| 4602 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4603 | |
| 4604 | /*****************************************************************************/ |
| 4605 | /* Device events */ |
| 4606 | #define EC_CMD_DEVICE_EVENT 0x00AA |
| 4607 | |
| 4608 | enum ec_device_event { |
| 4609 | EC_DEVICE_EVENT_TRACKPAD, |
| 4610 | EC_DEVICE_EVENT_DSP, |
| 4611 | EC_DEVICE_EVENT_WIFI, |
| 4612 | }; |
| 4613 | |
| 4614 | enum ec_device_event_param { |
| 4615 | /* Get and clear pending device events */ |
| 4616 | EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS, |
| 4617 | /* Get device event mask */ |
| 4618 | EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS, |
| 4619 | /* Set device event mask */ |
| 4620 | EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS, |
| 4621 | }; |
| 4622 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4623 | #define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4624 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4625 | struct ec_params_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4626 | uint32_t event_mask; |
| 4627 | uint8_t param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4628 | } __ec_align_size1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4629 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4630 | struct ec_response_device_event { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4631 | uint32_t event_mask; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4632 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 4633 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4634 | /*****************************************************************************/ |
| 4635 | /* Smart battery pass-through */ |
| 4636 | |
| 4637 | /* Get / Set 16-bit smart battery registers */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4638 | #define EC_CMD_SB_READ_WORD 0x00B0 |
| 4639 | #define EC_CMD_SB_WRITE_WORD 0x00B1 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4640 | |
| 4641 | /* Get / Set string smart battery parameters |
| 4642 | * formatted as SMBUS "block". |
| 4643 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4644 | #define EC_CMD_SB_READ_BLOCK 0x00B2 |
| 4645 | #define EC_CMD_SB_WRITE_BLOCK 0x00B3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4646 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4647 | struct ec_params_sb_rd { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4648 | uint8_t reg; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4649 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4650 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4651 | struct ec_response_sb_rd_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4652 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4653 | } __ec_align2; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4654 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4655 | struct ec_params_sb_wr_word { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4656 | uint8_t reg; |
| 4657 | uint16_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4658 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4659 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4660 | struct ec_response_sb_rd_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4661 | uint8_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4662 | } __ec_align1; |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4663 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4664 | struct ec_params_sb_wr_block { |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4665 | uint8_t reg; |
| 4666 | uint16_t data[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4667 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4668 | |
| 4669 | /*****************************************************************************/ |
| 4670 | /* Battery vendor parameters |
| 4671 | * |
| 4672 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 4673 | * differ between boards or batteries. On a set operation, the response |
| 4674 | * contains the actual value set, which may be rounded or clipped from the |
| 4675 | * requested value. |
| 4676 | */ |
| 4677 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4678 | #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4679 | |
| 4680 | enum ec_battery_vendor_param_mode { |
| 4681 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 4682 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 4683 | }; |
| 4684 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4685 | struct ec_params_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4686 | uint32_t param; |
| 4687 | uint32_t value; |
| 4688 | uint8_t mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4689 | } __ec_align_size1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4690 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4691 | struct ec_response_battery_vendor_param { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4692 | uint32_t value; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4693 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4694 | |
| 4695 | /*****************************************************************************/ |
| 4696 | /* |
| 4697 | * Smart Battery Firmware Update Commands |
| 4698 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4699 | #define EC_CMD_SB_FW_UPDATE 0x00B5 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4700 | |
| 4701 | enum ec_sb_fw_update_subcmd { |
| 4702 | EC_SB_FW_UPDATE_PREPARE = 0x0, |
| 4703 | EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */ |
| 4704 | EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */ |
| 4705 | EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */ |
| 4706 | EC_SB_FW_UPDATE_END = 0x4, |
| 4707 | EC_SB_FW_UPDATE_STATUS = 0x5, |
| 4708 | EC_SB_FW_UPDATE_PROTECT = 0x6, |
| 4709 | EC_SB_FW_UPDATE_MAX = 0x7, |
| 4710 | }; |
| 4711 | |
| 4712 | #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32 |
| 4713 | #define SB_FW_UPDATE_CMD_STATUS_SIZE 2 |
| 4714 | #define SB_FW_UPDATE_CMD_INFO_SIZE 8 |
| 4715 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4716 | struct ec_sb_fw_update_header { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4717 | uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */ |
| 4718 | uint16_t fw_id; /* firmware id */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4719 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4720 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4721 | struct ec_params_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4722 | struct ec_sb_fw_update_header hdr; |
| 4723 | union { |
| 4724 | /* EC_SB_FW_UPDATE_PREPARE = 0x0 */ |
| 4725 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
| 4726 | /* EC_SB_FW_UPDATE_BEGIN = 0x2 */ |
| 4727 | /* EC_SB_FW_UPDATE_END = 0x4 */ |
| 4728 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
| 4729 | /* EC_SB_FW_UPDATE_PROTECT = 0x6 */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4730 | /* Those have no args */ |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4731 | |
| 4732 | /* EC_SB_FW_UPDATE_WRITE = 0x3 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4733 | struct __ec_align4 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4734 | uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE]; |
| 4735 | } write; |
| 4736 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4737 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4738 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4739 | struct ec_response_sb_fw_update { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4740 | union { |
| 4741 | /* EC_SB_FW_UPDATE_INFO = 0x1 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4742 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4743 | uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE]; |
| 4744 | } info; |
| 4745 | |
| 4746 | /* EC_SB_FW_UPDATE_STATUS = 0x5 */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4747 | struct __ec_align1 { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4748 | uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE]; |
| 4749 | } status; |
| 4750 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4751 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4752 | |
| 4753 | /* |
| 4754 | * Entering Verified Boot Mode Command |
| 4755 | * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command. |
| 4756 | * Valid Modes are: normal, developer, and recovery. |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4757 | * |
| 4758 | * EC no longer needs to know what mode vboot has entered, |
| 4759 | * so this command is deprecated. (See chromium:1014379.) |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4760 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4761 | #define EC_CMD_ENTERING_MODE 0x00B6 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4762 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4763 | struct ec_params_entering_mode { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4764 | int vboot_mode; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4765 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 4766 | |
| 4767 | #define VBOOT_MODE_NORMAL 0 |
| 4768 | #define VBOOT_MODE_DEVELOPER 1 |
| 4769 | #define VBOOT_MODE_RECOVERY 2 |
| 4770 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 4771 | /*****************************************************************************/ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4772 | /* |
| 4773 | * I2C passthru protection command: Protects I2C tunnels against access on |
| 4774 | * certain addresses (board-specific). |
| 4775 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 4776 | #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4777 | |
| 4778 | enum ec_i2c_passthru_protect_subcmd { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4779 | EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0, |
| 4780 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1, |
| 4781 | EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2, |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4782 | }; |
| 4783 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4784 | struct ec_params_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4785 | uint8_t subcmd; |
| 4786 | uint8_t port; /* I2C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4787 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4788 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4789 | struct ec_response_i2c_passthru_protect { |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4790 | uint8_t status; /* Status flags (0: unlocked, 1: locked) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4791 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4792 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4793 | |
| 4794 | /*****************************************************************************/ |
| 4795 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4796 | * HDMI CEC commands |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4797 | * |
| 4798 | * These commands are for sending and receiving message via HDMI CEC |
| 4799 | */ |
| 4800 | |
| 4801 | #define MAX_CEC_MSG_LEN 16 |
| 4802 | |
| 4803 | /* CEC message from the AP to be written on the CEC bus */ |
| 4804 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 4805 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4806 | /** |
| 4807 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 4808 | * @msg: message content to write to the CEC bus |
| 4809 | */ |
| 4810 | struct ec_params_cec_write { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4811 | uint8_t msg[MAX_CEC_MSG_LEN]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4812 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4813 | |
| 4814 | /* Set various CEC parameters */ |
| 4815 | #define EC_CMD_CEC_SET 0x00BA |
| 4816 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4817 | /** |
| 4818 | * struct ec_params_cec_set - CEC parameters set |
| 4819 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4820 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 4821 | * or 1 to enable CEC functionality, in case cmd is |
| 4822 | * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical |
| 4823 | * address between 0 and 15 or 0xff to unregister |
| 4824 | */ |
| 4825 | struct ec_params_cec_set { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4826 | uint8_t cmd; /* enum cec_command */ |
| 4827 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4828 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4829 | |
| 4830 | /* Read various CEC parameters */ |
| 4831 | #define EC_CMD_CEC_GET 0x00BB |
| 4832 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4833 | /** |
| 4834 | * struct ec_params_cec_get - CEC parameters get |
| 4835 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 4836 | */ |
| 4837 | struct ec_params_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4838 | uint8_t cmd; /* enum cec_command */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4839 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4840 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4841 | /** |
| 4842 | * struct ec_response_cec_get - CEC parameters get response |
| 4843 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 4844 | * disabled or 1 if CEC functionality is enabled, |
| 4845 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 4846 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 4847 | */ |
| 4848 | struct ec_response_cec_get { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4849 | uint8_t val; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4850 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4851 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4852 | /* CEC parameters command */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4853 | enum cec_command { |
| 4854 | /* CEC reading, writing and events enable */ |
| 4855 | CEC_CMD_ENABLE, |
| 4856 | /* CEC logical address */ |
| 4857 | CEC_CMD_LOGICAL_ADDRESS, |
| 4858 | }; |
| 4859 | |
| 4860 | /* Events from CEC to AP */ |
| 4861 | enum mkbp_cec_event { |
| 4862 | /* Outgoing message was acknowledged by a follower */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4863 | EC_MKBP_CEC_SEND_OK = BIT(0), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4864 | /* Outgoing message was not acknowledged */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4865 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 4866 | }; |
| 4867 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 4868 | /*****************************************************************************/ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4869 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4870 | /* Commands for audio codec. */ |
| 4871 | #define EC_CMD_EC_CODEC 0x00BC |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4872 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4873 | enum ec_codec_subcmd { |
| 4874 | EC_CODEC_GET_CAPABILITIES = 0x0, |
| 4875 | EC_CODEC_GET_SHM_ADDR = 0x1, |
| 4876 | EC_CODEC_SET_SHM_ADDR = 0x2, |
| 4877 | EC_CODEC_SUBCMD_COUNT, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4878 | }; |
| 4879 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4880 | enum ec_codec_cap { |
| 4881 | EC_CODEC_CAP_WOV_AUDIO_SHM = 0, |
| 4882 | EC_CODEC_CAP_WOV_LANG_SHM = 1, |
| 4883 | EC_CODEC_CAP_LAST = 32, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4884 | }; |
| 4885 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4886 | enum ec_codec_shm_id { |
| 4887 | EC_CODEC_SHM_ID_WOV_AUDIO = 0x0, |
| 4888 | EC_CODEC_SHM_ID_WOV_LANG = 0x1, |
| 4889 | EC_CODEC_SHM_ID_LAST, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4890 | }; |
| 4891 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4892 | enum ec_codec_shm_type { |
| 4893 | EC_CODEC_SHM_TYPE_EC_RAM = 0x0, |
| 4894 | EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1, |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4895 | }; |
| 4896 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4897 | struct __ec_align1 ec_param_ec_codec_get_shm_addr { |
| 4898 | uint8_t shm_id; |
| 4899 | uint8_t reserved[3]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4900 | }; |
| 4901 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4902 | struct __ec_align4 ec_param_ec_codec_set_shm_addr { |
| 4903 | uint64_t phys_addr; |
| 4904 | uint32_t len; |
| 4905 | uint8_t shm_id; |
| 4906 | uint8_t reserved[3]; |
| 4907 | }; |
| 4908 | |
| 4909 | struct __ec_align4 ec_param_ec_codec { |
| 4910 | uint8_t cmd; /* enum ec_codec_subcmd */ |
| 4911 | uint8_t reserved[3]; |
| 4912 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4913 | union { |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4914 | struct ec_param_ec_codec_get_shm_addr |
| 4915 | get_shm_addr_param; |
| 4916 | struct ec_param_ec_codec_set_shm_addr |
| 4917 | set_shm_addr_param; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 4918 | }; |
| 4919 | }; |
| 4920 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 4921 | struct __ec_align4 ec_response_ec_codec_get_capabilities { |
| 4922 | uint32_t capabilities; |
| 4923 | }; |
| 4924 | |
| 4925 | struct __ec_align4 ec_response_ec_codec_get_shm_addr { |
| 4926 | uint64_t phys_addr; |
| 4927 | uint32_t len; |
| 4928 | uint8_t type; |
| 4929 | uint8_t reserved[3]; |
| 4930 | }; |
| 4931 | |
| 4932 | /*****************************************************************************/ |
| 4933 | |
| 4934 | /* Commands for DMIC on audio codec. */ |
| 4935 | #define EC_CMD_EC_CODEC_DMIC 0x00BD |
| 4936 | |
| 4937 | enum ec_codec_dmic_subcmd { |
| 4938 | EC_CODEC_DMIC_GET_MAX_GAIN = 0x0, |
| 4939 | EC_CODEC_DMIC_SET_GAIN_IDX = 0x1, |
| 4940 | EC_CODEC_DMIC_GET_GAIN_IDX = 0x2, |
| 4941 | EC_CODEC_DMIC_SUBCMD_COUNT, |
| 4942 | }; |
| 4943 | |
| 4944 | enum ec_codec_dmic_channel { |
| 4945 | EC_CODEC_DMIC_CHANNEL_0 = 0x0, |
| 4946 | EC_CODEC_DMIC_CHANNEL_1 = 0x1, |
| 4947 | EC_CODEC_DMIC_CHANNEL_2 = 0x2, |
| 4948 | EC_CODEC_DMIC_CHANNEL_3 = 0x3, |
| 4949 | EC_CODEC_DMIC_CHANNEL_4 = 0x4, |
| 4950 | EC_CODEC_DMIC_CHANNEL_5 = 0x5, |
| 4951 | EC_CODEC_DMIC_CHANNEL_6 = 0x6, |
| 4952 | EC_CODEC_DMIC_CHANNEL_7 = 0x7, |
| 4953 | EC_CODEC_DMIC_CHANNEL_COUNT, |
| 4954 | }; |
| 4955 | |
| 4956 | struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx { |
| 4957 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 4958 | uint8_t gain; |
| 4959 | uint8_t reserved[2]; |
| 4960 | }; |
| 4961 | |
| 4962 | struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx { |
| 4963 | uint8_t channel; /* enum ec_codec_dmic_channel */ |
| 4964 | uint8_t reserved[3]; |
| 4965 | }; |
| 4966 | |
| 4967 | struct __ec_align4 ec_param_ec_codec_dmic { |
| 4968 | uint8_t cmd; /* enum ec_codec_dmic_subcmd */ |
| 4969 | uint8_t reserved[3]; |
| 4970 | |
| 4971 | union { |
| 4972 | struct ec_param_ec_codec_dmic_set_gain_idx |
| 4973 | set_gain_idx_param; |
| 4974 | struct ec_param_ec_codec_dmic_get_gain_idx |
| 4975 | get_gain_idx_param; |
| 4976 | }; |
| 4977 | }; |
| 4978 | |
| 4979 | struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain { |
| 4980 | uint8_t max_gain; |
| 4981 | }; |
| 4982 | |
| 4983 | struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx { |
| 4984 | uint8_t gain; |
| 4985 | }; |
| 4986 | |
| 4987 | /*****************************************************************************/ |
| 4988 | |
| 4989 | /* Commands for I2S RX on audio codec. */ |
| 4990 | |
| 4991 | #define EC_CMD_EC_CODEC_I2S_RX 0x00BE |
| 4992 | |
| 4993 | enum ec_codec_i2s_rx_subcmd { |
| 4994 | EC_CODEC_I2S_RX_ENABLE = 0x0, |
| 4995 | EC_CODEC_I2S_RX_DISABLE = 0x1, |
| 4996 | EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2, |
| 4997 | EC_CODEC_I2S_RX_SET_DAIFMT = 0x3, |
| 4998 | EC_CODEC_I2S_RX_SET_BCLK = 0x4, |
| 4999 | EC_CODEC_I2S_RX_SUBCMD_COUNT, |
| 5000 | }; |
| 5001 | |
| 5002 | enum ec_codec_i2s_rx_sample_depth { |
| 5003 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0, |
| 5004 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1, |
| 5005 | EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT, |
| 5006 | }; |
| 5007 | |
| 5008 | enum ec_codec_i2s_rx_daifmt { |
| 5009 | EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0, |
| 5010 | EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1, |
| 5011 | EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2, |
| 5012 | EC_CODEC_I2S_RX_DAIFMT_COUNT, |
| 5013 | }; |
| 5014 | |
| 5015 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth { |
| 5016 | uint8_t depth; |
| 5017 | uint8_t reserved[3]; |
| 5018 | }; |
| 5019 | |
| 5020 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain { |
| 5021 | uint8_t left; |
| 5022 | uint8_t right; |
| 5023 | uint8_t reserved[2]; |
| 5024 | }; |
| 5025 | |
| 5026 | struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt { |
| 5027 | uint8_t daifmt; |
| 5028 | uint8_t reserved[3]; |
| 5029 | }; |
| 5030 | |
| 5031 | struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk { |
| 5032 | uint32_t bclk; |
| 5033 | }; |
| 5034 | |
| 5035 | struct __ec_align4 ec_param_ec_codec_i2s_rx { |
| 5036 | uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */ |
| 5037 | uint8_t reserved[3]; |
| 5038 | |
| 5039 | union { |
| 5040 | struct ec_param_ec_codec_i2s_rx_set_sample_depth |
| 5041 | set_sample_depth_param; |
| 5042 | struct ec_param_ec_codec_i2s_rx_set_daifmt |
| 5043 | set_daifmt_param; |
| 5044 | struct ec_param_ec_codec_i2s_rx_set_bclk |
| 5045 | set_bclk_param; |
| 5046 | }; |
| 5047 | }; |
| 5048 | |
| 5049 | /*****************************************************************************/ |
| 5050 | /* Commands for WoV on audio codec. */ |
| 5051 | |
| 5052 | #define EC_CMD_EC_CODEC_WOV 0x00BF |
| 5053 | |
| 5054 | enum ec_codec_wov_subcmd { |
| 5055 | EC_CODEC_WOV_SET_LANG = 0x0, |
| 5056 | EC_CODEC_WOV_SET_LANG_SHM = 0x1, |
| 5057 | EC_CODEC_WOV_GET_LANG = 0x2, |
| 5058 | EC_CODEC_WOV_ENABLE = 0x3, |
| 5059 | EC_CODEC_WOV_DISABLE = 0x4, |
| 5060 | EC_CODEC_WOV_READ_AUDIO = 0x5, |
| 5061 | EC_CODEC_WOV_READ_AUDIO_SHM = 0x6, |
| 5062 | EC_CODEC_WOV_SUBCMD_COUNT, |
| 5063 | }; |
| 5064 | |
| 5065 | /* |
| 5066 | * @hash is SHA256 of the whole language model. |
| 5067 | * @total_len indicates the length of whole language model. |
| 5068 | * @offset is the cursor from the beginning of the model. |
| 5069 | * @buf is the packet buffer. |
| 5070 | * @len denotes how many bytes in the buf. |
| 5071 | */ |
| 5072 | struct __ec_align4 ec_param_ec_codec_wov_set_lang { |
| 5073 | uint8_t hash[32]; |
| 5074 | uint32_t total_len; |
| 5075 | uint32_t offset; |
| 5076 | uint8_t buf[128]; |
| 5077 | uint32_t len; |
| 5078 | }; |
| 5079 | |
| 5080 | struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm { |
| 5081 | uint8_t hash[32]; |
| 5082 | uint32_t total_len; |
| 5083 | }; |
| 5084 | |
| 5085 | struct __ec_align4 ec_param_ec_codec_wov { |
| 5086 | uint8_t cmd; /* enum ec_codec_wov_subcmd */ |
| 5087 | uint8_t reserved[3]; |
| 5088 | |
| 5089 | union { |
| 5090 | struct ec_param_ec_codec_wov_set_lang |
| 5091 | set_lang_param; |
| 5092 | struct ec_param_ec_codec_wov_set_lang_shm |
| 5093 | set_lang_shm_param; |
| 5094 | }; |
| 5095 | }; |
| 5096 | |
| 5097 | struct __ec_align4 ec_response_ec_codec_wov_get_lang { |
| 5098 | uint8_t hash[32]; |
| 5099 | }; |
| 5100 | |
| 5101 | struct __ec_align4 ec_response_ec_codec_wov_read_audio { |
| 5102 | uint8_t buf[128]; |
| 5103 | uint32_t len; |
| 5104 | }; |
| 5105 | |
| 5106 | struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm { |
| 5107 | uint32_t offset; |
| 5108 | uint32_t len; |
| 5109 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5110 | |
| 5111 | /*****************************************************************************/ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5112 | /* System commands */ |
| 5113 | |
| 5114 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 5115 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 5116 | * necessarily reboot the EC. Rename to "image" or something similar? |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5117 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5118 | #define EC_CMD_REBOOT_EC 0x00D2 |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5119 | |
| 5120 | /* Command */ |
| 5121 | enum ec_reboot_cmd { |
| 5122 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5123 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5124 | EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5125 | /* (command 3 was jump to RW-B) */ |
| 5126 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5127 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
Daisuke Nojiri | 40d0bfa | 2017-11-30 17:41:09 -0800 | [diff] [blame] | 5128 | EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */ |
| 5129 | EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5130 | }; |
| 5131 | |
| 5132 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5133 | #define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */ |
| 5134 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */ |
| 5135 | #define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5136 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5137 | struct ec_params_reboot_ec { |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5138 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 5139 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5140 | } __ec_align1; |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5141 | |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5142 | /* |
| 5143 | * Get information on last EC panic. |
| 5144 | * |
| 5145 | * Returns variable-length platform-dependent panic information. See panic.h |
| 5146 | * for details. |
| 5147 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5148 | #define EC_CMD_GET_PANIC_INFO 0x00D3 |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5149 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5150 | /*****************************************************************************/ |
| 5151 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5152 | * Special commands |
| 5153 | * |
| 5154 | * These do not follow the normal rules for commands. See each command for |
| 5155 | * details. |
| 5156 | */ |
| 5157 | |
| 5158 | /* |
| 5159 | * Reboot NOW |
| 5160 | * |
| 5161 | * This command will work even when the EC LPC interface is busy, because the |
| 5162 | * reboot command is processed at interrupt level. Note that when the EC |
| 5163 | * reboots, the host will reboot too, so there is no response to this command. |
| 5164 | * |
| 5165 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 5166 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5167 | #define EC_CMD_REBOOT 0x00D1 /* Think "die" */ |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5168 | |
| 5169 | /* |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5170 | * Resend last response (not supported on LPC). |
| 5171 | * |
| 5172 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 5173 | * there was no previous command, or the previous command's response was too |
| 5174 | * big to save. |
| 5175 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5176 | #define EC_CMD_RESEND_RESPONSE 0x00DB |
Duncan Laurie | 433432b | 2013-06-03 10:38:22 -0700 | [diff] [blame] | 5177 | |
| 5178 | /* |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5179 | * This header byte on a command indicate version 0. Any header byte less |
| 5180 | * than this means that we are talking to an old EC which doesn't support |
| 5181 | * versioning. In that case, we assume version 0. |
| 5182 | * |
| 5183 | * Header bytes greater than this indicate a later version. For example, |
| 5184 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 5185 | * |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5186 | * The old EC interface must not use commands 0xdc or higher. |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5187 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5188 | #define EC_CMD_VERSION0 0x00DC |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5189 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5190 | /*****************************************************************************/ |
| 5191 | /* |
| 5192 | * PD commands |
| 5193 | * |
| 5194 | * These commands are for PD MCU communication. |
| 5195 | */ |
| 5196 | |
| 5197 | /* EC to PD MCU exchange status command */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5198 | #define EC_CMD_PD_EXCHANGE_STATUS 0x0100 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5199 | #define EC_VER_PD_EXCHANGE_STATUS 2 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5200 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5201 | enum pd_charge_state { |
| 5202 | PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */ |
| 5203 | PD_CHARGE_NONE, /* No charging allowed */ |
| 5204 | PD_CHARGE_5V, /* 5V charging only */ |
| 5205 | PD_CHARGE_MAX /* Charge at max voltage */ |
| 5206 | }; |
| 5207 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5208 | /* Status of EC being sent to PD */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5209 | #define EC_STATUS_HIBERNATING BIT(0) |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5210 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5211 | struct ec_params_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5212 | uint8_t status; /* EC status */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5213 | int8_t batt_soc; /* battery state of charge */ |
| 5214 | uint8_t charge_state; /* charging state (from enum pd_charge_state) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5215 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5216 | |
| 5217 | /* Status of PD being sent back to EC */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5218 | #define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */ |
| 5219 | #define PD_STATUS_IN_RW BIT(1) /* Running RW image */ |
| 5220 | #define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */ |
| 5221 | #define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */ |
| 5222 | #define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */ |
| 5223 | #define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */ |
| 5224 | #define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5225 | #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \ |
| 5226 | PD_STATUS_TCPC_ALERT_1 | \ |
| 5227 | PD_STATUS_HOST_EVENT) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5228 | struct ec_response_pd_status { |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5229 | uint32_t curr_lim_ma; /* input current limit */ |
| 5230 | uint16_t status; /* PD MCU status */ |
| 5231 | int8_t active_charge_port; /* active charging port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5232 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5233 | |
| 5234 | /* AP to PD MCU host event status command, cleared on read */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5235 | #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5236 | |
| 5237 | /* PD MCU host event status bits */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5238 | #define PD_EVENT_UPDATE_DEVICE BIT(0) |
| 5239 | #define PD_EVENT_POWER_CHANGE BIT(1) |
| 5240 | #define PD_EVENT_IDENTITY_RECEIVED BIT(2) |
| 5241 | #define PD_EVENT_DATA_SWAP BIT(3) |
| 5242 | struct ec_response_host_event_status { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5243 | uint32_t status; /* PD MCU host event status */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5244 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5245 | |
| 5246 | /* Set USB type-C port role and muxes */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5247 | #define EC_CMD_USB_PD_CONTROL 0x0101 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5248 | |
| 5249 | enum usb_pd_control_role { |
| 5250 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 5251 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 5252 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 5253 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 5254 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5255 | USB_PD_CTRL_ROLE_FREEZE = 5, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5256 | USB_PD_CTRL_ROLE_COUNT |
| 5257 | }; |
| 5258 | |
| 5259 | enum usb_pd_control_mux { |
| 5260 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 5261 | USB_PD_CTRL_MUX_NONE = 1, |
| 5262 | USB_PD_CTRL_MUX_USB = 2, |
| 5263 | USB_PD_CTRL_MUX_DP = 3, |
| 5264 | USB_PD_CTRL_MUX_DOCK = 4, |
| 5265 | USB_PD_CTRL_MUX_AUTO = 5, |
| 5266 | USB_PD_CTRL_MUX_COUNT |
| 5267 | }; |
| 5268 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5269 | enum usb_pd_control_swap { |
| 5270 | USB_PD_CTRL_SWAP_NONE = 0, |
| 5271 | USB_PD_CTRL_SWAP_DATA = 1, |
| 5272 | USB_PD_CTRL_SWAP_POWER = 2, |
| 5273 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 5274 | USB_PD_CTRL_SWAP_COUNT |
| 5275 | }; |
| 5276 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5277 | struct ec_params_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5278 | uint8_t port; |
| 5279 | uint8_t role; |
| 5280 | uint8_t mux; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5281 | uint8_t swap; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5282 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5283 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5284 | #define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */ |
| 5285 | #define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */ |
| 5286 | #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] | 5287 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5288 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 5289 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 5290 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 5291 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 5292 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 5293 | #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5294 | #define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5295 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5296 | struct ec_response_usb_pd_control { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5297 | uint8_t enabled; |
| 5298 | uint8_t role; |
| 5299 | uint8_t polarity; |
| 5300 | uint8_t state; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5301 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5302 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5303 | struct ec_response_usb_pd_control_v1 { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5304 | uint8_t enabled; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5305 | uint8_t role; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5306 | uint8_t polarity; |
| 5307 | char state[32]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5308 | } __ec_align1; |
| 5309 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5310 | /* Possible port partner connections based on CC line states */ |
| 5311 | enum pd_cc_states { |
| 5312 | PD_CC_NONE = 0, /* No port partner attached */ |
| 5313 | |
| 5314 | /* From DFP perspective */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5315 | PD_CC_UFP_NONE = 1, /* No UFP accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5316 | PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */ |
| 5317 | PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */ |
| 5318 | PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */ |
| 5319 | |
| 5320 | /* From UFP perspective */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5321 | PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5322 | PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5323 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5324 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5325 | /* Active/Passive Cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5326 | #define USB_PD_CTRL_ACTIVE_CABLE BIT(0) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5327 | /* Optical/Non-optical cable */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5328 | #define USB_PD_CTRL_OPTICAL_CABLE BIT(1) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5329 | /* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5330 | #define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2) |
| 5331 | /* Active Link Uni-Direction */ |
| 5332 | #define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3) |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5333 | |
| 5334 | /* |
| 5335 | * Underdevelopement : |
| 5336 | * Please remove this tag if using _v2 outside platform/ec |
| 5337 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5338 | struct ec_response_usb_pd_control_v2 { |
| 5339 | uint8_t enabled; |
| 5340 | uint8_t role; |
| 5341 | uint8_t polarity; |
| 5342 | char state[32]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5343 | uint8_t cc_state; /* enum pd_cc_states representing cc state */ |
| 5344 | uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5345 | uint8_t reserved; /* Reserved for future use */ |
| 5346 | uint8_t control_flags; /* USB_PD_CTRL_*flags */ |
| 5347 | uint8_t cable_speed; /* TBT_SS_* cable speed */ |
| 5348 | uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5349 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5350 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5351 | #define EC_CMD_USB_PD_PORTS 0x0102 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5352 | |
Patrick Georgi | 0f6187a | 2017-07-28 15:57:23 +0200 | [diff] [blame] | 5353 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 5354 | #define EC_USB_PD_MAX_PORTS 8 |
| 5355 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5356 | struct ec_response_usb_pd_ports { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5357 | uint8_t num_ports; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5358 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5359 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5360 | #define EC_CMD_USB_PD_POWER_INFO 0x0103 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5361 | |
| 5362 | #define PD_POWER_CHARGING_PORT 0xff |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5363 | struct ec_params_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5364 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5365 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5366 | |
| 5367 | enum usb_chg_type { |
| 5368 | USB_CHG_TYPE_NONE, |
| 5369 | USB_CHG_TYPE_PD, |
| 5370 | USB_CHG_TYPE_C, |
| 5371 | USB_CHG_TYPE_PROPRIETARY, |
| 5372 | USB_CHG_TYPE_BC12_DCP, |
| 5373 | USB_CHG_TYPE_BC12_CDP, |
| 5374 | USB_CHG_TYPE_BC12_SDP, |
| 5375 | USB_CHG_TYPE_OTHER, |
| 5376 | USB_CHG_TYPE_VBUS, |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5377 | USB_CHG_TYPE_UNKNOWN, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5378 | USB_CHG_TYPE_DEDICATED, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5379 | }; |
| 5380 | enum usb_power_roles { |
| 5381 | USB_PD_PORT_POWER_DISCONNECTED, |
| 5382 | USB_PD_PORT_POWER_SOURCE, |
| 5383 | USB_PD_PORT_POWER_SINK, |
| 5384 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 5385 | }; |
| 5386 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5387 | struct usb_chg_measures { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5388 | uint16_t voltage_max; |
| 5389 | uint16_t voltage_now; |
| 5390 | uint16_t current_max; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5391 | uint16_t current_lim; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5392 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5393 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5394 | struct ec_response_usb_pd_power_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5395 | uint8_t role; |
| 5396 | uint8_t type; |
| 5397 | uint8_t dualrole; |
| 5398 | uint8_t reserved1; |
| 5399 | struct usb_chg_measures meas; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5400 | uint32_t max_power; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5401 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5402 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5403 | |
| 5404 | /* |
| 5405 | * This command will return the number of USB PD charge port + the number |
| 5406 | * of dedicated port present. |
| 5407 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 5408 | */ |
| 5409 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5410 | struct ec_response_charge_port_count { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5411 | uint8_t port_count; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5412 | } __ec_align1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5413 | |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5414 | /* Write USB-PD device FW */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5415 | #define EC_CMD_USB_PD_FW_UPDATE 0x0110 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5416 | |
| 5417 | enum usb_pd_fw_update_cmds { |
| 5418 | USB_PD_FW_REBOOT, |
| 5419 | USB_PD_FW_FLASH_ERASE, |
| 5420 | USB_PD_FW_FLASH_WRITE, |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5421 | USB_PD_FW_ERASE_SIG, |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5422 | }; |
| 5423 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5424 | struct ec_params_usb_pd_fw_update { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5425 | uint16_t dev_id; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5426 | uint8_t cmd; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5427 | uint8_t port; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5428 | uint32_t size; /* Size to write in bytes */ |
| 5429 | /* Followed by data to write */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5430 | } __ec_align4; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5431 | |
| 5432 | /* Write USB-PD Accessory RW_HASH table entry */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5433 | #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5434 | /* RW hash is first 20 bytes of SHA-256 of RW section */ |
| 5435 | #define PD_RW_HASH_SIZE 20 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5436 | struct ec_params_usb_pd_rw_hash_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5437 | uint16_t dev_id; |
| 5438 | uint8_t dev_rw_hash[PD_RW_HASH_SIZE]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5439 | uint8_t reserved; /* |
| 5440 | * For alignment of current_image |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5441 | * TODO(rspangler) but it's not aligned! |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5442 | * Should have been reserved[2]. |
| 5443 | */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5444 | uint32_t current_image; /* One of ec_image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5445 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5446 | |
| 5447 | /* Read USB-PD Accessory info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5448 | #define EC_CMD_USB_PD_DEV_INFO 0x0112 |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5449 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5450 | struct ec_params_usb_pd_info_request { |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5451 | uint8_t port; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5452 | } __ec_align1; |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 5453 | |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5454 | /* Read USB-PD Device discovery info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5455 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5456 | struct ec_params_usb_pd_discovery_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5457 | uint16_t vid; /* USB-IF VID */ |
| 5458 | uint16_t pid; /* USB-IF PID */ |
| 5459 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5460 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5461 | |
| 5462 | /* Override default charge behavior */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5463 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5464 | |
| 5465 | /* Negative port parameters have special meaning */ |
| 5466 | enum usb_pd_override_ports { |
| 5467 | OVERRIDE_DONT_CHARGE = -2, |
| 5468 | OVERRIDE_OFF = -1, |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5469 | /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */ |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5470 | }; |
| 5471 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5472 | struct ec_params_charge_port_override { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5473 | int16_t override_port; /* Override port# */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5474 | } __ec_align2; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5475 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5476 | /* |
| 5477 | * Read (and delete) one entry of PD event log. |
| 5478 | * TODO(crbug.com/751742): Make this host command more generic to accommodate |
| 5479 | * future non-PD logs that use the same internal EC event_log. |
| 5480 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5481 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5482 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5483 | struct ec_response_pd_log { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5484 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 5485 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 5486 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 5487 | uint16_t data; /* type-defined data payload */ |
| 5488 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5489 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5490 | |
| 5491 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 5492 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 5493 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5494 | #define PD_LOG_SIZE_MASK 0x1f |
| 5495 | #define PD_LOG_PORT_MASK 0xe0 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5496 | #define PD_LOG_PORT_SHIFT 5 |
| 5497 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 5498 | ((size) & PD_LOG_SIZE_MASK)) |
| 5499 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 5500 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 5501 | |
| 5502 | /* PD event log : entry types */ |
| 5503 | /* PD MCU events */ |
| 5504 | #define PD_EVENT_MCU_BASE 0x00 |
| 5505 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 5506 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 5507 | /* Reserved for custom board event */ |
| 5508 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 5509 | /* PD generic accessory events */ |
| 5510 | #define PD_EVENT_ACC_BASE 0x20 |
| 5511 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 5512 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 5513 | /* PD power supply events */ |
| 5514 | #define PD_EVENT_PS_BASE 0x40 |
| 5515 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 5516 | /* PD video dongles events */ |
| 5517 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 5518 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 5519 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 5520 | /* Returned in the "type" field, when there is no entry available */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5521 | #define PD_EVENT_NO_ENTRY 0xff |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5522 | |
| 5523 | /* |
| 5524 | * PD_EVENT_MCU_CHARGE event definition : |
| 5525 | * the payload is "struct usb_chg_measures" |
| 5526 | * the data field contains the port state flags as defined below : |
| 5527 | */ |
| 5528 | /* Port partner is a dual role device */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5529 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5530 | /* Port is the pending override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5531 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5532 | /* Port is the override port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5533 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5534 | /* Charger type */ |
| 5535 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 5536 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5537 | /* Power delivery role */ |
| 5538 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 5539 | |
| 5540 | /* |
| 5541 | * PD_EVENT_PS_FAULT data field flags definition : |
| 5542 | */ |
| 5543 | #define PS_FAULT_OCP 1 |
| 5544 | #define PS_FAULT_FAST_OCP 2 |
| 5545 | #define PS_FAULT_OVP 3 |
| 5546 | #define PS_FAULT_DISCH 4 |
| 5547 | |
| 5548 | /* |
| 5549 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 5550 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5551 | struct mcdp_version { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5552 | uint8_t major; |
| 5553 | uint8_t minor; |
| 5554 | uint16_t build; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5555 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5556 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5557 | struct mcdp_info { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5558 | uint8_t family[2]; |
| 5559 | uint8_t chipid[2]; |
| 5560 | struct mcdp_version irom; |
| 5561 | struct mcdp_version fw; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5562 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5563 | |
| 5564 | /* struct mcdp_info field decoding */ |
| 5565 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 5566 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 5567 | |
| 5568 | /* Get/Set USB-PD Alternate mode info */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5569 | #define EC_CMD_USB_PD_GET_AMODE 0x0116 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5570 | struct ec_params_usb_pd_get_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5571 | uint16_t svid_idx; /* SVID index to get */ |
| 5572 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5573 | } __ec_align_size1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5574 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5575 | struct ec_params_usb_pd_get_mode_response { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5576 | uint16_t svid; /* SVID */ |
| 5577 | uint16_t opos; /* Object Position */ |
| 5578 | uint32_t vdo[6]; /* Mode VDOs */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5579 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5580 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5581 | #define EC_CMD_USB_PD_SET_AMODE 0x0117 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5582 | |
| 5583 | enum pd_mode_cmd { |
| 5584 | PD_EXIT_MODE = 0, |
| 5585 | PD_ENTER_MODE = 1, |
| 5586 | /* Not a command. Do NOT remove. */ |
| 5587 | PD_MODE_CMD_COUNT, |
| 5588 | }; |
| 5589 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5590 | struct ec_params_usb_pd_set_mode_request { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5591 | uint32_t cmd; /* enum pd_mode_cmd */ |
| 5592 | uint16_t svid; /* SVID to set */ |
| 5593 | uint8_t opos; /* Object Position */ |
| 5594 | uint8_t port; /* port */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5595 | } __ec_align4; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5596 | |
| 5597 | /* Ask the PD MCU to record a log of a requested type */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5598 | #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118 |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5599 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5600 | struct ec_params_pd_write_log_entry { |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5601 | uint8_t type; /* event type : see PD_EVENT_xx above */ |
| 5602 | 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] | 5603 | } __ec_align1; |
Shawn Nematbakhsh | 235f922 | 2015-03-24 11:47:18 -0700 | [diff] [blame] | 5604 | |
Stefan Reinauer | d6682e8 | 2013-02-21 15:39:35 -0800 | [diff] [blame] | 5605 | |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5606 | /* Control USB-PD chip */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5607 | #define EC_CMD_PD_CONTROL 0x0119 |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5608 | |
| 5609 | enum ec_pd_control_cmd { |
| 5610 | PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */ |
| 5611 | PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */ |
| 5612 | PD_RESET, /* Force reset the PD chip */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5613 | PD_CONTROL_DISABLE, /* Disable further calls to this command */ |
| 5614 | PD_CHIP_ON, /* Power on the PD chip */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5615 | }; |
| 5616 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5617 | struct ec_params_pd_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5618 | uint8_t chip; /* chip id */ |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5619 | uint8_t subcmd; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5620 | } __ec_align1; |
Gwendal Grignou | 880b458 | 2016-06-20 08:49:25 -0700 | [diff] [blame] | 5621 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5622 | /* Get info about USB-C SS muxes */ |
| 5623 | #define EC_CMD_USB_PD_MUX_INFO 0x011A |
| 5624 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5625 | struct ec_params_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5626 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5627 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5628 | |
| 5629 | /* Flags representing mux state */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5630 | #define USB_PD_MUX_NONE 0 /* Open switch */ |
| 5631 | #define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */ |
| 5632 | #define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */ |
| 5633 | #define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */ |
| 5634 | #define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */ |
| 5635 | #define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */ |
| 5636 | #define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */ |
| 5637 | #define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5638 | #define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */ |
| 5639 | |
| 5640 | /* USB-C Dock connected */ |
| 5641 | #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] | 5642 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5643 | struct ec_response_usb_pd_mux_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5644 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5645 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5646 | |
| 5647 | #define EC_CMD_PD_CHIP_INFO 0x011B |
| 5648 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5649 | struct ec_params_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5650 | uint8_t port; /* USB-C port number */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5651 | /* |
| 5652 | * Fetch the live chip info or hard-coded + cached chip info |
| 5653 | * 0: hardcoded value for VID/PID, cached value for FW version |
| 5654 | * 1: live chip value for VID/PID/FW Version |
| 5655 | */ |
| 5656 | uint8_t live; |
| 5657 | } __ec_align1; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5658 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5659 | struct ec_response_pd_chip_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5660 | uint16_t vendor_id; |
| 5661 | uint16_t product_id; |
| 5662 | uint16_t device_id; |
| 5663 | union { |
| 5664 | uint8_t fw_version_string[8]; |
| 5665 | uint64_t fw_version_number; |
| 5666 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5667 | } __ec_align2; |
| 5668 | |
| 5669 | struct ec_response_pd_chip_info_v1 { |
| 5670 | uint16_t vendor_id; |
| 5671 | uint16_t product_id; |
| 5672 | uint16_t device_id; |
| 5673 | union { |
| 5674 | uint8_t fw_version_string[8]; |
| 5675 | uint64_t fw_version_number; |
| 5676 | }; |
| 5677 | union { |
| 5678 | uint8_t min_req_fw_version_string[8]; |
| 5679 | uint64_t min_req_fw_version_number; |
| 5680 | }; |
| 5681 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5682 | |
| 5683 | /* Run RW signature verification and get status */ |
| 5684 | #define EC_CMD_RWSIG_CHECK_STATUS 0x011C |
| 5685 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5686 | struct ec_response_rwsig_check_status { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5687 | uint32_t status; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5688 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5689 | |
| 5690 | /* For controlling RWSIG task */ |
| 5691 | #define EC_CMD_RWSIG_ACTION 0x011D |
| 5692 | |
| 5693 | enum rwsig_action { |
| 5694 | RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */ |
| 5695 | RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */ |
| 5696 | }; |
| 5697 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5698 | struct ec_params_rwsig_action { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5699 | uint32_t action; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5700 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5701 | |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5702 | /* Run verification on a slot */ |
| 5703 | #define EC_CMD_EFS_VERIFY 0x011E |
| 5704 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5705 | struct ec_params_efs_verify { |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5706 | uint8_t region; /* enum ec_flash_region */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5707 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5708 | |
| 5709 | /* |
| 5710 | * Retrieve info from Cros Board Info store. Response is based on the data |
| 5711 | * type. Integers return a uint32. Strings return a string, using the response |
| 5712 | * size to determine how big it is. |
| 5713 | */ |
| 5714 | #define EC_CMD_GET_CROS_BOARD_INFO 0x011F |
| 5715 | /* |
| 5716 | * Write info into Cros Board Info on EEPROM. Write fails if the board has |
| 5717 | * hardware write-protect enabled. |
| 5718 | */ |
| 5719 | #define EC_CMD_SET_CROS_BOARD_INFO 0x0120 |
| 5720 | |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5721 | enum cbi_data_tag { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5722 | CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */ |
| 5723 | CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */ |
| 5724 | CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */ |
Aaron Durbin | b388c0e | 2018-08-07 12:24:21 -0600 | [diff] [blame] | 5725 | CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */ |
Wisley Chen | c1efec7 | 2018-11-06 09:28:23 +0800 | [diff] [blame] | 5726 | CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5727 | CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5728 | CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5729 | CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5730 | CBI_TAG_COUNT, |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5731 | }; |
| 5732 | |
| 5733 | /* |
| 5734 | * Flags to control read operation |
| 5735 | * |
| 5736 | * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify |
| 5737 | * write was successful without reboot. |
| 5738 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5739 | #define CBI_GET_RELOAD BIT(0) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5740 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5741 | struct ec_params_get_cbi { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5742 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5743 | uint32_t flag; /* CBI_GET_* */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5744 | } __ec_align4; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5745 | |
| 5746 | /* |
| 5747 | * Flags to control write behavior. |
| 5748 | * |
| 5749 | * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's |
| 5750 | * useful when writing multiple fields in a row. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5751 | * 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] | 5752 | * will be initialized to zero first. |
| 5753 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5754 | #define CBI_SET_NO_SYNC BIT(0) |
| 5755 | #define CBI_SET_INIT BIT(1) |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5756 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5757 | struct ec_params_set_cbi { |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5758 | uint32_t tag; /* enum cbi_data_tag */ |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5759 | uint32_t flag; /* CBI_SET_* */ |
Daisuke Nojiri | f984a05 | 2018-02-15 12:38:15 -0800 | [diff] [blame] | 5760 | uint32_t size; /* Data size */ |
| 5761 | uint8_t data[]; /* For string and raw data */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5762 | } __ec_align1; |
Daisuke Nojiri | 07f9748f | 2018-02-01 07:46:02 -0800 | [diff] [blame] | 5763 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5764 | /* |
| 5765 | * Information about resets of the AP by the EC and the EC's own uptime. |
| 5766 | */ |
| 5767 | #define EC_CMD_GET_UPTIME_INFO 0x0121 |
| 5768 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5769 | /* Reset causes */ |
| 5770 | #define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */ |
| 5771 | #define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */ |
| 5772 | #define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */ |
| 5773 | #define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */ |
| 5774 | #define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */ |
| 5775 | #define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */ |
| 5776 | #define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */ |
| 5777 | #define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */ |
| 5778 | #define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */ |
| 5779 | #define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */ |
| 5780 | #define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */ |
| 5781 | #define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */ |
| 5782 | #define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */ |
| 5783 | #define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from |
| 5784 | * previous boot |
| 5785 | */ |
| 5786 | #define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */ |
| 5787 | #define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */ |
| 5788 | #define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */ |
| 5789 | #define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */ |
| 5790 | #define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 5791 | #define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This |
| 5792 | * enables PD in RO for Chromebox. |
| 5793 | */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5794 | |
| 5795 | struct ec_response_uptime_info { |
| 5796 | /* |
| 5797 | * Number of milliseconds since the last EC boot. Sysjump resets |
| 5798 | * typically do not restart the EC's time_since_boot epoch. |
| 5799 | * |
| 5800 | * WARNING: The EC's sense of time is much less accurate than the AP's |
| 5801 | * sense of time, in both phase and frequency. This timebase is similar |
| 5802 | * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error. |
| 5803 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5804 | uint32_t time_since_ec_boot_ms; |
| 5805 | |
| 5806 | /* |
| 5807 | * Number of times the AP was reset by the EC since the last EC boot. |
| 5808 | * Note that the AP may be held in reset by the EC during the initial |
| 5809 | * boot sequence, such that the very first AP boot may count as more |
| 5810 | * than one here. |
| 5811 | */ |
| 5812 | uint32_t ap_resets_since_ec_boot; |
| 5813 | |
| 5814 | /* |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5815 | * The set of flags which describe the EC's most recent reset. |
| 5816 | * See EC_RESET_FLAG_* for details. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5817 | */ |
| 5818 | uint32_t ec_reset_flags; |
| 5819 | |
| 5820 | /* Empty log entries have both the cause and timestamp set to zero. */ |
| 5821 | struct ap_reset_log_entry { |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5822 | /* |
| 5823 | * See include/chipset.h: enum chipset_{reset,shutdown}_reason |
| 5824 | * for details. |
| 5825 | */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5826 | uint16_t reset_cause; |
| 5827 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5828 | /* Reserved for protocol growth. */ |
| 5829 | uint16_t reserved; |
| 5830 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5831 | /* |
| 5832 | * The time of the reset's assertion, in milliseconds since the |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5833 | * last EC boot, in the same epoch as time_since_ec_boot_ms. |
| 5834 | * Set to zero if the log entry is empty. |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5835 | */ |
| 5836 | uint32_t reset_time_ms; |
| 5837 | } recent_ap_reset[4]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5838 | } __ec_align4; |
| 5839 | |
| 5840 | /* |
| 5841 | * Add entropy to the device secret (stored in the rollback region). |
| 5842 | * |
| 5843 | * Depending on the chip, the operation may take a long time (e.g. to erase |
| 5844 | * flash), so the commands are asynchronous. |
| 5845 | */ |
| 5846 | #define EC_CMD_ADD_ENTROPY 0x0122 |
| 5847 | |
| 5848 | enum add_entropy_action { |
| 5849 | /* Add entropy to the current secret. */ |
| 5850 | ADD_ENTROPY_ASYNC = 0, |
| 5851 | /* |
| 5852 | * Add entropy, and also make sure that the previous secret is erased. |
| 5853 | * (this can be implemented by adding entropy multiple times until |
| 5854 | * all rolback blocks have been overwritten). |
| 5855 | */ |
| 5856 | ADD_ENTROPY_RESET_ASYNC = 1, |
| 5857 | /* Read back result from the previous operation. */ |
| 5858 | ADD_ENTROPY_GET_RESULT = 2, |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 5859 | }; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 5860 | |
| 5861 | struct ec_params_rollback_add_entropy { |
| 5862 | uint8_t action; |
| 5863 | } __ec_align1; |
| 5864 | |
| 5865 | /* |
| 5866 | * Perform a single read of a given ADC channel. |
| 5867 | */ |
| 5868 | #define EC_CMD_ADC_READ 0x0123 |
| 5869 | |
| 5870 | struct ec_params_adc_read { |
| 5871 | uint8_t adc_channel; |
| 5872 | } __ec_align1; |
| 5873 | |
| 5874 | struct ec_response_adc_read { |
| 5875 | int32_t adc_value; |
| 5876 | } __ec_align4; |
| 5877 | |
| 5878 | /* |
| 5879 | * Read back rollback info |
| 5880 | */ |
| 5881 | #define EC_CMD_ROLLBACK_INFO 0x0124 |
| 5882 | |
| 5883 | struct ec_response_rollback_info { |
| 5884 | int32_t id; /* Incrementing number to indicate which region to use. */ |
| 5885 | int32_t rollback_min_version; |
| 5886 | int32_t rw_rollback_version; |
| 5887 | } __ec_align4; |
| 5888 | |
| 5889 | |
| 5890 | /* Issue AP reset */ |
| 5891 | #define EC_CMD_AP_RESET 0x0125 |
| 5892 | |
| 5893 | /*****************************************************************************/ |
| 5894 | /* Locate peripheral chips |
| 5895 | * |
| 5896 | * Return values: |
| 5897 | * EC_RES_UNAVAILABLE: The chip type is supported but not found on system. |
| 5898 | * EC_RES_INVALID_PARAM: The chip type was unrecognized. |
| 5899 | * EC_RES_OVERFLOW: The index number exceeded the number of chip instances. |
| 5900 | */ |
| 5901 | #define EC_CMD_LOCATE_CHIP 0x0126 |
| 5902 | |
| 5903 | enum ec_chip_type { |
| 5904 | EC_CHIP_TYPE_CBI_EEPROM = 0, |
| 5905 | EC_CHIP_TYPE_TCPC = 1, |
| 5906 | EC_CHIP_TYPE_COUNT, |
| 5907 | EC_CHIP_TYPE_MAX = 0xFF, |
| 5908 | }; |
| 5909 | |
| 5910 | enum ec_bus_type { |
| 5911 | EC_BUS_TYPE_I2C = 0, |
| 5912 | EC_BUS_TYPE_EMBEDDED = 1, |
| 5913 | EC_BUS_TYPE_COUNT, |
| 5914 | EC_BUS_TYPE_MAX = 0xFF, |
| 5915 | }; |
| 5916 | |
| 5917 | struct ec_i2c_info { |
| 5918 | uint16_t port; /* Physical port for device */ |
| 5919 | uint16_t addr_flags; /* 7-bit (or 10-bit) address */ |
| 5920 | }; |
| 5921 | |
| 5922 | struct ec_params_locate_chip { |
| 5923 | uint8_t type; /* enum ec_chip_type */ |
| 5924 | uint8_t index; /* Specifies one instance of chip type */ |
| 5925 | /* Used for type specific parameters in future */ |
| 5926 | union { |
| 5927 | uint16_t reserved; |
| 5928 | }; |
| 5929 | } __ec_align2; |
| 5930 | |
| 5931 | |
| 5932 | struct ec_response_locate_chip { |
| 5933 | uint8_t bus_type; /* enum ec_bus_type */ |
| 5934 | uint8_t reserved; /* Aligning the following union to 2 bytes */ |
| 5935 | union { |
| 5936 | struct ec_i2c_info i2c_info; |
| 5937 | }; |
| 5938 | } __ec_align2; |
| 5939 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 5940 | /* |
| 5941 | * Reboot AP on G3 |
| 5942 | * |
| 5943 | * This command is used for validation purpose, where the AP needs to be |
| 5944 | * returned back to S0 state from G3 state without using the servo to trigger |
| 5945 | * wake events.For this,there is no request or response struct. |
| 5946 | * |
| 5947 | * Order of command usage: |
| 5948 | * ectool reboot_ap_on_g3 && shutdown -h now |
| 5949 | */ |
| 5950 | #define EC_CMD_REBOOT_AP_ON_G3 0x0127 |
| 5951 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 5952 | /*****************************************************************************/ |
Tim Wawrzynczak | 87afa90 | 2020-01-22 15:02:48 -0700 | [diff] [blame] | 5953 | /* Get PD port capabilities |
| 5954 | * |
| 5955 | * Returns the following static *capabilities* of the given port: |
| 5956 | * 1) Power role: source, sink, or dual. It is not anticipated that |
| 5957 | * future CrOS devices would ever be only a source, so the options are |
| 5958 | * sink or dual. |
| 5959 | * 2) Try-power role: source, sink, or none (practically speaking, I don't |
| 5960 | * believe any CrOS device would support Try.SNK, so this would be source |
| 5961 | * or none). |
| 5962 | * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual |
| 5963 | * for CrOS devices. |
| 5964 | */ |
| 5965 | #define EC_CMD_GET_PD_PORT_CAPS 0x0128 |
| 5966 | |
| 5967 | enum ec_pd_power_role_caps { |
| 5968 | EC_PD_POWER_ROLE_SOURCE = 0, |
| 5969 | EC_PD_POWER_ROLE_SINK = 1, |
| 5970 | EC_PD_POWER_ROLE_DUAL = 2, |
| 5971 | }; |
| 5972 | |
| 5973 | enum ec_pd_try_power_role_caps { |
| 5974 | EC_PD_TRY_POWER_ROLE_NONE = 0, |
| 5975 | EC_PD_TRY_POWER_ROLE_SINK = 1, |
| 5976 | EC_PD_TRY_POWER_ROLE_SOURCE = 2, |
| 5977 | }; |
| 5978 | |
| 5979 | enum ec_pd_data_role_caps { |
| 5980 | EC_PD_DATA_ROLE_DFP = 0, |
| 5981 | EC_PD_DATA_ROLE_UFP = 1, |
| 5982 | EC_PD_DATA_ROLE_DUAL = 2, |
| 5983 | }; |
| 5984 | |
| 5985 | /* From: power_manager/power_supply_properties.proto */ |
| 5986 | enum ec_pd_port_location { |
| 5987 | /* The location of the port is unknown, or there's only one port. */ |
| 5988 | EC_PD_PORT_LOCATION_UNKNOWN = 0, |
| 5989 | |
| 5990 | /* |
| 5991 | * Various positions on the device. The first word describes the side of |
| 5992 | * the device where the port is located while the second clarifies the |
| 5993 | * position. For example, LEFT_BACK means the farthest-back port on the |
| 5994 | * left side, while BACK_LEFT means the leftmost port on the back of the |
| 5995 | * device. |
| 5996 | */ |
| 5997 | EC_PD_PORT_LOCATION_LEFT = 1, |
| 5998 | EC_PD_PORT_LOCATION_RIGHT = 2, |
| 5999 | EC_PD_PORT_LOCATION_BACK = 3, |
| 6000 | EC_PD_PORT_LOCATION_FRONT = 4, |
| 6001 | EC_PD_PORT_LOCATION_LEFT_FRONT = 5, |
| 6002 | EC_PD_PORT_LOCATION_LEFT_BACK = 6, |
| 6003 | EC_PD_PORT_LOCATION_RIGHT_FRONT = 7, |
| 6004 | EC_PD_PORT_LOCATION_RIGHT_BACK = 8, |
| 6005 | EC_PD_PORT_LOCATION_BACK_LEFT = 9, |
| 6006 | EC_PD_PORT_LOCATION_BACK_RIGHT = 10, |
| 6007 | }; |
| 6008 | |
| 6009 | struct ec_params_get_pd_port_caps { |
| 6010 | uint8_t port; /* Which port to interrogate */ |
| 6011 | } __ec_align1; |
| 6012 | |
| 6013 | struct ec_response_get_pd_port_caps { |
| 6014 | uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */ |
| 6015 | uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */ |
| 6016 | uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */ |
| 6017 | uint8_t pd_port_location; /* enum ec_pd_port_location */ |
| 6018 | } __ec_align1; |
| 6019 | |
| 6020 | /*****************************************************************************/ |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6021 | /* |
| 6022 | * Button press simulation |
| 6023 | * |
| 6024 | * This command is used to simulate a button press. |
| 6025 | * Supported commands are vup(volume up) vdown(volume down) & rec(recovery) |
| 6026 | * Time duration for which button needs to be pressed is an optional parameter. |
| 6027 | * |
| 6028 | * NOTE: This is only available on unlocked devices for testing purposes only. |
| 6029 | */ |
| 6030 | #define EC_CMD_BUTTON 0x0129 |
| 6031 | |
| 6032 | struct ec_params_button { |
| 6033 | /* Button mask aligned to enum keyboard_button_type */ |
| 6034 | uint32_t btn_mask; |
| 6035 | |
| 6036 | /* Duration in milliseconds button needs to be pressed */ |
| 6037 | uint32_t press_ms; |
| 6038 | } __ec_align1; |
| 6039 | |
| 6040 | enum keyboard_button_type { |
| 6041 | KEYBOARD_BUTTON_POWER = 0, |
| 6042 | KEYBOARD_BUTTON_VOLUME_DOWN = 1, |
| 6043 | KEYBOARD_BUTTON_VOLUME_UP = 2, |
| 6044 | KEYBOARD_BUTTON_RECOVERY = 3, |
| 6045 | KEYBOARD_BUTTON_CAPSENSE_1 = 4, |
| 6046 | KEYBOARD_BUTTON_CAPSENSE_2 = 5, |
| 6047 | KEYBOARD_BUTTON_CAPSENSE_3 = 6, |
| 6048 | KEYBOARD_BUTTON_CAPSENSE_4 = 7, |
| 6049 | KEYBOARD_BUTTON_CAPSENSE_5 = 8, |
| 6050 | KEYBOARD_BUTTON_CAPSENSE_6 = 9, |
| 6051 | KEYBOARD_BUTTON_CAPSENSE_7 = 10, |
| 6052 | KEYBOARD_BUTTON_CAPSENSE_8 = 11, |
| 6053 | |
| 6054 | KEYBOARD_BUTTON_COUNT |
| 6055 | }; |
Rajat Jain | c049572 | 2020-04-02 23:58:35 -0700 | [diff] [blame] | 6056 | /*****************************************************************************/ |
| 6057 | /* |
| 6058 | * "Get the Keyboard Config". An EC implementing this command is expected to be |
| 6059 | * vivaldi capable, i.e. can send action codes for the top row keys. |
| 6060 | * Additionally, capability to send function codes for the same keys is |
| 6061 | * optional and acceptable. |
| 6062 | * |
| 6063 | * Note: If the top row can generate both function and action codes by |
| 6064 | * using a dedicated Fn key, it does not matter whether the key sends |
| 6065 | * "function" or "action" codes by default. In both cases, the response |
| 6066 | * for this command will look the same. |
| 6067 | */ |
| 6068 | #define EC_CMD_GET_KEYBD_CONFIG 0x012A |
| 6069 | |
| 6070 | /* Possible values for the top row keys */ |
| 6071 | enum action_key { |
| 6072 | TK_ABSENT = 0, |
| 6073 | TK_BACK = 1, |
| 6074 | TK_FORWARD = 2, |
| 6075 | TK_REFRESH = 3, |
| 6076 | TK_FULLSCREEN = 4, |
| 6077 | TK_OVERVIEW = 5, |
| 6078 | TK_BRIGHTNESS_DOWN = 6, |
| 6079 | TK_BRIGHTNESS_UP = 7, |
| 6080 | TK_VOL_MUTE = 8, |
| 6081 | TK_VOL_DOWN = 9, |
| 6082 | TK_VOL_UP = 10, |
| 6083 | TK_SNAPSHOT = 11, |
| 6084 | TK_PRIVACY_SCRN_TOGGLE = 12, |
| 6085 | TK_KBD_BKLIGHT_DOWN = 13, |
| 6086 | TK_KBD_BKLIGHT_UP = 14, |
| 6087 | TK_PLAY_PAUSE = 15, |
| 6088 | TK_NEXT_TRACK = 16, |
| 6089 | TK_PREV_TRACK = 17, |
| 6090 | }; |
| 6091 | |
| 6092 | /* |
| 6093 | * Max & Min number of top row keys, excluding Esc and Screenlock keys. |
| 6094 | * If this needs to change, please create a new version of the command. |
| 6095 | */ |
| 6096 | #define MAX_TOP_ROW_KEYS 15 |
| 6097 | #define MIN_TOP_ROW_KEYS 10 |
| 6098 | |
| 6099 | /* |
| 6100 | * Is the keyboard capable of sending function keys *in addition to* |
| 6101 | * action keys. This is possible for e.g. if the keyboard has a |
| 6102 | * dedicated Fn key. |
| 6103 | */ |
| 6104 | #define KEYBD_CAP_FUNCTION_KEYS BIT(0) |
| 6105 | /* |
| 6106 | * Whether the keyboard has a dedicated numeric keyboard. |
| 6107 | */ |
| 6108 | #define KEYBD_CAP_NUMERIC_KEYPAD BIT(1) |
| 6109 | /* |
| 6110 | * Whether the keyboard has a screenlock key. |
| 6111 | */ |
| 6112 | #define KEYBD_CAP_SCRNLOCK_KEY BIT(2) |
| 6113 | |
| 6114 | struct ec_response_keybd_config { |
| 6115 | /* |
| 6116 | * Number of top row keys, excluding Esc and Screenlock. |
| 6117 | * If this is 0, all Vivaldi keyboard code is disabled. |
| 6118 | * (i.e. does not expose any tables to the kernel). |
| 6119 | */ |
| 6120 | uint8_t num_top_row_keys; |
| 6121 | |
| 6122 | /* |
| 6123 | * The action keys in the top row, in order from left to right. |
| 6124 | * The values are filled from enum action_key. Esc and Screenlock |
| 6125 | * keys are not considered part of top row keys. |
| 6126 | */ |
| 6127 | uint8_t action_keys[MAX_TOP_ROW_KEYS]; |
| 6128 | |
| 6129 | /* Capability flags */ |
| 6130 | uint8_t capabilities; |
| 6131 | |
| 6132 | } __ec_align1; |
Furquan Shaikh | e6c04b9 | 2020-04-07 22:01:59 -0700 | [diff] [blame] | 6133 | |
| 6134 | /*****************************************************************************/ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6135 | /* The command range 0x200-0x2FF is reserved for Rotor. */ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6136 | |
| 6137 | /*****************************************************************************/ |
| 6138 | /* |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6139 | * Reserve a range of host commands for the CR51 firmware. |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6140 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6141 | #define EC_CMD_CR51_BASE 0x0300 |
| 6142 | #define EC_CMD_CR51_LAST 0x03FF |
| 6143 | |
| 6144 | /*****************************************************************************/ |
| 6145 | /* Fingerprint MCU commands: range 0x0400-0x040x */ |
| 6146 | |
| 6147 | /* Fingerprint SPI sensor passthru command: prototyping ONLY */ |
| 6148 | #define EC_CMD_FP_PASSTHRU 0x0400 |
| 6149 | |
| 6150 | #define EC_FP_FLAG_NOT_COMPLETE 0x1 |
| 6151 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6152 | struct ec_params_fp_passthru { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6153 | uint16_t len; /* Number of bytes to write then read */ |
| 6154 | uint16_t flags; /* EC_FP_FLAG_xxx */ |
| 6155 | uint8_t data[]; /* Data to send */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6156 | } __ec_align2; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6157 | |
| 6158 | /* Configure the Fingerprint MCU behavior */ |
| 6159 | #define EC_CMD_FP_MODE 0x0402 |
| 6160 | |
| 6161 | /* Put the sensor in its lowest power mode */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6162 | #define FP_MODE_DEEPSLEEP BIT(0) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6163 | /* Wait to see a finger on the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6164 | #define FP_MODE_FINGER_DOWN BIT(1) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6165 | /* Poll until the finger has left the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6166 | #define FP_MODE_FINGER_UP BIT(2) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6167 | /* Capture the current finger image */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6168 | #define FP_MODE_CAPTURE BIT(3) |
| 6169 | /* Finger enrollment session on-going */ |
| 6170 | #define FP_MODE_ENROLL_SESSION BIT(4) |
| 6171 | /* Enroll the current finger image */ |
| 6172 | #define FP_MODE_ENROLL_IMAGE BIT(5) |
| 6173 | /* Try to match the current finger image */ |
| 6174 | #define FP_MODE_MATCH BIT(6) |
| 6175 | /* Reset and re-initialize the sensor. */ |
| 6176 | #define FP_MODE_RESET_SENSOR BIT(7) |
| 6177 | /* special value: don't change anything just read back current mode */ |
| 6178 | #define FP_MODE_DONT_CHANGE BIT(31) |
| 6179 | |
| 6180 | #define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \ |
| 6181 | FP_MODE_FINGER_DOWN | \ |
| 6182 | FP_MODE_FINGER_UP | \ |
| 6183 | FP_MODE_CAPTURE | \ |
| 6184 | FP_MODE_ENROLL_SESSION | \ |
| 6185 | FP_MODE_ENROLL_IMAGE | \ |
| 6186 | FP_MODE_MATCH | \ |
| 6187 | FP_MODE_RESET_SENSOR | \ |
| 6188 | FP_MODE_DONT_CHANGE) |
| 6189 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6190 | /* Capture types defined in bits [30..28] */ |
| 6191 | #define FP_MODE_CAPTURE_TYPE_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6192 | #define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT) |
| 6193 | /* |
| 6194 | * This enum must remain ordered, if you add new values you must ensure that |
| 6195 | * FP_CAPTURE_TYPE_MAX is still the last one. |
| 6196 | */ |
| 6197 | enum fp_capture_type { |
| 6198 | /* Full blown vendor-defined capture (produces 'frame_size' bytes) */ |
| 6199 | FP_CAPTURE_VENDOR_FORMAT = 0, |
| 6200 | /* Simple raw image capture (produces width x height x bpp bits) */ |
| 6201 | FP_CAPTURE_SIMPLE_IMAGE = 1, |
| 6202 | /* Self test pattern (e.g. checkerboard) */ |
| 6203 | FP_CAPTURE_PATTERN0 = 2, |
| 6204 | /* Self test pattern (e.g. inverted checkerboard) */ |
| 6205 | FP_CAPTURE_PATTERN1 = 3, |
| 6206 | /* Capture for Quality test with fixed contrast */ |
| 6207 | FP_CAPTURE_QUALITY_TEST = 4, |
| 6208 | /* Capture for pixel reset value test */ |
| 6209 | FP_CAPTURE_RESET_TEST = 5, |
| 6210 | FP_CAPTURE_TYPE_MAX, |
| 6211 | }; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6212 | /* Extracts the capture type from the sensor 'mode' word */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6213 | #define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \ |
| 6214 | >> FP_MODE_CAPTURE_TYPE_SHIFT) |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6215 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6216 | struct ec_params_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6217 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6218 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6219 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6220 | struct ec_response_fp_mode { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6221 | uint32_t mode; /* as defined by FP_MODE_ constants */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6222 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6223 | |
| 6224 | /* Retrieve Fingerprint sensor information */ |
| 6225 | #define EC_CMD_FP_INFO 0x0403 |
| 6226 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6227 | /* Number of dead pixels detected on the last maintenance */ |
| 6228 | #define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF) |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6229 | /* Unknown number of dead pixels detected on the last maintenance */ |
| 6230 | #define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6231 | /* No interrupt from the sensor */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6232 | #define FP_ERROR_NO_IRQ BIT(12) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6233 | /* SPI communication error */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6234 | #define FP_ERROR_SPI_COMM BIT(13) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6235 | /* Invalid sensor Hardware ID */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6236 | #define FP_ERROR_BAD_HWID BIT(14) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6237 | /* Sensor initialization failed */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6238 | #define FP_ERROR_INIT_FAIL BIT(15) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6239 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6240 | struct ec_response_fp_info_v0 { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6241 | /* Sensor identification */ |
| 6242 | uint32_t vendor_id; |
| 6243 | uint32_t product_id; |
| 6244 | uint32_t model_id; |
| 6245 | uint32_t version; |
| 6246 | /* Image frame characteristics */ |
| 6247 | uint32_t frame_size; |
| 6248 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 6249 | uint16_t width; |
| 6250 | uint16_t height; |
| 6251 | uint16_t bpp; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6252 | uint16_t errors; /* see FP_ERROR_ flags above */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6253 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6254 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6255 | struct ec_response_fp_info { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6256 | /* Sensor identification */ |
| 6257 | uint32_t vendor_id; |
| 6258 | uint32_t product_id; |
| 6259 | uint32_t model_id; |
| 6260 | uint32_t version; |
| 6261 | /* Image frame characteristics */ |
| 6262 | uint32_t frame_size; |
| 6263 | uint32_t pixel_format; /* using V4L2_PIX_FMT_ */ |
| 6264 | uint16_t width; |
| 6265 | uint16_t height; |
| 6266 | uint16_t bpp; |
| 6267 | uint16_t errors; /* see FP_ERROR_ flags above */ |
| 6268 | /* Template/finger current information */ |
| 6269 | uint32_t template_size; /* max template size in bytes */ |
| 6270 | uint16_t template_max; /* maximum number of fingers/templates */ |
| 6271 | uint16_t template_valid; /* number of valid fingers/templates */ |
| 6272 | uint32_t template_dirty; /* bitmap of templates with MCU side changes */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6273 | uint32_t template_version; /* version of the template format */ |
| 6274 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6275 | |
| 6276 | /* Get the last captured finger frame or a template content */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6277 | #define EC_CMD_FP_FRAME 0x0404 |
| 6278 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6279 | /* constants defining the 'offset' field which also contains the frame index */ |
| 6280 | #define FP_FRAME_INDEX_SHIFT 28 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6281 | /* Frame buffer where the captured image is stored */ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6282 | #define FP_FRAME_INDEX_RAW_IMAGE 0 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6283 | /* First frame buffer holding a template */ |
| 6284 | #define FP_FRAME_INDEX_TEMPLATE 1 |
| 6285 | #define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT) |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6286 | #define FP_FRAME_OFFSET_MASK 0x0FFFFFFF |
| 6287 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6288 | /* Version of the format of the encrypted templates. */ |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6289 | #define FP_TEMPLATE_FORMAT_VERSION 4 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6290 | |
| 6291 | /* Constants for encryption parameters */ |
| 6292 | #define FP_CONTEXT_NONCE_BYTES 12 |
| 6293 | #define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t)) |
| 6294 | #define FP_CONTEXT_TAG_BYTES 16 |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6295 | #define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16 |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6296 | #define FP_CONTEXT_TPM_BYTES 32 |
| 6297 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6298 | /* Constants for positive match parameters. */ |
| 6299 | #define FP_POSITIVE_MATCH_SALT_BYTES 16 |
| 6300 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6301 | struct ec_fp_template_encryption_metadata { |
| 6302 | /* |
| 6303 | * Version of the structure format (N=3). |
| 6304 | */ |
| 6305 | uint16_t struct_version; |
| 6306 | /* Reserved bytes, set to 0. */ |
| 6307 | uint16_t reserved; |
| 6308 | /* |
| 6309 | * The salt is *only* ever used for key derivation. The nonce is unique, |
| 6310 | * a different one is used for every message. |
| 6311 | */ |
| 6312 | uint8_t nonce[FP_CONTEXT_NONCE_BYTES]; |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6313 | uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6314 | uint8_t tag[FP_CONTEXT_TAG_BYTES]; |
| 6315 | }; |
| 6316 | |
| 6317 | struct ec_params_fp_frame { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6318 | /* |
| 6319 | * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE |
| 6320 | * in the high nibble, and the real offset within the frame in |
| 6321 | * FP_FRAME_OFFSET_MASK. |
| 6322 | */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6323 | uint32_t offset; |
| 6324 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6325 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6326 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6327 | /* Load a template into the MCU */ |
| 6328 | #define EC_CMD_FP_TEMPLATE 0x0405 |
| 6329 | |
| 6330 | /* Flag in the 'size' field indicating that the full template has been sent */ |
| 6331 | #define FP_TEMPLATE_COMMIT 0x80000000 |
| 6332 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6333 | struct ec_params_fp_template { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6334 | uint32_t offset; |
| 6335 | uint32_t size; |
| 6336 | uint8_t data[]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6337 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6338 | |
| 6339 | /* Clear the current fingerprint user context and set a new one */ |
| 6340 | #define EC_CMD_FP_CONTEXT 0x0406 |
| 6341 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6342 | struct ec_params_fp_context { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6343 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6344 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6345 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6346 | enum fp_context_action { |
| 6347 | FP_CONTEXT_ASYNC = 0, |
| 6348 | FP_CONTEXT_GET_RESULT = 1, |
| 6349 | }; |
| 6350 | |
| 6351 | /* Version 1 of the command is "asynchronous". */ |
| 6352 | struct ec_params_fp_context_v1 { |
| 6353 | uint8_t action; /**< enum fp_context_action */ |
| 6354 | uint8_t reserved[3]; /**< padding for alignment */ |
| 6355 | uint32_t userid[FP_CONTEXT_USERID_WORDS]; |
| 6356 | } __ec_align4; |
| 6357 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6358 | #define EC_CMD_FP_STATS 0x0407 |
| 6359 | |
| 6360 | #define FPSTATS_CAPTURE_INV BIT(0) |
| 6361 | #define FPSTATS_MATCHING_INV BIT(1) |
| 6362 | |
| 6363 | struct ec_response_fp_stats { |
| 6364 | uint32_t capture_time_us; |
| 6365 | uint32_t matching_time_us; |
| 6366 | uint32_t overall_time_us; |
| 6367 | struct { |
| 6368 | uint32_t lo; |
| 6369 | uint32_t hi; |
| 6370 | } overall_t0; |
| 6371 | uint8_t timestamps_invalid; |
| 6372 | int8_t template_matched; |
| 6373 | } __ec_align2; |
| 6374 | |
| 6375 | #define EC_CMD_FP_SEED 0x0408 |
| 6376 | struct ec_params_fp_seed { |
| 6377 | /* |
| 6378 | * Version of the structure format (N=3). |
| 6379 | */ |
| 6380 | uint16_t struct_version; |
| 6381 | /* Reserved bytes, set to 0. */ |
| 6382 | uint16_t reserved; |
| 6383 | /* Seed from the TPM. */ |
| 6384 | uint8_t seed[FP_CONTEXT_TPM_BYTES]; |
| 6385 | } __ec_align4; |
| 6386 | |
| 6387 | #define EC_CMD_FP_ENC_STATUS 0x0409 |
| 6388 | |
| 6389 | /* FP TPM seed has been set or not */ |
| 6390 | #define FP_ENC_STATUS_SEED_SET BIT(0) |
| 6391 | |
| 6392 | struct ec_response_fp_encryption_status { |
| 6393 | /* Used bits in encryption engine status */ |
| 6394 | uint32_t valid_flags; |
| 6395 | /* Encryption engine status */ |
| 6396 | uint32_t status; |
| 6397 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6398 | |
Jett Rink | ba2edaf | 2020-01-14 11:49:06 -0700 | [diff] [blame] | 6399 | #define EC_CMD_FP_READ_MATCH_SECRET 0x040A |
| 6400 | struct ec_params_fp_read_match_secret { |
| 6401 | uint16_t fgr; |
| 6402 | } __ec_align4; |
| 6403 | |
| 6404 | /* The positive match secret has the length of the SHA256 digest. */ |
| 6405 | #define FP_POSITIVE_MATCH_SECRET_BYTES 32 |
| 6406 | struct ec_response_fp_read_match_secret { |
| 6407 | uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES]; |
| 6408 | } __ec_align4; |
| 6409 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6410 | /*****************************************************************************/ |
| 6411 | /* Touchpad MCU commands: range 0x0500-0x05FF */ |
| 6412 | |
| 6413 | /* Perform touchpad self test */ |
| 6414 | #define EC_CMD_TP_SELF_TEST 0x0500 |
| 6415 | |
| 6416 | /* Get number of frame types, and the size of each type */ |
| 6417 | #define EC_CMD_TP_FRAME_INFO 0x0501 |
| 6418 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6419 | struct ec_response_tp_frame_info { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6420 | uint32_t n_frames; |
| 6421 | uint32_t frame_sizes[0]; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6422 | } __ec_align4; |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6423 | |
| 6424 | /* Create a snapshot of current frame readings */ |
| 6425 | #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502 |
| 6426 | |
| 6427 | /* Read the frame */ |
| 6428 | #define EC_CMD_TP_FRAME_GET 0x0503 |
| 6429 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6430 | struct ec_params_tp_frame_get { |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6431 | uint32_t frame_index; |
| 6432 | uint32_t offset; |
| 6433 | uint32_t size; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6434 | } __ec_align4; |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6435 | |
| 6436 | /*****************************************************************************/ |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6437 | /* EC-EC communication commands: range 0x0600-0x06FF */ |
| 6438 | |
| 6439 | #define EC_COMM_TEXT_MAX 8 |
| 6440 | |
| 6441 | /* |
| 6442 | * Get battery static information, i.e. information that never changes, or |
| 6443 | * very infrequently. |
| 6444 | */ |
| 6445 | #define EC_CMD_BATTERY_GET_STATIC 0x0600 |
| 6446 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6447 | /** |
| 6448 | * struct ec_params_battery_static_info - Battery static info parameters |
| 6449 | * @index: Battery index. |
| 6450 | */ |
| 6451 | struct ec_params_battery_static_info { |
| 6452 | uint8_t index; |
| 6453 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6454 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6455 | /** |
| 6456 | * struct ec_response_battery_static_info - Battery static info response |
| 6457 | * @design_capacity: Battery Design Capacity (mAh) |
| 6458 | * @design_voltage: Battery Design Voltage (mV) |
| 6459 | * @manufacturer: Battery Manufacturer String |
| 6460 | * @model: Battery Model Number String |
| 6461 | * @serial: Battery Serial Number String |
| 6462 | * @type: Battery Type String |
| 6463 | * @cycle_count: Battery Cycle Count |
| 6464 | */ |
| 6465 | struct ec_response_battery_static_info { |
| 6466 | uint16_t design_capacity; |
| 6467 | uint16_t design_voltage; |
| 6468 | char manufacturer[EC_COMM_TEXT_MAX]; |
| 6469 | char model[EC_COMM_TEXT_MAX]; |
| 6470 | char serial[EC_COMM_TEXT_MAX]; |
| 6471 | char type[EC_COMM_TEXT_MAX]; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6472 | /* TODO(crbug.com/795991): Consider moving to dynamic structure. */ |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6473 | uint32_t cycle_count; |
| 6474 | } __ec_align4; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6475 | |
| 6476 | /* |
| 6477 | * Get battery dynamic information, i.e. information that is likely to change |
| 6478 | * every time it is read. |
| 6479 | */ |
| 6480 | #define EC_CMD_BATTERY_GET_DYNAMIC 0x0601 |
| 6481 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6482 | /** |
| 6483 | * struct ec_params_battery_dynamic_info - Battery dynamic info parameters |
| 6484 | * @index: Battery index. |
| 6485 | */ |
| 6486 | struct ec_params_battery_dynamic_info { |
| 6487 | uint8_t index; |
| 6488 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6489 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6490 | /** |
| 6491 | * struct ec_response_battery_dynamic_info - Battery dynamic info response |
| 6492 | * @actual_voltage: Battery voltage (mV) |
| 6493 | * @actual_current: Battery current (mA); negative=discharging |
| 6494 | * @remaining_capacity: Remaining capacity (mAh) |
| 6495 | * @full_capacity: Capacity (mAh, might change occasionally) |
| 6496 | * @flags: Flags, see EC_BATT_FLAG_* |
| 6497 | * @desired_voltage: Charging voltage desired by battery (mV) |
| 6498 | * @desired_current: Charging current desired by battery (mA) |
| 6499 | */ |
| 6500 | struct ec_response_battery_dynamic_info { |
| 6501 | int16_t actual_voltage; |
| 6502 | int16_t actual_current; |
| 6503 | int16_t remaining_capacity; |
| 6504 | int16_t full_capacity; |
| 6505 | int16_t flags; |
| 6506 | int16_t desired_voltage; |
| 6507 | int16_t desired_current; |
| 6508 | } __ec_align2; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6509 | |
| 6510 | /* |
| 6511 | * Control charger chip. Used to control charger chip on the slave. |
| 6512 | */ |
| 6513 | #define EC_CMD_CHARGER_CONTROL 0x0602 |
| 6514 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6515 | /** |
| 6516 | * struct ec_params_charger_control - Charger control parameters |
| 6517 | * @max_current: Charger current (mA). Positive to allow base to draw up to |
| 6518 | * max_current and (possibly) charge battery, negative to request current |
| 6519 | * from base (OTG). |
| 6520 | * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is |
| 6521 | * >= 0. |
| 6522 | * @allow_charging: Allow base battery charging (only makes sense if |
| 6523 | * max_current > 0). |
| 6524 | */ |
| 6525 | struct ec_params_charger_control { |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6526 | int16_t max_current; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6527 | uint16_t otg_voltage; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6528 | uint8_t allow_charging; |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6529 | } __ec_align_size1; |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6530 | |
| 6531 | /*****************************************************************************/ |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6532 | /* |
| 6533 | * Reserve a range of host commands for board-specific, experimental, or |
| 6534 | * special purpose features. These can be (re)used without updating this file. |
| 6535 | * |
| 6536 | * CAUTION: Don't go nuts with this. Shipping products should document ALL |
| 6537 | * their EC commands for easier development, testing, debugging, and support. |
| 6538 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6539 | * All commands MUST be #defined to be 4-digit UPPER CASE hex values |
| 6540 | * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work. |
| 6541 | * |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6542 | * In your experimental code, you may want to do something like this: |
| 6543 | * |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6544 | * #define EC_CMD_MAGIC_FOO 0x0000 |
| 6545 | * #define EC_CMD_MAGIC_BAR 0x0001 |
| 6546 | * #define EC_CMD_MAGIC_HEY 0x0002 |
| 6547 | * |
| 6548 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler, |
| 6549 | * EC_VER_MASK(0); |
| 6550 | * |
| 6551 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler, |
| 6552 | * EC_VER_MASK(0); |
| 6553 | * |
| 6554 | * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler, |
| 6555 | * EC_VER_MASK(0); |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6556 | */ |
| 6557 | #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00 |
| 6558 | #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF |
| 6559 | |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6560 | /* |
| 6561 | * Given the private host command offset, calculate the true private host |
| 6562 | * command value. |
| 6563 | */ |
| 6564 | #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \ |
| 6565 | (EC_CMD_BOARD_SPECIFIC_BASE + (command)) |
| 6566 | |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 6567 | /*****************************************************************************/ |
| 6568 | /* |
Duncan Laurie | 8caa80b | 2014-09-18 12:48:06 -0700 | [diff] [blame] | 6569 | * Passthru commands |
| 6570 | * |
| 6571 | * Some platforms have sub-processors chained to each other. For example. |
| 6572 | * |
| 6573 | * AP <--> EC <--> PD MCU |
| 6574 | * |
| 6575 | * The top 2 bits of the command number are used to indicate which device the |
| 6576 | * command is intended for. Device 0 is always the device receiving the |
| 6577 | * command; other device mapping is board-specific. |
| 6578 | * |
| 6579 | * When a device receives a command to be passed to a sub-processor, it passes |
| 6580 | * it on with the device number set back to 0. This allows the sub-processor |
| 6581 | * to remain blissfully unaware of whether the command originated on the next |
| 6582 | * device up the chain, or was passed through from the AP. |
| 6583 | * |
| 6584 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 6585 | * AP sends command 0x4002 to the EC |
| 6586 | * EC sends command 0x0002 to the PD MCU |
| 6587 | * EC forwards PD MCU response back to the AP |
| 6588 | */ |
| 6589 | |
| 6590 | /* Offset and max command number for sub-device n */ |
| 6591 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 6592 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 6593 | |
| 6594 | /*****************************************************************************/ |
| 6595 | /* |
Duncan Laurie | 93e2444 | 2014-01-06 12:30:52 -0800 | [diff] [blame] | 6596 | * Deprecated constants. These constants have been renamed for clarity. The |
| 6597 | * meaning and size has not changed. Programs that use the old names should |
| 6598 | * switch to the new names soon, as the old names may not be carried forward |
| 6599 | * forever. |
| 6600 | */ |
| 6601 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 6602 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 6603 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 6604 | |
Jonathan Brandmeyer | 6bffc5c | 2018-07-23 16:30:44 -0600 | [diff] [blame] | 6605 | #endif /* !__ACPI__ */ |
Duncan Laurie | 67f26cc | 2017-06-29 23:17:22 -0700 | [diff] [blame] | 6606 | |
You-Cheng Syu | 8d6ea6a | 2019-03-13 21:37:23 +0800 | [diff] [blame] | 6607 | #ifdef __cplusplus |
| 6608 | } |
| 6609 | #endif |
| 6610 | |
Duncan Laurie | eb31685 | 2015-12-01 18:51:18 -0800 | [diff] [blame] | 6611 | #endif /* __CROS_EC_EC_COMMANDS_H */ |