Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Host communication command constants for ChromeOS EC |
| 3 | * |
| 4 | * Copyright (C) 2012 Google, Inc |
| 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * The ChromeOS EC multi function device is used to mux all the requests |
| 16 | * to the EC device for its multiple features: keyboard controller, |
| 17 | * battery charging and regulator control, firmware update. |
| 18 | * |
| 19 | * NOTE: This file is copied verbatim from the ChromeOS EC Open Source |
| 20 | * project in an attempt to make future updates easy to make. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __CROS_EC_COMMANDS_H |
| 24 | #define __CROS_EC_COMMANDS_H |
| 25 | |
| 26 | /* |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 27 | * Current version of this protocol |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 28 | * |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 29 | * TODO(crosbug.com/p/11223): This is effectively useless; protocol is |
| 30 | * determined in other ways. Remove this once the kernel code no longer |
| 31 | * depends on it. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 32 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 33 | #define EC_PROTO_VERSION 0x00000002 |
| 34 | |
| 35 | /* Command version mask */ |
| 36 | #define EC_VER_MASK(version) (1UL << (version)) |
| 37 | |
| 38 | /* I/O addresses for ACPI commands */ |
| 39 | #define EC_LPC_ADDR_ACPI_DATA 0x62 |
| 40 | #define EC_LPC_ADDR_ACPI_CMD 0x66 |
| 41 | |
| 42 | /* I/O addresses for host command */ |
| 43 | #define EC_LPC_ADDR_HOST_DATA 0x200 |
| 44 | #define EC_LPC_ADDR_HOST_CMD 0x204 |
| 45 | |
| 46 | /* I/O addresses for host command args and params */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 47 | /* Protocol version 2 */ |
| 48 | #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ |
| 49 | #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is |
| 50 | * EC_PROTO2_MAX_PARAM_SIZE */ |
| 51 | /* Protocol version 3 */ |
| 52 | #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ |
| 53 | #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 54 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 55 | /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff |
| 56 | * and they tell the kernel that so we have to think of it as two parts. */ |
| 57 | #define EC_HOST_CMD_REGION0 0x800 |
| 58 | #define EC_HOST_CMD_REGION1 0x880 |
| 59 | #define EC_HOST_CMD_REGION_SIZE 0x80 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 60 | |
| 61 | /* EC command register bit functions */ |
| 62 | #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */ |
| 63 | #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */ |
| 64 | #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */ |
| 65 | #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */ |
| 66 | #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */ |
| 67 | #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */ |
| 68 | #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */ |
| 69 | |
| 70 | #define EC_LPC_ADDR_MEMMAP 0x900 |
| 71 | #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ |
| 72 | #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ |
| 73 | |
| 74 | /* The offset address of each type of data in mapped memory. */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 75 | #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */ |
| 76 | #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */ |
| 77 | #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */ |
| 78 | #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 79 | #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ |
| 80 | #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ |
| 81 | #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ |
| 82 | #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ |
| 83 | #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 84 | #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */ |
| 85 | /* Unused 0x28 - 0x2f */ |
| 86 | #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ |
| 87 | /* Unused 0x31 - 0x33 */ |
| 88 | #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */ |
| 89 | /* Reserve 0x38 - 0x3f for additional host event-related stuff */ |
| 90 | /* Battery values are all 32 bits */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 91 | #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ |
| 92 | #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ |
| 93 | #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ |
| 94 | #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */ |
| 95 | #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ |
| 96 | #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ |
| 97 | #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ |
| 98 | #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 99 | /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 100 | #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ |
| 101 | #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ |
| 102 | #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ |
| 103 | #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 104 | #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */ |
| 105 | /* Unused 0x84 - 0x8f */ |
| 106 | #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ |
| 107 | /* Unused 0x91 */ |
| 108 | #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */ |
| 109 | #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ |
| 110 | /* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */ |
| 111 | |
| 112 | |
| 113 | /* Define the format of the accelerometer mapped memory status byte. */ |
| 114 | #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f |
| 115 | #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4) |
| 116 | #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7) |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 117 | |
| 118 | /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ |
| 119 | #define EC_TEMP_SENSOR_ENTRIES 16 |
| 120 | /* |
| 121 | * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B. |
| 122 | * |
| 123 | * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. |
| 124 | */ |
| 125 | #define EC_TEMP_SENSOR_B_ENTRIES 8 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 126 | |
| 127 | /* Special values for mapped temperature sensors */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 128 | #define EC_TEMP_SENSOR_NOT_PRESENT 0xff |
| 129 | #define EC_TEMP_SENSOR_ERROR 0xfe |
| 130 | #define EC_TEMP_SENSOR_NOT_POWERED 0xfd |
| 131 | #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc |
| 132 | /* |
| 133 | * The offset of temperature value stored in mapped memory. This allows |
| 134 | * reporting a temperature range of 200K to 454K = -73C to 181C. |
| 135 | */ |
| 136 | #define EC_TEMP_SENSOR_OFFSET 200 |
| 137 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 138 | /* |
| 139 | * Number of ALS readings at EC_MEMMAP_ALS |
| 140 | */ |
| 141 | #define EC_ALS_ENTRIES 2 |
| 142 | |
| 143 | /* |
| 144 | * The default value a temperature sensor will return when it is present but |
| 145 | * has not been read this boot. This is a reasonable number to avoid |
| 146 | * triggering alarms on the host. |
| 147 | */ |
| 148 | #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET) |
| 149 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 150 | #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ |
| 151 | #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ |
| 152 | #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ |
| 153 | |
| 154 | /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */ |
| 155 | #define EC_BATT_FLAG_AC_PRESENT 0x01 |
| 156 | #define EC_BATT_FLAG_BATT_PRESENT 0x02 |
| 157 | #define EC_BATT_FLAG_DISCHARGING 0x04 |
| 158 | #define EC_BATT_FLAG_CHARGING 0x08 |
| 159 | #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 |
| 160 | |
| 161 | /* Switch flags at EC_MEMMAP_SWITCHES */ |
| 162 | #define EC_SWITCH_LID_OPEN 0x01 |
| 163 | #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 |
| 164 | #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 165 | /* Was recovery requested via keyboard; now unused. */ |
| 166 | #define EC_SWITCH_IGNORE1 0x08 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 167 | /* Recovery requested via dedicated signal (from servo board) */ |
| 168 | #define EC_SWITCH_DEDICATED_RECOVERY 0x10 |
| 169 | /* Was fake developer mode switch; now unused. Remove in next refactor. */ |
| 170 | #define EC_SWITCH_IGNORE0 0x20 |
| 171 | |
| 172 | /* Host command interface flags */ |
| 173 | /* Host command interface supports LPC args (LPC interface only) */ |
| 174 | #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 175 | /* Host command interface supports version 3 protocol */ |
| 176 | #define EC_HOST_CMD_FLAG_VERSION_3 0x02 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 177 | |
| 178 | /* Wireless switch flags */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 179 | #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */ |
| 180 | #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */ |
| 181 | #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */ |
| 182 | #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ |
| 183 | #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 184 | |
| 185 | /* |
| 186 | * This header file is used in coreboot both in C and ACPI code. The ACPI code |
| 187 | * is pre-processed to handle constants but the ASL compiler is unable to |
| 188 | * handle actual C code so keep it separate. |
| 189 | */ |
| 190 | #ifndef __ACPI__ |
| 191 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 192 | /* |
| 193 | * Define __packed if someone hasn't beat us to it. Linux kernel style |
| 194 | * checking prefers __packed over __attribute__((packed)). |
| 195 | */ |
| 196 | #ifndef __packed |
| 197 | #define __packed __attribute__((packed)) |
| 198 | #endif |
| 199 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 200 | /* LPC command status byte masks */ |
| 201 | /* EC has written a byte in the data register and host hasn't read it yet */ |
| 202 | #define EC_LPC_STATUS_TO_HOST 0x01 |
| 203 | /* Host has written a command/data byte and the EC hasn't read it yet */ |
| 204 | #define EC_LPC_STATUS_FROM_HOST 0x02 |
| 205 | /* EC is processing a command */ |
| 206 | #define EC_LPC_STATUS_PROCESSING 0x04 |
| 207 | /* Last write to EC was a command, not data */ |
| 208 | #define EC_LPC_STATUS_LAST_CMD 0x08 |
| 209 | /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */ |
| 210 | #define EC_LPC_STATUS_BURST_MODE 0x10 |
| 211 | /* SCI event is pending (requesting SCI query) */ |
| 212 | #define EC_LPC_STATUS_SCI_PENDING 0x20 |
| 213 | /* SMI event is pending (requesting SMI query) */ |
| 214 | #define EC_LPC_STATUS_SMI_PENDING 0x40 |
| 215 | /* (reserved) */ |
| 216 | #define EC_LPC_STATUS_RESERVED 0x80 |
| 217 | |
| 218 | /* |
| 219 | * EC is busy. This covers both the EC processing a command, and the host has |
| 220 | * written a new command but the EC hasn't picked it up yet. |
| 221 | */ |
| 222 | #define EC_LPC_STATUS_BUSY_MASK \ |
| 223 | (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) |
| 224 | |
| 225 | /* Host command response codes */ |
| 226 | enum ec_status { |
| 227 | EC_RES_SUCCESS = 0, |
| 228 | EC_RES_INVALID_COMMAND = 1, |
| 229 | EC_RES_ERROR = 2, |
| 230 | EC_RES_INVALID_PARAM = 3, |
| 231 | EC_RES_ACCESS_DENIED = 4, |
| 232 | EC_RES_INVALID_RESPONSE = 5, |
| 233 | EC_RES_INVALID_VERSION = 6, |
| 234 | EC_RES_INVALID_CHECKSUM = 7, |
| 235 | EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */ |
| 236 | EC_RES_UNAVAILABLE = 9, /* No response available */ |
| 237 | EC_RES_TIMEOUT = 10, /* We got a timeout */ |
| 238 | EC_RES_OVERFLOW = 11, /* Table / data overflow */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 239 | EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ |
| 240 | EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ |
| 241 | EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | /* |
| 245 | * Host event codes. Note these are 1-based, not 0-based, because ACPI query |
| 246 | * EC command uses code 0 to mean "no event pending". We explicitly specify |
| 247 | * each value in the enum listing so they won't change if we delete/insert an |
| 248 | * item or rearrange the list (it needs to be stable across platforms, not |
| 249 | * just within a single compiled instance). |
| 250 | */ |
| 251 | enum host_event_code { |
| 252 | EC_HOST_EVENT_LID_CLOSED = 1, |
| 253 | EC_HOST_EVENT_LID_OPEN = 2, |
| 254 | EC_HOST_EVENT_POWER_BUTTON = 3, |
| 255 | EC_HOST_EVENT_AC_CONNECTED = 4, |
| 256 | EC_HOST_EVENT_AC_DISCONNECTED = 5, |
| 257 | EC_HOST_EVENT_BATTERY_LOW = 6, |
| 258 | EC_HOST_EVENT_BATTERY_CRITICAL = 7, |
| 259 | EC_HOST_EVENT_BATTERY = 8, |
| 260 | EC_HOST_EVENT_THERMAL_THRESHOLD = 9, |
| 261 | EC_HOST_EVENT_THERMAL_OVERLOAD = 10, |
| 262 | EC_HOST_EVENT_THERMAL = 11, |
| 263 | EC_HOST_EVENT_USB_CHARGER = 12, |
| 264 | EC_HOST_EVENT_KEY_PRESSED = 13, |
| 265 | /* |
| 266 | * EC has finished initializing the host interface. The host can check |
| 267 | * for this event following sending a EC_CMD_REBOOT_EC command to |
| 268 | * determine when the EC is ready to accept subsequent commands. |
| 269 | */ |
| 270 | EC_HOST_EVENT_INTERFACE_READY = 14, |
| 271 | /* Keyboard recovery combo has been pressed */ |
| 272 | EC_HOST_EVENT_KEYBOARD_RECOVERY = 15, |
| 273 | |
| 274 | /* Shutdown due to thermal overload */ |
| 275 | EC_HOST_EVENT_THERMAL_SHUTDOWN = 16, |
| 276 | /* Shutdown due to battery level too low */ |
| 277 | EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, |
| 278 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 279 | /* Suggest that the AP throttle itself */ |
| 280 | EC_HOST_EVENT_THROTTLE_START = 18, |
| 281 | /* Suggest that the AP resume normal speed */ |
| 282 | EC_HOST_EVENT_THROTTLE_STOP = 19, |
| 283 | |
| 284 | /* Hang detect logic detected a hang and host event timeout expired */ |
| 285 | EC_HOST_EVENT_HANG_DETECT = 20, |
| 286 | /* Hang detect logic detected a hang and warm rebooted the AP */ |
| 287 | EC_HOST_EVENT_HANG_REBOOT = 21, |
Benson Leung | c698316 | 2017-07-17 11:41:39 +0200 | [diff] [blame] | 288 | /* PD MCU triggering host event */ |
| 289 | EC_HOST_EVENT_PD_MCU = 22, |
| 290 | |
| 291 | /* EC desires to change state of host-controlled USB mux */ |
| 292 | EC_HOST_EVENT_USB_MUX = 28, |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 293 | |
Stephen Barber | 3eff6d2 | 2017-11-10 22:55:52 +0100 | [diff] [blame] | 294 | /* EC RTC event occurred */ |
| 295 | EC_HOST_EVENT_RTC = 26, |
| 296 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 297 | /* |
| 298 | * The high bit of the event mask is not used as a host event code. If |
| 299 | * it reads back as set, then the entire event mask should be |
| 300 | * considered invalid by the host. This can happen when reading the |
| 301 | * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is |
| 302 | * not initialized on the EC, or improperly configured on the host. |
| 303 | */ |
| 304 | EC_HOST_EVENT_INVALID = 32 |
| 305 | }; |
| 306 | /* Host event mask */ |
| 307 | #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1)) |
| 308 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 309 | /** |
| 310 | * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS |
| 311 | * @flags: The host argument flags. |
| 312 | * @command_version: Command version. |
| 313 | * @data_size: The length of data. |
| 314 | * @checksum: Checksum; sum of command + flags + command_version + data_size + |
| 315 | * all params/response data bytes. |
| 316 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 317 | struct ec_lpc_host_args { |
| 318 | uint8_t flags; |
| 319 | uint8_t command_version; |
| 320 | uint8_t data_size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 321 | uint8_t checksum; |
| 322 | } __packed; |
| 323 | |
| 324 | /* Flags for ec_lpc_host_args.flags */ |
| 325 | /* |
| 326 | * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command |
| 327 | * params. |
| 328 | * |
| 329 | * If EC gets a command and this flag is not set, this is an old-style command. |
| 330 | * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with |
| 331 | * unknown length. EC must respond with an old-style response (that is, |
| 332 | * withouth setting EC_HOST_ARGS_FLAG_TO_HOST). |
| 333 | */ |
| 334 | #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 |
| 335 | /* |
| 336 | * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response. |
| 337 | * |
| 338 | * If EC responds to a command and this flag is not set, this is an old-style |
| 339 | * response. Command version is 0 and response data from EC is at |
| 340 | * EC_LPC_ADDR_OLD_PARAM with unknown length. |
| 341 | */ |
| 342 | #define EC_HOST_ARGS_FLAG_TO_HOST 0x02 |
| 343 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 344 | /*****************************************************************************/ |
| 345 | /* |
| 346 | * Byte codes returned by EC over SPI interface. |
| 347 | * |
| 348 | * These can be used by the AP to debug the EC interface, and to determine |
| 349 | * when the EC is not in a state where it will ever get around to responding |
| 350 | * to the AP. |
| 351 | * |
| 352 | * Example of sequence of bytes read from EC for a current good transfer: |
| 353 | * 1. - - AP asserts chip select (CS#) |
| 354 | * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request |
| 355 | * 3. - - EC starts handling CS# interrupt |
| 356 | * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request |
| 357 | * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in |
| 358 | * bytes looking for EC_SPI_FRAME_START |
| 359 | * 6. - - EC finishes processing and sets up response |
| 360 | * 7. EC_SPI_FRAME_START - AP reads frame byte |
| 361 | * 8. (response packet) - AP reads response packet |
| 362 | * 9. EC_SPI_PAST_END - Any additional bytes read by AP |
| 363 | * 10 - - AP deasserts chip select |
| 364 | * 11 - - EC processes CS# interrupt and sets up DMA for |
| 365 | * next request |
| 366 | * |
| 367 | * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than |
| 368 | * the following byte values: |
| 369 | * EC_SPI_OLD_READY |
| 370 | * EC_SPI_RX_READY |
| 371 | * EC_SPI_RECEIVING |
| 372 | * EC_SPI_PROCESSING |
| 373 | * |
| 374 | * Then the EC found an error in the request, or was not ready for the request |
| 375 | * and lost data. The AP should give up waiting for EC_SPI_FRAME_START, |
| 376 | * because the EC is unable to tell when the AP is done sending its request. |
| 377 | */ |
| 378 | |
| 379 | /* |
| 380 | * Framing byte which precedes a response packet from the EC. After sending a |
| 381 | * request, the AP will clock in bytes until it sees the framing byte, then |
| 382 | * clock in the response packet. |
| 383 | */ |
| 384 | #define EC_SPI_FRAME_START 0xec |
| 385 | |
| 386 | /* |
| 387 | * Padding bytes which are clocked out after the end of a response packet. |
| 388 | */ |
| 389 | #define EC_SPI_PAST_END 0xed |
| 390 | |
| 391 | /* |
| 392 | * EC is ready to receive, and has ignored the byte sent by the AP. EC expects |
| 393 | * that the AP will send a valid packet header (starting with |
| 394 | * EC_COMMAND_PROTOCOL_3) in the next 32 bytes. |
| 395 | */ |
| 396 | #define EC_SPI_RX_READY 0xf8 |
| 397 | |
| 398 | /* |
| 399 | * EC has started receiving the request from the AP, but hasn't started |
| 400 | * processing it yet. |
| 401 | */ |
| 402 | #define EC_SPI_RECEIVING 0xf9 |
| 403 | |
| 404 | /* EC has received the entire request from the AP and is processing it. */ |
| 405 | #define EC_SPI_PROCESSING 0xfa |
| 406 | |
| 407 | /* |
| 408 | * EC received bad data from the AP, such as a packet header with an invalid |
| 409 | * length. EC will ignore all data until chip select deasserts. |
| 410 | */ |
| 411 | #define EC_SPI_RX_BAD_DATA 0xfb |
| 412 | |
| 413 | /* |
| 414 | * EC received data from the AP before it was ready. That is, the AP asserted |
| 415 | * chip select and started clocking data before the EC was ready to receive it. |
| 416 | * EC will ignore all data until chip select deasserts. |
| 417 | */ |
| 418 | #define EC_SPI_NOT_READY 0xfc |
| 419 | |
| 420 | /* |
| 421 | * EC was ready to receive a request from the AP. EC has treated the byte sent |
| 422 | * by the AP as part of a request packet, or (for old-style ECs) is processing |
| 423 | * a fully received packet but is not ready to respond yet. |
| 424 | */ |
| 425 | #define EC_SPI_OLD_READY 0xfd |
| 426 | |
| 427 | /*****************************************************************************/ |
| 428 | |
| 429 | /* |
| 430 | * Protocol version 2 for I2C and SPI send a request this way: |
| 431 | * |
| 432 | * 0 EC_CMD_VERSION0 + (command version) |
| 433 | * 1 Command number |
| 434 | * 2 Length of params = N |
| 435 | * 3..N+2 Params, if any |
| 436 | * N+3 8-bit checksum of bytes 0..N+2 |
| 437 | * |
| 438 | * The corresponding response is: |
| 439 | * |
| 440 | * 0 Result code (EC_RES_*) |
| 441 | * 1 Length of params = M |
| 442 | * 2..M+1 Params, if any |
| 443 | * M+2 8-bit checksum of bytes 0..M+1 |
| 444 | */ |
| 445 | #define EC_PROTO2_REQUEST_HEADER_BYTES 3 |
| 446 | #define EC_PROTO2_REQUEST_TRAILER_BYTES 1 |
| 447 | #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \ |
| 448 | EC_PROTO2_REQUEST_TRAILER_BYTES) |
| 449 | |
| 450 | #define EC_PROTO2_RESPONSE_HEADER_BYTES 2 |
| 451 | #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1 |
| 452 | #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \ |
| 453 | EC_PROTO2_RESPONSE_TRAILER_BYTES) |
| 454 | |
| 455 | /* Parameter length was limited by the LPC interface */ |
| 456 | #define EC_PROTO2_MAX_PARAM_SIZE 0xfc |
| 457 | |
| 458 | /* Maximum request and response packet sizes for protocol version 2 */ |
| 459 | #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \ |
| 460 | EC_PROTO2_MAX_PARAM_SIZE) |
| 461 | #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \ |
| 462 | EC_PROTO2_MAX_PARAM_SIZE) |
| 463 | |
| 464 | /*****************************************************************************/ |
| 465 | |
| 466 | /* |
| 467 | * Value written to legacy command port / prefix byte to indicate protocol |
| 468 | * 3+ structs are being used. Usage is bus-dependent. |
| 469 | */ |
| 470 | #define EC_COMMAND_PROTOCOL_3 0xda |
| 471 | |
| 472 | #define EC_HOST_REQUEST_VERSION 3 |
| 473 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 474 | /** |
| 475 | * struct ec_host_request - Version 3 request from host. |
| 476 | * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it |
| 477 | * receives a header with a version it doesn't know how to |
| 478 | * parse. |
| 479 | * @checksum: Checksum of request and data; sum of all bytes including checksum |
| 480 | * should total to 0. |
| 481 | * @command: Command to send (EC_CMD_...) |
| 482 | * @command_version: Command version. |
| 483 | * @reserved: Unused byte in current protocol version; set to 0. |
| 484 | * @data_len: Length of data which follows this header. |
| 485 | */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 486 | struct ec_host_request { |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 487 | uint8_t struct_version; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 488 | uint8_t checksum; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 489 | uint16_t command; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 490 | uint8_t command_version; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 491 | uint8_t reserved; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 492 | uint16_t data_len; |
| 493 | } __packed; |
| 494 | |
| 495 | #define EC_HOST_RESPONSE_VERSION 3 |
| 496 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 497 | /** |
| 498 | * struct ec_host_response - Version 3 response from EC. |
| 499 | * @struct_version: Struct version (=3). |
| 500 | * @checksum: Checksum of response and data; sum of all bytes including |
| 501 | * checksum should total to 0. |
| 502 | * @result: EC's response to the command (separate from communication failure) |
| 503 | * @data_len: Length of data which follows this header. |
| 504 | * @reserved: Unused bytes in current protocol version; set to 0. |
| 505 | */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 506 | struct ec_host_response { |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 507 | uint8_t struct_version; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 508 | uint8_t checksum; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 509 | uint16_t result; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 510 | uint16_t data_len; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 511 | uint16_t reserved; |
| 512 | } __packed; |
| 513 | |
| 514 | /*****************************************************************************/ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 515 | /* |
| 516 | * Notes on commands: |
| 517 | * |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 518 | * Each command is an 16-bit command value. Commands which take params or |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 519 | * return response data specify structs for that data. If no struct is |
| 520 | * specified, the command does not input or output data, respectively. |
| 521 | * Parameter/response length is implicit in the structs. Some underlying |
| 522 | * communication protocols (I2C, SPI) may add length or checksum headers, but |
| 523 | * those are implementation-dependent and not defined here. |
| 524 | */ |
| 525 | |
| 526 | /*****************************************************************************/ |
| 527 | /* General / test commands */ |
| 528 | |
| 529 | /* |
| 530 | * Get protocol version, used to deal with non-backward compatible protocol |
| 531 | * changes. |
| 532 | */ |
| 533 | #define EC_CMD_PROTO_VERSION 0x00 |
| 534 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 535 | /** |
| 536 | * struct ec_response_proto_version - Response to the proto version command. |
| 537 | * @version: The protocol version. |
| 538 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 539 | struct ec_response_proto_version { |
| 540 | uint32_t version; |
| 541 | } __packed; |
| 542 | |
| 543 | /* |
| 544 | * Hello. This is a simple command to test the EC is responsive to |
| 545 | * commands. |
| 546 | */ |
| 547 | #define EC_CMD_HELLO 0x01 |
| 548 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 549 | /** |
| 550 | * struct ec_params_hello - Parameters to the hello command. |
| 551 | * @in_data: Pass anything here. |
| 552 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 553 | struct ec_params_hello { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 554 | uint32_t in_data; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 555 | } __packed; |
| 556 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 557 | /** |
| 558 | * struct ec_response_hello - Response to the hello command. |
| 559 | * @out_data: Output will be in_data + 0x01020304. |
| 560 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 561 | struct ec_response_hello { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 562 | uint32_t out_data; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 563 | } __packed; |
| 564 | |
| 565 | /* Get version number */ |
| 566 | #define EC_CMD_GET_VERSION 0x02 |
| 567 | |
| 568 | enum ec_current_image { |
| 569 | EC_IMAGE_UNKNOWN = 0, |
| 570 | EC_IMAGE_RO, |
| 571 | EC_IMAGE_RW |
| 572 | }; |
| 573 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 574 | /** |
| 575 | * struct ec_response_get_version - Response to the get version command. |
| 576 | * @version_string_ro: Null-terminated RO firmware version string. |
| 577 | * @version_string_rw: Null-terminated RW firmware version string. |
| 578 | * @reserved: Unused bytes; was previously RW-B firmware version string. |
| 579 | * @current_image: One of ec_current_image. |
| 580 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 581 | struct ec_response_get_version { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 582 | char version_string_ro[32]; |
| 583 | char version_string_rw[32]; |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 584 | char reserved[32]; |
| 585 | uint32_t current_image; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 586 | } __packed; |
| 587 | |
| 588 | /* Read test */ |
| 589 | #define EC_CMD_READ_TEST 0x03 |
| 590 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 591 | /** |
| 592 | * struct ec_params_read_test - Parameters for the read test command. |
| 593 | * @offset: Starting value for read buffer. |
| 594 | * @size: Size to read in bytes. |
| 595 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 596 | struct ec_params_read_test { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 597 | uint32_t offset; |
| 598 | uint32_t size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 599 | } __packed; |
| 600 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 601 | /** |
| 602 | * struct ec_response_read_test - Response to the read test command. |
| 603 | * @data: Data returned by the read test command. |
| 604 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 605 | struct ec_response_read_test { |
| 606 | uint32_t data[32]; |
| 607 | } __packed; |
| 608 | |
| 609 | /* |
| 610 | * Get build information |
| 611 | * |
| 612 | * Response is null-terminated string. |
| 613 | */ |
| 614 | #define EC_CMD_GET_BUILD_INFO 0x04 |
| 615 | |
| 616 | /* Get chip info */ |
| 617 | #define EC_CMD_GET_CHIP_INFO 0x05 |
| 618 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 619 | /** |
| 620 | * struct ec_response_get_chip_info - Response to the get chip info command. |
| 621 | * @vendor: Null-terminated string for chip vendor. |
| 622 | * @name: Null-terminated string for chip name. |
| 623 | * @revision: Null-terminated string for chip mask version. |
| 624 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 625 | struct ec_response_get_chip_info { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 626 | char vendor[32]; |
| 627 | char name[32]; |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 628 | char revision[32]; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 629 | } __packed; |
| 630 | |
| 631 | /* Get board HW version */ |
| 632 | #define EC_CMD_GET_BOARD_VERSION 0x06 |
| 633 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 634 | /** |
| 635 | * struct ec_response_board_version - Response to the board version command. |
| 636 | * @board_version: A monotonously incrementing number. |
| 637 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 638 | struct ec_response_board_version { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 639 | uint16_t board_version; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 640 | } __packed; |
| 641 | |
| 642 | /* |
| 643 | * Read memory-mapped data. |
| 644 | * |
| 645 | * This is an alternate interface to memory-mapped data for bus protocols |
| 646 | * which don't support direct-mapped memory - I2C, SPI, etc. |
| 647 | * |
| 648 | * Response is params.size bytes of data. |
| 649 | */ |
| 650 | #define EC_CMD_READ_MEMMAP 0x07 |
| 651 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 652 | /** |
| 653 | * struct ec_params_read_memmap - Parameters for the read memory map command. |
| 654 | * @offset: Offset in memmap (EC_MEMMAP_*). |
| 655 | * @size: Size to read in bytes. |
| 656 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 657 | struct ec_params_read_memmap { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 658 | uint8_t offset; |
| 659 | uint8_t size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 660 | } __packed; |
| 661 | |
| 662 | /* Read versions supported for a command */ |
| 663 | #define EC_CMD_GET_CMD_VERSIONS 0x08 |
| 664 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 665 | /** |
| 666 | * struct ec_params_get_cmd_versions - Parameters for the get command versions. |
| 667 | * @cmd: Command to check. |
| 668 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 669 | struct ec_params_get_cmd_versions { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 670 | uint8_t cmd; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 671 | } __packed; |
| 672 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 673 | /** |
| 674 | * struct ec_params_get_cmd_versions_v1 - Parameters for the get command |
| 675 | * versions (v1) |
| 676 | * @cmd: Command to check. |
| 677 | */ |
Nicolas Boichat | 0aa877c | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 678 | struct ec_params_get_cmd_versions_v1 { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 679 | uint16_t cmd; |
Nicolas Boichat | 0aa877c | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 680 | } __packed; |
| 681 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 682 | /** |
| 683 | * struct ec_response_get_cmd_version - Response to the get command versions. |
| 684 | * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with |
| 685 | * a desired version. |
| 686 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 687 | struct ec_response_get_cmd_versions { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 688 | uint32_t version_mask; |
| 689 | } __packed; |
| 690 | |
| 691 | /* |
| 692 | * Check EC communcations status (busy). This is needed on i2c/spi but not |
| 693 | * on lpc since it has its own out-of-band busy indicator. |
| 694 | * |
| 695 | * lpc must read the status from the command register. Attempting this on |
| 696 | * lpc will overwrite the args/parameter space and corrupt its data. |
| 697 | */ |
| 698 | #define EC_CMD_GET_COMMS_STATUS 0x09 |
| 699 | |
| 700 | /* Avoid using ec_status which is for return values */ |
| 701 | enum ec_comms_status { |
| 702 | EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */ |
| 703 | }; |
| 704 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 705 | /** |
| 706 | * struct ec_response_get_comms_status - Response to the get comms status |
| 707 | * command. |
| 708 | * @flags: Mask of enum ec_comms_status. |
| 709 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 710 | struct ec_response_get_comms_status { |
| 711 | uint32_t flags; /* Mask of enum ec_comms_status */ |
| 712 | } __packed; |
| 713 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 714 | /* Fake a variety of responses, purely for testing purposes. */ |
| 715 | #define EC_CMD_TEST_PROTOCOL 0x0a |
| 716 | |
| 717 | /* Tell the EC what to send back to us. */ |
| 718 | struct ec_params_test_protocol { |
| 719 | uint32_t ec_result; |
| 720 | uint32_t ret_len; |
| 721 | uint8_t buf[32]; |
| 722 | } __packed; |
| 723 | |
| 724 | /* Here it comes... */ |
| 725 | struct ec_response_test_protocol { |
| 726 | uint8_t buf[32]; |
| 727 | } __packed; |
| 728 | |
| 729 | /* Get prococol information */ |
| 730 | #define EC_CMD_GET_PROTOCOL_INFO 0x0b |
| 731 | |
| 732 | /* Flags for ec_response_get_protocol_info.flags */ |
| 733 | /* EC_RES_IN_PROGRESS may be returned if a command is slow */ |
| 734 | #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0) |
| 735 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 736 | /** |
| 737 | * struct ec_response_get_protocol_info - Response to the get protocol info. |
| 738 | * @protocol_versions: Bitmask of protocol versions supported (1 << n means |
| 739 | * version n). |
| 740 | * @max_request_packet_size: Maximum request packet size in bytes. |
| 741 | * @max_response_packet_size: Maximum response packet size in bytes. |
| 742 | * @flags: see EC_PROTOCOL_INFO_* |
| 743 | */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 744 | struct ec_response_get_protocol_info { |
| 745 | /* Fields which exist if at least protocol version 3 supported */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 746 | uint32_t protocol_versions; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 747 | uint16_t max_request_packet_size; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 748 | uint16_t max_response_packet_size; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 749 | uint32_t flags; |
| 750 | } __packed; |
| 751 | |
| 752 | |
| 753 | /*****************************************************************************/ |
| 754 | /* Get/Set miscellaneous values */ |
| 755 | |
| 756 | /* The upper byte of .flags tells what to do (nothing means "get") */ |
| 757 | #define EC_GSV_SET 0x80000000 |
| 758 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 759 | /* |
| 760 | * The lower three bytes of .flags identifies the parameter, if that has |
| 761 | * meaning for an individual command. |
| 762 | */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 763 | #define EC_GSV_PARAM_MASK 0x00ffffff |
| 764 | |
| 765 | struct ec_params_get_set_value { |
| 766 | uint32_t flags; |
| 767 | uint32_t value; |
| 768 | } __packed; |
| 769 | |
| 770 | struct ec_response_get_set_value { |
| 771 | uint32_t flags; |
| 772 | uint32_t value; |
| 773 | } __packed; |
| 774 | |
| 775 | /* More than one command can use these structs to get/set paramters. */ |
| 776 | #define EC_CMD_GSV_PAUSE_IN_S5 0x0c |
| 777 | |
Vincent Palatin | e4244eb | 2016-08-01 11:54:37 +0200 | [diff] [blame] | 778 | /*****************************************************************************/ |
| 779 | /* List the features supported by the firmware */ |
| 780 | #define EC_CMD_GET_FEATURES 0x0d |
| 781 | |
| 782 | /* Supported features */ |
| 783 | enum ec_feature_code { |
| 784 | /* |
| 785 | * This image contains a limited set of features. Another image |
| 786 | * in RW partition may support more features. |
| 787 | */ |
| 788 | EC_FEATURE_LIMITED = 0, |
| 789 | /* |
| 790 | * Commands for probing/reading/writing/erasing the flash in the |
| 791 | * EC are present. |
| 792 | */ |
| 793 | EC_FEATURE_FLASH = 1, |
| 794 | /* |
| 795 | * Can control the fan speed directly. |
| 796 | */ |
| 797 | EC_FEATURE_PWM_FAN = 2, |
| 798 | /* |
| 799 | * Can control the intensity of the keyboard backlight. |
| 800 | */ |
| 801 | EC_FEATURE_PWM_KEYB = 3, |
| 802 | /* |
| 803 | * Support Google lightbar, introduced on Pixel. |
| 804 | */ |
| 805 | EC_FEATURE_LIGHTBAR = 4, |
| 806 | /* Control of LEDs */ |
| 807 | EC_FEATURE_LED = 5, |
| 808 | /* Exposes an interface to control gyro and sensors. |
| 809 | * The host goes through the EC to access these sensors. |
| 810 | * In addition, the EC may provide composite sensors, like lid angle. |
| 811 | */ |
| 812 | EC_FEATURE_MOTION_SENSE = 6, |
| 813 | /* The keyboard is controlled by the EC */ |
| 814 | EC_FEATURE_KEYB = 7, |
| 815 | /* The AP can use part of the EC flash as persistent storage. */ |
| 816 | EC_FEATURE_PSTORE = 8, |
| 817 | /* The EC monitors BIOS port 80h, and can return POST codes. */ |
| 818 | EC_FEATURE_PORT80 = 9, |
| 819 | /* |
| 820 | * Thermal management: include TMP specific commands. |
| 821 | * Higher level than direct fan control. |
| 822 | */ |
| 823 | EC_FEATURE_THERMAL = 10, |
| 824 | /* Can switch the screen backlight on/off */ |
| 825 | EC_FEATURE_BKLIGHT_SWITCH = 11, |
| 826 | /* Can switch the wifi module on/off */ |
| 827 | EC_FEATURE_WIFI_SWITCH = 12, |
| 828 | /* Monitor host events, through for example SMI or SCI */ |
| 829 | EC_FEATURE_HOST_EVENTS = 13, |
| 830 | /* The EC exposes GPIO commands to control/monitor connected devices. */ |
| 831 | EC_FEATURE_GPIO = 14, |
| 832 | /* The EC can send i2c messages to downstream devices. */ |
| 833 | EC_FEATURE_I2C = 15, |
| 834 | /* Command to control charger are included */ |
| 835 | EC_FEATURE_CHARGER = 16, |
| 836 | /* Simple battery support. */ |
| 837 | EC_FEATURE_BATTERY = 17, |
| 838 | /* |
| 839 | * Support Smart battery protocol |
| 840 | * (Common Smart Battery System Interface Specification) |
| 841 | */ |
| 842 | EC_FEATURE_SMART_BATTERY = 18, |
| 843 | /* EC can dectect when the host hangs. */ |
| 844 | EC_FEATURE_HANG_DETECT = 19, |
| 845 | /* Report power information, for pit only */ |
| 846 | EC_FEATURE_PMU = 20, |
| 847 | /* Another Cros EC device is present downstream of this one */ |
| 848 | EC_FEATURE_SUB_MCU = 21, |
| 849 | /* Support USB Power delivery (PD) commands */ |
| 850 | EC_FEATURE_USB_PD = 22, |
| 851 | /* Control USB multiplexer, for audio through USB port for instance. */ |
| 852 | EC_FEATURE_USB_MUX = 23, |
| 853 | /* Motion Sensor code has an internal software FIFO */ |
| 854 | EC_FEATURE_MOTION_SENSE_FIFO = 24, |
Stephen Barber | 3eff6d2 | 2017-11-10 22:55:52 +0100 | [diff] [blame] | 855 | /* EC has RTC feature that can be controlled by host commands */ |
| 856 | EC_FEATURE_RTC = 27, |
Neil Armstrong | f47674e | 2018-07-04 17:08:19 +0200 | [diff] [blame] | 857 | /* EC supports CEC commands */ |
| 858 | EC_FEATURE_CEC = 35, |
Rushikesh S Kadam | d4cee95 | 2019-03-01 13:50:54 +0530 | [diff] [blame] | 859 | /* The MCU is an Integrated Sensor Hub */ |
| 860 | EC_FEATURE_ISH = 40, |
Vincent Palatin | e4244eb | 2016-08-01 11:54:37 +0200 | [diff] [blame] | 861 | }; |
| 862 | |
| 863 | #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) |
| 864 | #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 865 | |
Vincent Palatin | e4244eb | 2016-08-01 11:54:37 +0200 | [diff] [blame] | 866 | struct ec_response_get_features { |
| 867 | uint32_t flags[2]; |
| 868 | } __packed; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 869 | |
| 870 | /*****************************************************************************/ |
| 871 | /* Flash commands */ |
| 872 | |
| 873 | /* Get flash info */ |
| 874 | #define EC_CMD_FLASH_INFO 0x10 |
| 875 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 876 | /** |
| 877 | * struct ec_response_flash_info - Response to the flash info command. |
| 878 | * @flash_size: Usable flash size in bytes. |
| 879 | * @write_block_size: Write block size. Write offset and size must be a |
| 880 | * multiple of this. |
| 881 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 882 | * multiple of this. |
| 883 | * @protect_block_size: Protection block size. Protection offset and size |
| 884 | * must be a multiple of this. |
| 885 | * |
| 886 | * Version 0 returns these fields. |
| 887 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 888 | struct ec_response_flash_info { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 889 | uint32_t flash_size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 890 | uint32_t write_block_size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 891 | uint32_t erase_block_size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 892 | uint32_t protect_block_size; |
| 893 | } __packed; |
| 894 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 895 | /* Flags for version 1+ flash info command */ |
| 896 | /* EC flash erases bits to 0 instead of 1 */ |
| 897 | #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0) |
| 898 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 899 | /** |
| 900 | * struct ec_response_flash_info_1 - Response to the flash info v1 command. |
| 901 | * @flash_size: Usable flash size in bytes. |
| 902 | * @write_block_size: Write block size. Write offset and size must be a |
| 903 | * multiple of this. |
| 904 | * @erase_block_size: Erase block size. Erase offset and size must be a |
| 905 | * multiple of this. |
| 906 | * @protect_block_size: Protection block size. Protection offset and size |
| 907 | * must be a multiple of this. |
| 908 | * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if |
| 909 | * size is exactly this and offset is a multiple of this. |
| 910 | * For example, an EC may have a write buffer which can do |
| 911 | * half-page operations if data is aligned, and a slower |
| 912 | * word-at-a-time write mode. |
| 913 | * @flags: Flags; see EC_FLASH_INFO_* |
| 914 | * |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 915 | * Version 1 returns the same initial fields as version 0, with additional |
| 916 | * fields following. |
| 917 | * |
| 918 | * gcc anonymous structs don't seem to get along with the __packed directive; |
| 919 | * if they did we'd define the version 0 struct as a sub-struct of this one. |
| 920 | */ |
| 921 | struct ec_response_flash_info_1 { |
| 922 | /* Version 0 fields; see above for description */ |
| 923 | uint32_t flash_size; |
| 924 | uint32_t write_block_size; |
| 925 | uint32_t erase_block_size; |
| 926 | uint32_t protect_block_size; |
| 927 | |
| 928 | /* Version 1 adds these fields: */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 929 | uint32_t write_ideal_size; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 930 | uint32_t flags; |
| 931 | } __packed; |
| 932 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 933 | /* |
| 934 | * Read flash |
| 935 | * |
| 936 | * Response is params.size bytes of data. |
| 937 | */ |
| 938 | #define EC_CMD_FLASH_READ 0x11 |
| 939 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 940 | /** |
| 941 | * struct ec_params_flash_read - Parameters for the flash read command. |
| 942 | * @offset: Byte offset to read. |
| 943 | * @size: Size to read in bytes. |
| 944 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 945 | struct ec_params_flash_read { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 946 | uint32_t offset; |
| 947 | uint32_t size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 948 | } __packed; |
| 949 | |
| 950 | /* Write flash */ |
| 951 | #define EC_CMD_FLASH_WRITE 0x12 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 952 | #define EC_VER_FLASH_WRITE 1 |
| 953 | |
| 954 | /* Version 0 of the flash command supported only 64 bytes of data */ |
| 955 | #define EC_FLASH_WRITE_VER0_SIZE 64 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 956 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 957 | /** |
| 958 | * struct ec_params_flash_write - Parameters for the flash write command. |
| 959 | * @offset: Byte offset to write. |
| 960 | * @size: Size to write in bytes. |
| 961 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 962 | struct ec_params_flash_write { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 963 | uint32_t offset; |
| 964 | uint32_t size; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 965 | /* Followed by data to write */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 966 | } __packed; |
| 967 | |
| 968 | /* Erase flash */ |
| 969 | #define EC_CMD_FLASH_ERASE 0x13 |
| 970 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 971 | /** |
| 972 | * struct ec_params_flash_erase - Parameters for the flash erase command. |
| 973 | * @offset: Byte offset to erase. |
| 974 | * @size: Size to erase in bytes. |
| 975 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 976 | struct ec_params_flash_erase { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 977 | uint32_t offset; |
| 978 | uint32_t size; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 979 | } __packed; |
| 980 | |
| 981 | /* |
| 982 | * Get/set flash protection. |
| 983 | * |
| 984 | * If mask!=0, sets/clear the requested bits of flags. Depending on the |
| 985 | * firmware write protect GPIO, not all flags will take effect immediately; |
| 986 | * some flags require a subsequent hard reset to take effect. Check the |
| 987 | * returned flags bits to see what actually happened. |
| 988 | * |
| 989 | * If mask=0, simply returns the current flags state. |
| 990 | */ |
| 991 | #define EC_CMD_FLASH_PROTECT 0x15 |
| 992 | #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ |
| 993 | |
| 994 | /* Flags for flash protection */ |
| 995 | /* RO flash code protected when the EC boots */ |
| 996 | #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0) |
| 997 | /* |
| 998 | * RO flash code protected now. If this bit is set, at-boot status cannot |
| 999 | * be changed. |
| 1000 | */ |
| 1001 | #define EC_FLASH_PROTECT_RO_NOW (1 << 1) |
| 1002 | /* Entire flash code protected now, until reboot. */ |
| 1003 | #define EC_FLASH_PROTECT_ALL_NOW (1 << 2) |
| 1004 | /* Flash write protect GPIO is asserted now */ |
| 1005 | #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3) |
| 1006 | /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ |
| 1007 | #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4) |
| 1008 | /* |
| 1009 | * Error - flash protection is in inconsistent state. At least one bank of |
| 1010 | * flash which should be protected is not protected. Usually fixed by |
| 1011 | * re-requesting the desired flags, or by a hard reset if that fails. |
| 1012 | */ |
| 1013 | #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5) |
| 1014 | /* Entile flash code protected when the EC boots */ |
| 1015 | #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6) |
| 1016 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 1017 | /** |
| 1018 | * struct ec_params_flash_protect - Parameters for the flash protect command. |
| 1019 | * @mask: Bits in flags to apply. |
| 1020 | * @flags: New flags to apply. |
| 1021 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1022 | struct ec_params_flash_protect { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 1023 | uint32_t mask; |
| 1024 | uint32_t flags; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1025 | } __packed; |
| 1026 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 1027 | /** |
| 1028 | * struct ec_response_flash_protect - Response to the flash protect command. |
| 1029 | * @flags: Current value of flash protect flags. |
| 1030 | * @valid_flags: Flags which are valid on this platform. This allows the |
| 1031 | * caller to distinguish between flags which aren't set vs. flags |
| 1032 | * which can't be set on this platform. |
| 1033 | * @writable_flags: Flags which can be changed given the current protection |
| 1034 | * state. |
| 1035 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1036 | struct ec_response_flash_protect { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1037 | uint32_t flags; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1038 | uint32_t valid_flags; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1039 | uint32_t writable_flags; |
| 1040 | } __packed; |
| 1041 | |
| 1042 | /* |
| 1043 | * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash |
| 1044 | * write protect. These commands may be reused with version > 0. |
| 1045 | */ |
| 1046 | |
| 1047 | /* Get the region offset/size */ |
| 1048 | #define EC_CMD_FLASH_REGION_INFO 0x16 |
| 1049 | #define EC_VER_FLASH_REGION_INFO 1 |
| 1050 | |
| 1051 | enum ec_flash_region { |
| 1052 | /* Region which holds read-only EC image */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1053 | EC_FLASH_REGION_RO = 0, |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1054 | /* Region which holds rewritable EC image */ |
| 1055 | EC_FLASH_REGION_RW, |
| 1056 | /* |
| 1057 | * Region which should be write-protected in the factory (a superset of |
| 1058 | * EC_FLASH_REGION_RO) |
| 1059 | */ |
| 1060 | EC_FLASH_REGION_WP_RO, |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1061 | /* Number of regions */ |
| 1062 | EC_FLASH_REGION_COUNT, |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1063 | }; |
| 1064 | |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 1065 | /** |
| 1066 | * struct ec_params_flash_region_info - Parameters for the flash region info |
| 1067 | * command. |
| 1068 | * @region: Flash region; see EC_FLASH_REGION_* |
| 1069 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1070 | struct ec_params_flash_region_info { |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 1071 | uint32_t region; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1072 | } __packed; |
| 1073 | |
| 1074 | struct ec_response_flash_region_info { |
| 1075 | uint32_t offset; |
| 1076 | uint32_t size; |
| 1077 | } __packed; |
| 1078 | |
| 1079 | /* Read/write VbNvContext */ |
| 1080 | #define EC_CMD_VBNV_CONTEXT 0x17 |
| 1081 | #define EC_VER_VBNV_CONTEXT 1 |
| 1082 | #define EC_VBNV_BLOCK_SIZE 16 |
| 1083 | |
| 1084 | enum ec_vbnvcontext_op { |
| 1085 | EC_VBNV_CONTEXT_OP_READ, |
| 1086 | EC_VBNV_CONTEXT_OP_WRITE, |
| 1087 | }; |
| 1088 | |
| 1089 | struct ec_params_vbnvcontext { |
| 1090 | uint32_t op; |
| 1091 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
| 1092 | } __packed; |
| 1093 | |
| 1094 | struct ec_response_vbnvcontext { |
| 1095 | uint8_t block[EC_VBNV_BLOCK_SIZE]; |
| 1096 | } __packed; |
| 1097 | |
| 1098 | /*****************************************************************************/ |
| 1099 | /* PWM commands */ |
| 1100 | |
| 1101 | /* Get fan target RPM */ |
| 1102 | #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20 |
| 1103 | |
| 1104 | struct ec_response_pwm_get_fan_rpm { |
| 1105 | uint32_t rpm; |
| 1106 | } __packed; |
| 1107 | |
| 1108 | /* Set target fan RPM */ |
| 1109 | #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21 |
| 1110 | |
| 1111 | struct ec_params_pwm_set_fan_target_rpm { |
| 1112 | uint32_t rpm; |
| 1113 | } __packed; |
| 1114 | |
| 1115 | /* Get keyboard backlight */ |
| 1116 | #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22 |
| 1117 | |
| 1118 | struct ec_response_pwm_get_keyboard_backlight { |
| 1119 | uint8_t percent; |
| 1120 | uint8_t enabled; |
| 1121 | } __packed; |
| 1122 | |
| 1123 | /* Set keyboard backlight */ |
| 1124 | #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23 |
| 1125 | |
| 1126 | struct ec_params_pwm_set_keyboard_backlight { |
| 1127 | uint8_t percent; |
| 1128 | } __packed; |
| 1129 | |
| 1130 | /* Set target fan PWM duty cycle */ |
| 1131 | #define EC_CMD_PWM_SET_FAN_DUTY 0x24 |
| 1132 | |
| 1133 | struct ec_params_pwm_set_fan_duty { |
| 1134 | uint32_t percent; |
| 1135 | } __packed; |
| 1136 | |
Brian Norris | 2b66bd6 | 2016-07-15 16:28:42 -0700 | [diff] [blame] | 1137 | #define EC_CMD_PWM_SET_DUTY 0x25 |
| 1138 | /* 16 bit duty cycle, 0xffff = 100% */ |
| 1139 | #define EC_PWM_MAX_DUTY 0xffff |
| 1140 | |
| 1141 | enum ec_pwm_type { |
| 1142 | /* All types, indexed by board-specific enum pwm_channel */ |
| 1143 | EC_PWM_TYPE_GENERIC = 0, |
| 1144 | /* Keyboard backlight */ |
| 1145 | EC_PWM_TYPE_KB_LIGHT, |
| 1146 | /* Display backlight */ |
| 1147 | EC_PWM_TYPE_DISPLAY_LIGHT, |
| 1148 | EC_PWM_TYPE_COUNT, |
| 1149 | }; |
| 1150 | |
| 1151 | struct ec_params_pwm_set_duty { |
| 1152 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1153 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1154 | uint8_t index; /* Type-specific index, or 0 if unique */ |
| 1155 | } __packed; |
| 1156 | |
| 1157 | #define EC_CMD_PWM_GET_DUTY 0x26 |
| 1158 | |
| 1159 | struct ec_params_pwm_get_duty { |
| 1160 | uint8_t pwm_type; /* ec_pwm_type */ |
| 1161 | uint8_t index; /* Type-specific index, or 0 if unique */ |
| 1162 | } __packed; |
| 1163 | |
| 1164 | struct ec_response_pwm_get_duty { |
| 1165 | uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ |
| 1166 | } __packed; |
| 1167 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1168 | /*****************************************************************************/ |
| 1169 | /* |
| 1170 | * Lightbar commands. This looks worse than it is. Since we only use one HOST |
| 1171 | * command to say "talk to the lightbar", we put the "and tell it to do X" part |
| 1172 | * into a subcommand. We'll make separate structs for subcommands with |
| 1173 | * different input args, so that we know how much to expect. |
| 1174 | */ |
| 1175 | #define EC_CMD_LIGHTBAR_CMD 0x28 |
| 1176 | |
| 1177 | struct rgb_s { |
| 1178 | uint8_t r, g, b; |
| 1179 | }; |
| 1180 | |
| 1181 | #define LB_BATTERY_LEVELS 4 |
Enric Balletbo i Serra | e2bbf91 | 2018-07-18 18:09:56 +0200 | [diff] [blame] | 1182 | |
| 1183 | /* |
| 1184 | * List of tweakable parameters. NOTE: It's __packed so it can be sent in a |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1185 | * host command, but the alignment is the same regardless. Keep it that way. |
| 1186 | */ |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1187 | struct lightbar_params_v0 { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1188 | /* Timing */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1189 | int32_t google_ramp_up; |
| 1190 | int32_t google_ramp_down; |
| 1191 | int32_t s3s0_ramp_up; |
| 1192 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1193 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1194 | int32_t s0s3_ramp_down; |
| 1195 | int32_t s3_sleep_for; |
| 1196 | int32_t s3_ramp_up; |
| 1197 | int32_t s3_ramp_down; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1198 | |
| 1199 | /* Oscillation */ |
| 1200 | uint8_t new_s0; |
| 1201 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1202 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1203 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1204 | |
| 1205 | /* Brightness limits based on the backlight and AC. */ |
| 1206 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1207 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1208 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1209 | |
| 1210 | /* Battery level thresholds */ |
| 1211 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1212 | |
| 1213 | /* Map [AC][battery_level] to color index */ |
| 1214 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1215 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1216 | |
| 1217 | /* Color palette */ |
| 1218 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
| 1219 | } __packed; |
| 1220 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1221 | struct lightbar_params_v1 { |
| 1222 | /* Timing */ |
| 1223 | int32_t google_ramp_up; |
| 1224 | int32_t google_ramp_down; |
| 1225 | int32_t s3s0_ramp_up; |
| 1226 | int32_t s0_tick_delay[2]; /* AC=0/1 */ |
| 1227 | int32_t s0a_tick_delay[2]; /* AC=0/1 */ |
| 1228 | int32_t s0s3_ramp_down; |
| 1229 | int32_t s3_sleep_for; |
| 1230 | int32_t s3_ramp_up; |
| 1231 | int32_t s3_ramp_down; |
| 1232 | int32_t tap_tick_delay; |
| 1233 | int32_t tap_display_time; |
| 1234 | |
| 1235 | /* Tap-for-battery params */ |
| 1236 | uint8_t tap_pct_red; |
| 1237 | uint8_t tap_pct_green; |
| 1238 | uint8_t tap_seg_min_on; |
| 1239 | uint8_t tap_seg_max_on; |
| 1240 | uint8_t tap_seg_osc; |
| 1241 | uint8_t tap_idx[3]; |
| 1242 | |
| 1243 | /* Oscillation */ |
| 1244 | uint8_t osc_min[2]; /* AC=0/1 */ |
| 1245 | uint8_t osc_max[2]; /* AC=0/1 */ |
| 1246 | uint8_t w_ofs[2]; /* AC=0/1 */ |
| 1247 | |
| 1248 | /* Brightness limits based on the backlight and AC. */ |
| 1249 | uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */ |
| 1250 | uint8_t bright_bl_on_min[2]; /* AC=0/1 */ |
| 1251 | uint8_t bright_bl_on_max[2]; /* AC=0/1 */ |
| 1252 | |
| 1253 | /* Battery level thresholds */ |
| 1254 | uint8_t battery_threshold[LB_BATTERY_LEVELS - 1]; |
| 1255 | |
| 1256 | /* Map [AC][battery_level] to color index */ |
| 1257 | uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ |
| 1258 | uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ |
| 1259 | |
| 1260 | /* Color palette */ |
| 1261 | struct rgb_s color[8]; /* 0-3 are Google colors */ |
| 1262 | } __packed; |
| 1263 | |
Eric Caruso | be3ebeb | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1264 | /* Lightbar program */ |
| 1265 | #define EC_LB_PROG_LEN 192 |
| 1266 | struct lightbar_program { |
| 1267 | uint8_t size; |
| 1268 | uint8_t data[EC_LB_PROG_LEN]; |
| 1269 | }; |
| 1270 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1271 | struct ec_params_lightbar { |
| 1272 | uint8_t cmd; /* Command (see enum lightbar_command) */ |
| 1273 | union { |
| 1274 | struct { |
| 1275 | /* no args */ |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1276 | } dump, off, on, init, get_seq, get_params_v0, get_params_v1, |
Eric Caruso | 405c843 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1277 | version, get_brightness, get_demo, suspend, resume; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1278 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1279 | struct { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1280 | uint8_t num; |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1281 | } set_brightness, seq, demo; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1282 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1283 | struct { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1284 | uint8_t ctrl, reg, value; |
| 1285 | } reg; |
| 1286 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1287 | struct { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1288 | uint8_t led, red, green, blue; |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1289 | } set_rgb; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1290 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1291 | struct { |
| 1292 | uint8_t led; |
| 1293 | } get_rgb; |
| 1294 | |
Eric Caruso | 405c843 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1295 | struct { |
| 1296 | uint8_t enable; |
| 1297 | } manual_suspend_ctrl; |
| 1298 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1299 | struct lightbar_params_v0 set_params_v0; |
| 1300 | struct lightbar_params_v1 set_params_v1; |
Eric Caruso | be3ebeb | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1301 | struct lightbar_program set_program; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1302 | }; |
| 1303 | } __packed; |
| 1304 | |
| 1305 | struct ec_response_lightbar { |
| 1306 | union { |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1307 | struct { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1308 | struct { |
| 1309 | uint8_t reg; |
| 1310 | uint8_t ic0; |
| 1311 | uint8_t ic1; |
| 1312 | } vals[23]; |
| 1313 | } dump; |
| 1314 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1315 | struct { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1316 | uint8_t num; |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1317 | } get_seq, get_brightness, get_demo; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1318 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1319 | struct lightbar_params_v0 get_params_v0; |
| 1320 | struct lightbar_params_v1 get_params_v1; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1321 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1322 | struct { |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1323 | uint32_t num; |
| 1324 | uint32_t flags; |
| 1325 | } version; |
| 1326 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1327 | struct { |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1328 | uint8_t red, green, blue; |
| 1329 | } get_rgb; |
| 1330 | |
| 1331 | struct { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1332 | /* no return params */ |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1333 | } off, on, init, set_brightness, seq, reg, set_rgb, |
Eric Caruso | be3ebeb | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1334 | demo, set_params_v0, set_params_v1, |
Eric Caruso | 405c843 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1335 | set_program, manual_suspend_ctrl, suspend, resume; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1336 | }; |
| 1337 | } __packed; |
| 1338 | |
| 1339 | /* Lightbar commands */ |
| 1340 | enum lightbar_command { |
| 1341 | LIGHTBAR_CMD_DUMP = 0, |
| 1342 | LIGHTBAR_CMD_OFF = 1, |
| 1343 | LIGHTBAR_CMD_ON = 2, |
| 1344 | LIGHTBAR_CMD_INIT = 3, |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1345 | LIGHTBAR_CMD_SET_BRIGHTNESS = 4, |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1346 | LIGHTBAR_CMD_SEQ = 5, |
| 1347 | LIGHTBAR_CMD_REG = 6, |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1348 | LIGHTBAR_CMD_SET_RGB = 7, |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1349 | LIGHTBAR_CMD_GET_SEQ = 8, |
| 1350 | LIGHTBAR_CMD_DEMO = 9, |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1351 | LIGHTBAR_CMD_GET_PARAMS_V0 = 10, |
| 1352 | LIGHTBAR_CMD_SET_PARAMS_V0 = 11, |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1353 | LIGHTBAR_CMD_VERSION = 12, |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1354 | LIGHTBAR_CMD_GET_BRIGHTNESS = 13, |
| 1355 | LIGHTBAR_CMD_GET_RGB = 14, |
| 1356 | LIGHTBAR_CMD_GET_DEMO = 15, |
| 1357 | LIGHTBAR_CMD_GET_PARAMS_V1 = 16, |
| 1358 | LIGHTBAR_CMD_SET_PARAMS_V1 = 17, |
Eric Caruso | be3ebeb | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1359 | LIGHTBAR_CMD_SET_PROGRAM = 18, |
Eric Caruso | 405c843 | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 1360 | LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, |
| 1361 | LIGHTBAR_CMD_SUSPEND = 20, |
| 1362 | LIGHTBAR_CMD_RESUME = 21, |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1363 | LIGHTBAR_NUM_CMDS |
| 1364 | }; |
| 1365 | |
| 1366 | /*****************************************************************************/ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1367 | /* LED control commands */ |
| 1368 | |
| 1369 | #define EC_CMD_LED_CONTROL 0x29 |
| 1370 | |
| 1371 | enum ec_led_id { |
| 1372 | /* LED to indicate battery state of charge */ |
| 1373 | EC_LED_ID_BATTERY_LED = 0, |
| 1374 | /* |
| 1375 | * LED to indicate system power state (on or in suspend). |
| 1376 | * May be on power button or on C-panel. |
| 1377 | */ |
| 1378 | EC_LED_ID_POWER_LED, |
| 1379 | /* LED on power adapter or its plug */ |
| 1380 | EC_LED_ID_ADAPTER_LED, |
| 1381 | |
| 1382 | EC_LED_ID_COUNT |
| 1383 | }; |
| 1384 | |
| 1385 | /* LED control flags */ |
| 1386 | #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */ |
| 1387 | #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */ |
| 1388 | |
| 1389 | enum ec_led_colors { |
| 1390 | EC_LED_COLOR_RED = 0, |
| 1391 | EC_LED_COLOR_GREEN, |
| 1392 | EC_LED_COLOR_BLUE, |
| 1393 | EC_LED_COLOR_YELLOW, |
| 1394 | EC_LED_COLOR_WHITE, |
| 1395 | |
| 1396 | EC_LED_COLOR_COUNT |
| 1397 | }; |
| 1398 | |
| 1399 | struct ec_params_led_control { |
| 1400 | uint8_t led_id; /* Which LED to control */ |
| 1401 | uint8_t flags; /* Control flags */ |
| 1402 | |
| 1403 | uint8_t brightness[EC_LED_COLOR_COUNT]; |
| 1404 | } __packed; |
| 1405 | |
| 1406 | struct ec_response_led_control { |
| 1407 | /* |
| 1408 | * Available brightness value range. |
| 1409 | * |
| 1410 | * Range 0 means color channel not present. |
| 1411 | * Range 1 means on/off control. |
| 1412 | * Other values means the LED is control by PWM. |
| 1413 | */ |
| 1414 | uint8_t brightness_range[EC_LED_COLOR_COUNT]; |
| 1415 | } __packed; |
| 1416 | |
| 1417 | /*****************************************************************************/ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1418 | /* Verified boot commands */ |
| 1419 | |
| 1420 | /* |
| 1421 | * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be |
| 1422 | * reused for other purposes with version > 0. |
| 1423 | */ |
| 1424 | |
| 1425 | /* Verified boot hash command */ |
| 1426 | #define EC_CMD_VBOOT_HASH 0x2A |
| 1427 | |
| 1428 | struct ec_params_vboot_hash { |
| 1429 | uint8_t cmd; /* enum ec_vboot_hash_cmd */ |
| 1430 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 1431 | uint8_t nonce_size; /* Nonce size; may be 0 */ |
| 1432 | uint8_t reserved0; /* Reserved; set 0 */ |
| 1433 | uint32_t offset; /* Offset in flash to hash */ |
| 1434 | uint32_t size; /* Number of bytes to hash */ |
| 1435 | uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */ |
| 1436 | } __packed; |
| 1437 | |
| 1438 | struct ec_response_vboot_hash { |
| 1439 | uint8_t status; /* enum ec_vboot_hash_status */ |
| 1440 | uint8_t hash_type; /* enum ec_vboot_hash_type */ |
| 1441 | uint8_t digest_size; /* Size of hash digest in bytes */ |
| 1442 | uint8_t reserved0; /* Ignore; will be 0 */ |
| 1443 | uint32_t offset; /* Offset in flash which was hashed */ |
| 1444 | uint32_t size; /* Number of bytes hashed */ |
| 1445 | uint8_t hash_digest[64]; /* Hash digest data */ |
| 1446 | } __packed; |
| 1447 | |
| 1448 | enum ec_vboot_hash_cmd { |
| 1449 | EC_VBOOT_HASH_GET = 0, /* Get current hash status */ |
| 1450 | EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */ |
| 1451 | EC_VBOOT_HASH_START = 2, /* Start computing a new hash */ |
| 1452 | EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */ |
| 1453 | }; |
| 1454 | |
| 1455 | enum ec_vboot_hash_type { |
| 1456 | EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */ |
| 1457 | }; |
| 1458 | |
| 1459 | enum ec_vboot_hash_status { |
| 1460 | EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */ |
| 1461 | EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */ |
| 1462 | EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */ |
| 1463 | }; |
| 1464 | |
| 1465 | /* |
| 1466 | * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC. |
| 1467 | * If one of these is specified, the EC will automatically update offset and |
| 1468 | * size to the correct values for the specified image (RO or RW). |
| 1469 | */ |
| 1470 | #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe |
| 1471 | #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd |
| 1472 | |
| 1473 | /*****************************************************************************/ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1474 | /* |
| 1475 | * Motion sense commands. We'll make separate structs for sub-commands with |
| 1476 | * different input args, so that we know how much to expect. |
| 1477 | */ |
| 1478 | #define EC_CMD_MOTION_SENSE_CMD 0x2B |
| 1479 | |
| 1480 | /* Motion sense commands */ |
| 1481 | enum motionsense_command { |
| 1482 | /* |
| 1483 | * Dump command returns all motion sensor data including motion sense |
| 1484 | * module flags and individual sensor flags. |
| 1485 | */ |
| 1486 | MOTIONSENSE_CMD_DUMP = 0, |
| 1487 | |
| 1488 | /* |
| 1489 | * Info command returns data describing the details of a given sensor, |
| 1490 | * including enum motionsensor_type, enum motionsensor_location, and |
| 1491 | * enum motionsensor_chip. |
| 1492 | */ |
| 1493 | MOTIONSENSE_CMD_INFO = 1, |
| 1494 | |
| 1495 | /* |
| 1496 | * EC Rate command is a setter/getter command for the EC sampling rate |
| 1497 | * of all motion sensors in milliseconds. |
| 1498 | */ |
| 1499 | MOTIONSENSE_CMD_EC_RATE = 2, |
| 1500 | |
| 1501 | /* |
| 1502 | * Sensor ODR command is a setter/getter command for the output data |
| 1503 | * rate of a specific motion sensor in millihertz. |
| 1504 | */ |
| 1505 | MOTIONSENSE_CMD_SENSOR_ODR = 3, |
| 1506 | |
| 1507 | /* |
| 1508 | * Sensor range command is a setter/getter command for the range of |
| 1509 | * a specified motion sensor in +/-G's or +/- deg/s. |
| 1510 | */ |
| 1511 | MOTIONSENSE_CMD_SENSOR_RANGE = 4, |
| 1512 | |
| 1513 | /* |
| 1514 | * Setter/getter command for the keyboard wake angle. When the lid |
| 1515 | * angle is greater than this value, keyboard wake is disabled in S3, |
| 1516 | * and when the lid angle goes less than this value, keyboard wake is |
| 1517 | * enabled. Note, the lid angle measurement is an approximate, |
| 1518 | * un-calibrated value, hence the wake angle isn't exact. |
| 1519 | */ |
| 1520 | MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5, |
| 1521 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1522 | /* |
| 1523 | * Returns a single sensor data. |
| 1524 | */ |
| 1525 | MOTIONSENSE_CMD_DATA = 6, |
| 1526 | |
| 1527 | /* |
| 1528 | * Perform low level calibration.. On sensors that support it, ask to |
| 1529 | * do offset calibration. |
| 1530 | */ |
| 1531 | MOTIONSENSE_CMD_PERFORM_CALIB = 10, |
| 1532 | |
| 1533 | /* |
| 1534 | * Sensor Offset command is a setter/getter command for the offset used |
| 1535 | * for calibration. The offsets can be calculated by the host, or via |
| 1536 | * PERFORM_CALIB command. |
| 1537 | */ |
| 1538 | MOTIONSENSE_CMD_SENSOR_OFFSET = 11, |
| 1539 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1540 | /* Number of motionsense sub-commands. */ |
| 1541 | MOTIONSENSE_NUM_CMDS |
| 1542 | }; |
| 1543 | |
| 1544 | enum motionsensor_id { |
| 1545 | EC_MOTION_SENSOR_ACCEL_BASE = 0, |
| 1546 | EC_MOTION_SENSOR_ACCEL_LID = 1, |
| 1547 | EC_MOTION_SENSOR_GYRO = 2, |
| 1548 | |
| 1549 | /* |
| 1550 | * Note, if more sensors are added and this count changes, the padding |
| 1551 | * in ec_response_motion_sense dump command must be modified. |
| 1552 | */ |
| 1553 | EC_MOTION_SENSOR_COUNT = 3 |
| 1554 | }; |
| 1555 | |
| 1556 | /* List of motion sensor types. */ |
| 1557 | enum motionsensor_type { |
| 1558 | MOTIONSENSE_TYPE_ACCEL = 0, |
| 1559 | MOTIONSENSE_TYPE_GYRO = 1, |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1560 | MOTIONSENSE_TYPE_MAG = 2, |
| 1561 | MOTIONSENSE_TYPE_PROX = 3, |
| 1562 | MOTIONSENSE_TYPE_LIGHT = 4, |
| 1563 | MOTIONSENSE_TYPE_ACTIVITY = 5, |
Gwendal Grignou | d732248 | 2017-01-24 14:41:41 +0100 | [diff] [blame] | 1564 | MOTIONSENSE_TYPE_BARO = 6, |
| 1565 | MOTIONSENSE_TYPE_MAX, |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1566 | }; |
| 1567 | |
| 1568 | /* List of motion sensor locations. */ |
| 1569 | enum motionsensor_location { |
| 1570 | MOTIONSENSE_LOC_BASE = 0, |
| 1571 | MOTIONSENSE_LOC_LID = 1, |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1572 | MOTIONSENSE_LOC_MAX, |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1573 | }; |
| 1574 | |
| 1575 | /* List of motion sensor chips. */ |
| 1576 | enum motionsensor_chip { |
| 1577 | MOTIONSENSE_CHIP_KXCJ9 = 0, |
| 1578 | }; |
| 1579 | |
| 1580 | /* Module flag masks used for the dump sub-command. */ |
| 1581 | #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0) |
| 1582 | |
| 1583 | /* Sensor flag masks used for the dump sub-command. */ |
| 1584 | #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0) |
| 1585 | |
| 1586 | /* |
| 1587 | * Send this value for the data element to only perform a read. If you |
| 1588 | * send any other value, the EC will interpret it as data to set and will |
| 1589 | * return the actual value set. |
| 1590 | */ |
| 1591 | #define EC_MOTION_SENSE_NO_VALUE -1 |
| 1592 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1593 | #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 |
| 1594 | |
| 1595 | /* Set Calibration information */ |
| 1596 | #define MOTION_SENSE_SET_OFFSET 1 |
| 1597 | |
| 1598 | struct ec_response_motion_sensor_data { |
| 1599 | /* Flags for each sensor. */ |
| 1600 | uint8_t flags; |
| 1601 | /* Sensor number the data comes from */ |
| 1602 | uint8_t sensor_num; |
| 1603 | /* Each sensor is up to 3-axis. */ |
| 1604 | union { |
| 1605 | int16_t data[3]; |
| 1606 | struct { |
| 1607 | uint16_t rsvd; |
| 1608 | uint32_t timestamp; |
| 1609 | } __packed; |
| 1610 | struct { |
| 1611 | uint8_t activity; /* motionsensor_activity */ |
| 1612 | uint8_t state; |
| 1613 | int16_t add_info[2]; |
| 1614 | }; |
| 1615 | }; |
| 1616 | } __packed; |
| 1617 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1618 | struct ec_params_motion_sense { |
| 1619 | uint8_t cmd; |
| 1620 | union { |
| 1621 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
| 1622 | struct { |
| 1623 | /* no args */ |
| 1624 | } dump; |
| 1625 | |
| 1626 | /* |
| 1627 | * Used for MOTIONSENSE_CMD_EC_RATE and |
| 1628 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
| 1629 | */ |
| 1630 | struct { |
| 1631 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 1632 | int16_t data; |
| 1633 | } ec_rate, kb_wake_angle; |
| 1634 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1635 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
| 1636 | struct { |
| 1637 | uint8_t sensor_num; |
| 1638 | |
| 1639 | /* |
| 1640 | * bit 0: If set (MOTION_SENSE_SET_OFFSET), set |
| 1641 | * the calibration information in the EC. |
| 1642 | * If unset, just retrieve calibration information. |
| 1643 | */ |
| 1644 | uint16_t flags; |
| 1645 | |
| 1646 | /* |
| 1647 | * Temperature at calibration, in units of 0.01 C |
| 1648 | * 0x8000: invalid / unknown. |
| 1649 | * 0x0: 0C |
| 1650 | * 0x7fff: +327.67C |
| 1651 | */ |
| 1652 | int16_t temp; |
| 1653 | |
| 1654 | /* |
| 1655 | * Offset for calibration. |
| 1656 | * Unit: |
| 1657 | * Accelerometer: 1/1024 g |
| 1658 | * Gyro: 1/1024 deg/s |
| 1659 | * Compass: 1/16 uT |
| 1660 | */ |
| 1661 | int16_t offset[3]; |
| 1662 | } __packed sensor_offset; |
| 1663 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1664 | /* Used for MOTIONSENSE_CMD_INFO. */ |
| 1665 | struct { |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1666 | uint8_t sensor_num; |
| 1667 | } info; |
| 1668 | |
| 1669 | /* |
| 1670 | * Used for MOTIONSENSE_CMD_SENSOR_ODR and |
| 1671 | * MOTIONSENSE_CMD_SENSOR_RANGE. |
| 1672 | */ |
| 1673 | struct { |
| 1674 | /* Should be element of enum motionsensor_id. */ |
| 1675 | uint8_t sensor_num; |
| 1676 | |
| 1677 | /* Rounding flag, true for round-up, false for down. */ |
| 1678 | uint8_t roundup; |
| 1679 | |
| 1680 | uint16_t reserved; |
| 1681 | |
| 1682 | /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ |
| 1683 | int32_t data; |
| 1684 | } sensor_odr, sensor_range; |
| 1685 | }; |
| 1686 | } __packed; |
| 1687 | |
| 1688 | struct ec_response_motion_sense { |
| 1689 | union { |
| 1690 | /* Used for MOTIONSENSE_CMD_DUMP. */ |
| 1691 | struct { |
| 1692 | /* Flags representing the motion sensor module. */ |
| 1693 | uint8_t module_flags; |
| 1694 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1695 | /* Number of sensors managed directly by the EC. */ |
| 1696 | uint8_t sensor_count; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1697 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1698 | /* |
| 1699 | * Sensor data is truncated if response_max is too small |
| 1700 | * for holding all the data. |
| 1701 | */ |
| 1702 | struct ec_response_motion_sensor_data sensor[0]; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1703 | } dump; |
| 1704 | |
| 1705 | /* Used for MOTIONSENSE_CMD_INFO. */ |
| 1706 | struct { |
| 1707 | /* Should be element of enum motionsensor_type. */ |
| 1708 | uint8_t type; |
| 1709 | |
| 1710 | /* Should be element of enum motionsensor_location. */ |
| 1711 | uint8_t location; |
| 1712 | |
| 1713 | /* Should be element of enum motionsensor_chip. */ |
| 1714 | uint8_t chip; |
| 1715 | } info; |
| 1716 | |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1717 | /* Used for MOTIONSENSE_CMD_DATA */ |
| 1718 | struct ec_response_motion_sensor_data data; |
| 1719 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1720 | /* |
| 1721 | * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, |
| 1722 | * MOTIONSENSE_CMD_SENSOR_RANGE, and |
| 1723 | * MOTIONSENSE_CMD_KB_WAKE_ANGLE. |
| 1724 | */ |
| 1725 | struct { |
| 1726 | /* Current value of the parameter queried. */ |
| 1727 | int32_t ret; |
| 1728 | } ec_rate, sensor_odr, sensor_range, kb_wake_angle; |
Enric Balletbo i Serra | 974e6f0 | 2016-08-01 11:54:35 +0200 | [diff] [blame] | 1729 | |
| 1730 | /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ |
| 1731 | struct { |
| 1732 | int16_t temp; |
| 1733 | int16_t offset[3]; |
| 1734 | } sensor_offset, perform_calib; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1735 | }; |
| 1736 | } __packed; |
| 1737 | |
| 1738 | /*****************************************************************************/ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1739 | /* USB charging control commands */ |
| 1740 | |
| 1741 | /* Set USB port charging mode */ |
| 1742 | #define EC_CMD_USB_CHARGE_SET_MODE 0x30 |
| 1743 | |
| 1744 | struct ec_params_usb_charge_set_mode { |
| 1745 | uint8_t usb_port_id; |
| 1746 | uint8_t mode; |
| 1747 | } __packed; |
| 1748 | |
| 1749 | /*****************************************************************************/ |
| 1750 | /* Persistent storage for host */ |
| 1751 | |
| 1752 | /* Maximum bytes that can be read/written in a single command */ |
| 1753 | #define EC_PSTORE_SIZE_MAX 64 |
| 1754 | |
| 1755 | /* Get persistent storage info */ |
| 1756 | #define EC_CMD_PSTORE_INFO 0x40 |
| 1757 | |
| 1758 | struct ec_response_pstore_info { |
| 1759 | /* Persistent storage size, in bytes */ |
| 1760 | uint32_t pstore_size; |
| 1761 | /* Access size; read/write offset and size must be a multiple of this */ |
| 1762 | uint32_t access_size; |
| 1763 | } __packed; |
| 1764 | |
| 1765 | /* |
| 1766 | * Read persistent storage |
| 1767 | * |
| 1768 | * Response is params.size bytes of data. |
| 1769 | */ |
| 1770 | #define EC_CMD_PSTORE_READ 0x41 |
| 1771 | |
| 1772 | struct ec_params_pstore_read { |
| 1773 | uint32_t offset; /* Byte offset to read */ |
| 1774 | uint32_t size; /* Size to read in bytes */ |
| 1775 | } __packed; |
| 1776 | |
| 1777 | /* Write persistent storage */ |
| 1778 | #define EC_CMD_PSTORE_WRITE 0x42 |
| 1779 | |
| 1780 | struct ec_params_pstore_write { |
| 1781 | uint32_t offset; /* Byte offset to write */ |
| 1782 | uint32_t size; /* Size to write in bytes */ |
| 1783 | uint8_t data[EC_PSTORE_SIZE_MAX]; |
| 1784 | } __packed; |
| 1785 | |
| 1786 | /*****************************************************************************/ |
| 1787 | /* Real-time clock */ |
| 1788 | |
| 1789 | /* RTC params and response structures */ |
| 1790 | struct ec_params_rtc { |
| 1791 | uint32_t time; |
| 1792 | } __packed; |
| 1793 | |
| 1794 | struct ec_response_rtc { |
| 1795 | uint32_t time; |
| 1796 | } __packed; |
| 1797 | |
| 1798 | /* These use ec_response_rtc */ |
| 1799 | #define EC_CMD_RTC_GET_VALUE 0x44 |
| 1800 | #define EC_CMD_RTC_GET_ALARM 0x45 |
| 1801 | |
| 1802 | /* These all use ec_params_rtc */ |
| 1803 | #define EC_CMD_RTC_SET_VALUE 0x46 |
| 1804 | #define EC_CMD_RTC_SET_ALARM 0x47 |
| 1805 | |
Stephen Barber | 3eff6d2 | 2017-11-10 22:55:52 +0100 | [diff] [blame] | 1806 | /* Pass as param to SET_ALARM to clear the current alarm */ |
| 1807 | #define EC_RTC_ALARM_CLEAR 0 |
| 1808 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1809 | /*****************************************************************************/ |
| 1810 | /* Port80 log access */ |
| 1811 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1812 | /* Maximum entries that can be read/written in a single command */ |
| 1813 | #define EC_PORT80_SIZE_MAX 32 |
| 1814 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1815 | /* Get last port80 code from previous boot */ |
| 1816 | #define EC_CMD_PORT80_LAST_BOOT 0x48 |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 1817 | #define EC_CMD_PORT80_READ 0x48 |
| 1818 | |
| 1819 | enum ec_port80_subcmd { |
| 1820 | EC_PORT80_GET_INFO = 0, |
| 1821 | EC_PORT80_READ_BUFFER, |
| 1822 | }; |
| 1823 | |
| 1824 | struct ec_params_port80_read { |
| 1825 | uint16_t subcmd; |
| 1826 | union { |
| 1827 | struct { |
| 1828 | uint32_t offset; |
| 1829 | uint32_t num_entries; |
| 1830 | } read_buffer; |
| 1831 | }; |
| 1832 | } __packed; |
| 1833 | |
| 1834 | struct ec_response_port80_read { |
| 1835 | union { |
| 1836 | struct { |
| 1837 | uint32_t writes; |
| 1838 | uint32_t history_size; |
| 1839 | uint32_t last_boot; |
| 1840 | } get_info; |
| 1841 | struct { |
| 1842 | uint16_t codes[EC_PORT80_SIZE_MAX]; |
| 1843 | } data; |
| 1844 | }; |
| 1845 | } __packed; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1846 | |
| 1847 | struct ec_response_port80_last_boot { |
| 1848 | uint16_t code; |
| 1849 | } __packed; |
| 1850 | |
| 1851 | /*****************************************************************************/ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1852 | /* Thermal engine commands. Note that there are two implementations. We'll |
| 1853 | * reuse the command number, but the data and behavior is incompatible. |
| 1854 | * Version 0 is what originally shipped on Link. |
| 1855 | * Version 1 separates the CPU thermal limits from the fan control. |
| 1856 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1857 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1858 | #define EC_CMD_THERMAL_SET_THRESHOLD 0x50 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1859 | #define EC_CMD_THERMAL_GET_THRESHOLD 0x51 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1860 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1861 | /* The version 0 structs are opaque. You have to know what they are for |
| 1862 | * the get/set commands to make any sense. |
| 1863 | */ |
| 1864 | |
| 1865 | /* Version 0 - set */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1866 | struct ec_params_thermal_set_threshold { |
| 1867 | uint8_t sensor_type; |
| 1868 | uint8_t threshold_id; |
| 1869 | uint16_t value; |
| 1870 | } __packed; |
| 1871 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1872 | /* Version 0 - get */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1873 | struct ec_params_thermal_get_threshold { |
| 1874 | uint8_t sensor_type; |
| 1875 | uint8_t threshold_id; |
| 1876 | } __packed; |
| 1877 | |
| 1878 | struct ec_response_thermal_get_threshold { |
| 1879 | uint16_t value; |
| 1880 | } __packed; |
| 1881 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1882 | |
| 1883 | /* The version 1 structs are visible. */ |
| 1884 | enum ec_temp_thresholds { |
| 1885 | EC_TEMP_THRESH_WARN = 0, |
| 1886 | EC_TEMP_THRESH_HIGH, |
| 1887 | EC_TEMP_THRESH_HALT, |
| 1888 | |
| 1889 | EC_TEMP_THRESH_COUNT |
| 1890 | }; |
| 1891 | |
| 1892 | /* Thermal configuration for one temperature sensor. Temps are in degrees K. |
| 1893 | * Zero values will be silently ignored by the thermal task. |
| 1894 | */ |
| 1895 | struct ec_thermal_config { |
| 1896 | uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ |
| 1897 | uint32_t temp_fan_off; /* no active cooling needed */ |
| 1898 | uint32_t temp_fan_max; /* max active cooling needed */ |
| 1899 | } __packed; |
| 1900 | |
| 1901 | /* Version 1 - get config for one sensor. */ |
| 1902 | struct ec_params_thermal_get_threshold_v1 { |
| 1903 | uint32_t sensor_num; |
| 1904 | } __packed; |
| 1905 | /* This returns a struct ec_thermal_config */ |
| 1906 | |
| 1907 | /* Version 1 - set config for one sensor. |
| 1908 | * Use read-modify-write for best results! */ |
| 1909 | struct ec_params_thermal_set_threshold_v1 { |
| 1910 | uint32_t sensor_num; |
| 1911 | struct ec_thermal_config cfg; |
| 1912 | } __packed; |
| 1913 | /* This returns no data */ |
| 1914 | |
| 1915 | /****************************************************************************/ |
| 1916 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1917 | /* Toggle automatic fan control */ |
| 1918 | #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52 |
| 1919 | |
| 1920 | /* Get TMP006 calibration data */ |
| 1921 | #define EC_CMD_TMP006_GET_CALIBRATION 0x53 |
| 1922 | |
| 1923 | struct ec_params_tmp006_get_calibration { |
| 1924 | uint8_t index; |
| 1925 | } __packed; |
| 1926 | |
| 1927 | struct ec_response_tmp006_get_calibration { |
| 1928 | float s0; |
| 1929 | float b0; |
| 1930 | float b1; |
| 1931 | float b2; |
| 1932 | } __packed; |
| 1933 | |
| 1934 | /* Set TMP006 calibration data */ |
| 1935 | #define EC_CMD_TMP006_SET_CALIBRATION 0x54 |
| 1936 | |
| 1937 | struct ec_params_tmp006_set_calibration { |
| 1938 | uint8_t index; |
| 1939 | uint8_t reserved[3]; /* Reserved; set 0 */ |
| 1940 | float s0; |
| 1941 | float b0; |
| 1942 | float b1; |
| 1943 | float b2; |
| 1944 | } __packed; |
| 1945 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 1946 | /* Read raw TMP006 data */ |
| 1947 | #define EC_CMD_TMP006_GET_RAW 0x55 |
| 1948 | |
| 1949 | struct ec_params_tmp006_get_raw { |
| 1950 | uint8_t index; |
| 1951 | } __packed; |
| 1952 | |
| 1953 | struct ec_response_tmp006_get_raw { |
| 1954 | int32_t t; /* In 1/100 K */ |
| 1955 | int32_t v; /* In nV */ |
| 1956 | }; |
| 1957 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1958 | /*****************************************************************************/ |
| 1959 | /* MKBP - Matrix KeyBoard Protocol */ |
| 1960 | |
| 1961 | /* |
| 1962 | * Read key state |
| 1963 | * |
| 1964 | * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for |
| 1965 | * expected response size. |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 1966 | * |
| 1967 | * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish |
| 1968 | * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type |
| 1969 | * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1970 | */ |
| 1971 | #define EC_CMD_MKBP_STATE 0x60 |
| 1972 | |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 1973 | /* |
| 1974 | * Provide information about various MKBP things. See enum ec_mkbp_info_type. |
| 1975 | */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1976 | #define EC_CMD_MKBP_INFO 0x61 |
| 1977 | |
| 1978 | struct ec_response_mkbp_info { |
| 1979 | uint32_t rows; |
| 1980 | uint32_t cols; |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 1981 | /* Formerly "switches", which was 0. */ |
| 1982 | uint8_t reserved; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 1983 | } __packed; |
| 1984 | |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 1985 | struct ec_params_mkbp_info { |
| 1986 | uint8_t info_type; |
| 1987 | uint8_t event_type; |
| 1988 | } __packed; |
| 1989 | |
| 1990 | enum ec_mkbp_info_type { |
| 1991 | /* |
| 1992 | * Info about the keyboard matrix: number of rows and columns. |
| 1993 | * |
| 1994 | * Returns struct ec_response_mkbp_info. |
| 1995 | */ |
| 1996 | EC_MKBP_INFO_KBD = 0, |
| 1997 | |
| 1998 | /* |
| 1999 | * For buttons and switches, info about which specifically are |
| 2000 | * supported. event_type must be set to one of the values in enum |
| 2001 | * ec_mkbp_event. |
| 2002 | * |
| 2003 | * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte |
| 2004 | * bitmask indicating which buttons or switches are present. See the |
| 2005 | * bit inidices below. |
| 2006 | */ |
| 2007 | EC_MKBP_INFO_SUPPORTED = 1, |
| 2008 | |
| 2009 | /* |
| 2010 | * Instantaneous state of buttons and switches. |
| 2011 | * |
| 2012 | * event_type must be set to one of the values in enum ec_mkbp_event. |
| 2013 | * |
| 2014 | * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13] |
| 2015 | * indicating the current state of the keyboard matrix. |
| 2016 | * |
| 2017 | * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw |
| 2018 | * event state. |
| 2019 | * |
| 2020 | * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the |
| 2021 | * state of supported buttons. |
| 2022 | * |
| 2023 | * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the |
| 2024 | * state of supported switches. |
| 2025 | */ |
| 2026 | EC_MKBP_INFO_CURRENT = 2, |
| 2027 | }; |
| 2028 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2029 | /* Simulate key press */ |
| 2030 | #define EC_CMD_MKBP_SIMULATE_KEY 0x62 |
| 2031 | |
| 2032 | struct ec_params_mkbp_simulate_key { |
| 2033 | uint8_t col; |
| 2034 | uint8_t row; |
| 2035 | uint8_t pressed; |
| 2036 | } __packed; |
| 2037 | |
| 2038 | /* Configure keyboard scanning */ |
| 2039 | #define EC_CMD_MKBP_SET_CONFIG 0x64 |
| 2040 | #define EC_CMD_MKBP_GET_CONFIG 0x65 |
| 2041 | |
| 2042 | /* flags */ |
| 2043 | enum mkbp_config_flags { |
| 2044 | EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */ |
| 2045 | }; |
| 2046 | |
| 2047 | enum mkbp_config_valid { |
| 2048 | EC_MKBP_VALID_SCAN_PERIOD = 1 << 0, |
| 2049 | EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1, |
| 2050 | EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3, |
| 2051 | EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4, |
| 2052 | EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5, |
| 2053 | EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6, |
| 2054 | EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7, |
| 2055 | }; |
| 2056 | |
| 2057 | /* Configuration for our key scanning algorithm */ |
| 2058 | struct ec_mkbp_config { |
| 2059 | uint32_t valid_mask; /* valid fields */ |
| 2060 | uint8_t flags; /* some flags (enum mkbp_config_flags) */ |
| 2061 | uint8_t valid_flags; /* which flags are valid */ |
| 2062 | uint16_t scan_period_us; /* period between start of scans */ |
| 2063 | /* revert to interrupt mode after no activity for this long */ |
| 2064 | uint32_t poll_timeout_us; |
| 2065 | /* |
| 2066 | * minimum post-scan relax time. Once we finish a scan we check |
| 2067 | * the time until we are due to start the next one. If this time is |
| 2068 | * shorter this field, we use this instead. |
| 2069 | */ |
| 2070 | uint16_t min_post_scan_delay_us; |
| 2071 | /* delay between setting up output and waiting for it to settle */ |
| 2072 | uint16_t output_settle_us; |
| 2073 | uint16_t debounce_down_us; /* time for debounce on key down */ |
| 2074 | uint16_t debounce_up_us; /* time for debounce on key up */ |
| 2075 | /* maximum depth to allow for fifo (0 = no keyscan output) */ |
| 2076 | uint8_t fifo_max_depth; |
| 2077 | } __packed; |
| 2078 | |
| 2079 | struct ec_params_mkbp_set_config { |
| 2080 | struct ec_mkbp_config config; |
| 2081 | } __packed; |
| 2082 | |
| 2083 | struct ec_response_mkbp_get_config { |
| 2084 | struct ec_mkbp_config config; |
| 2085 | } __packed; |
| 2086 | |
| 2087 | /* Run the key scan emulation */ |
| 2088 | #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66 |
| 2089 | |
| 2090 | enum ec_keyscan_seq_cmd { |
| 2091 | EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ |
| 2092 | EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */ |
| 2093 | EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */ |
| 2094 | EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */ |
| 2095 | EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */ |
| 2096 | }; |
| 2097 | |
| 2098 | enum ec_collect_flags { |
| 2099 | /* |
| 2100 | * Indicates this scan was processed by the EC. Due to timing, some |
| 2101 | * scans may be skipped. |
| 2102 | */ |
| 2103 | EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0, |
| 2104 | }; |
| 2105 | |
| 2106 | struct ec_collect_item { |
| 2107 | uint8_t flags; /* some flags (enum ec_collect_flags) */ |
| 2108 | }; |
| 2109 | |
| 2110 | struct ec_params_keyscan_seq_ctrl { |
| 2111 | uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ |
| 2112 | union { |
| 2113 | struct { |
| 2114 | uint8_t active; /* still active */ |
| 2115 | uint8_t num_items; /* number of items */ |
| 2116 | /* Current item being presented */ |
| 2117 | uint8_t cur_item; |
| 2118 | } status; |
| 2119 | struct { |
| 2120 | /* |
| 2121 | * Absolute time for this scan, measured from the |
| 2122 | * start of the sequence. |
| 2123 | */ |
| 2124 | uint32_t time_us; |
| 2125 | uint8_t scan[0]; /* keyscan data */ |
| 2126 | } add; |
| 2127 | struct { |
| 2128 | uint8_t start_item; /* First item to return */ |
| 2129 | uint8_t num_items; /* Number of items to return */ |
| 2130 | } collect; |
| 2131 | }; |
| 2132 | } __packed; |
| 2133 | |
| 2134 | struct ec_result_keyscan_seq_ctrl { |
| 2135 | union { |
| 2136 | struct { |
| 2137 | uint8_t num_items; /* Number of items */ |
| 2138 | /* Data for each item */ |
| 2139 | struct ec_collect_item item[0]; |
| 2140 | } collect; |
| 2141 | }; |
| 2142 | } __packed; |
| 2143 | |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 2144 | /* |
| 2145 | * Command for retrieving the next pending MKBP event from the EC device |
| 2146 | * |
| 2147 | * The device replies with UNAVAILABLE if there aren't any pending events. |
| 2148 | */ |
| 2149 | #define EC_CMD_GET_NEXT_EVENT 0x67 |
| 2150 | |
| 2151 | enum ec_mkbp_event { |
| 2152 | /* Keyboard matrix changed. The event data is the new matrix state. */ |
| 2153 | EC_MKBP_EVENT_KEY_MATRIX = 0, |
| 2154 | |
| 2155 | /* New host event. The event data is 4 bytes of host event flags. */ |
| 2156 | EC_MKBP_EVENT_HOST_EVENT = 1, |
| 2157 | |
| 2158 | /* New Sensor FIFO data. The event data is fifo_info structure. */ |
| 2159 | EC_MKBP_EVENT_SENSOR_FIFO = 2, |
| 2160 | |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 2161 | /* The state of the non-matrixed buttons have changed. */ |
| 2162 | EC_MKBP_EVENT_BUTTON = 3, |
| 2163 | |
| 2164 | /* The state of the switches have changed. */ |
| 2165 | EC_MKBP_EVENT_SWITCH = 4, |
| 2166 | |
Rajat Jain | e6eba3f | 2017-04-03 11:53:41 -0700 | [diff] [blame] | 2167 | /* EC sent a sysrq command */ |
| 2168 | EC_MKBP_EVENT_SYSRQ = 6, |
| 2169 | |
Neil Armstrong | f47674e | 2018-07-04 17:08:19 +0200 | [diff] [blame] | 2170 | /* Notify the AP that something happened on CEC */ |
| 2171 | EC_MKBP_EVENT_CEC_EVENT = 8, |
| 2172 | |
| 2173 | /* Send an incoming CEC message to the AP */ |
| 2174 | EC_MKBP_EVENT_CEC_MESSAGE = 9, |
| 2175 | |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 2176 | /* Number of MKBP events */ |
| 2177 | EC_MKBP_EVENT_COUNT, |
| 2178 | }; |
| 2179 | |
| 2180 | union ec_response_get_next_data { |
| 2181 | uint8_t key_matrix[13]; |
| 2182 | |
| 2183 | /* Unaligned */ |
| 2184 | uint32_t host_event; |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 2185 | |
| 2186 | uint32_t buttons; |
| 2187 | uint32_t switches; |
Rajat Jain | e6eba3f | 2017-04-03 11:53:41 -0700 | [diff] [blame] | 2188 | uint32_t sysrq; |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 2189 | } __packed; |
| 2190 | |
Neil Armstrong | 57e94c8 | 2018-07-04 17:08:18 +0200 | [diff] [blame] | 2191 | union ec_response_get_next_data_v1 { |
| 2192 | uint8_t key_matrix[16]; |
| 2193 | uint32_t host_event; |
| 2194 | uint32_t buttons; |
| 2195 | uint32_t switches; |
| 2196 | uint32_t sysrq; |
| 2197 | uint32_t cec_events; |
| 2198 | uint8_t cec_message[16]; |
| 2199 | } __packed; |
| 2200 | |
Vic Yang | 6f1d912 | 2016-08-10 19:05:24 +0200 | [diff] [blame] | 2201 | struct ec_response_get_next_event { |
| 2202 | uint8_t event_type; |
| 2203 | /* Followed by event data if any */ |
| 2204 | union ec_response_get_next_data data; |
| 2205 | } __packed; |
| 2206 | |
Neil Armstrong | 57e94c8 | 2018-07-04 17:08:18 +0200 | [diff] [blame] | 2207 | struct ec_response_get_next_event_v1 { |
| 2208 | uint8_t event_type; |
| 2209 | /* Followed by event data if any */ |
| 2210 | union ec_response_get_next_data_v1 data; |
| 2211 | } __packed; |
| 2212 | |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 2213 | /* Bit indices for buttons and switches.*/ |
| 2214 | /* Buttons */ |
| 2215 | #define EC_MKBP_POWER_BUTTON 0 |
| 2216 | #define EC_MKBP_VOL_UP 1 |
| 2217 | #define EC_MKBP_VOL_DOWN 2 |
| 2218 | |
| 2219 | /* Switches */ |
| 2220 | #define EC_MKBP_LID_OPEN 0 |
Gwendal Grignou | 6ccc3a3 | 2017-01-27 11:52:35 +0100 | [diff] [blame] | 2221 | #define EC_MKBP_TABLET_MODE 1 |
Dmitry Torokhov | 78d8f8f | 2018-10-05 11:41:13 -0700 | [diff] [blame] | 2222 | #define EC_MKBP_BASE_ATTACHED 2 |
Douglas Anderson | b44c4d3 | 2017-01-20 11:14:14 +0100 | [diff] [blame] | 2223 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2224 | /*****************************************************************************/ |
| 2225 | /* Temperature sensor commands */ |
| 2226 | |
| 2227 | /* Read temperature sensor info */ |
| 2228 | #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70 |
| 2229 | |
| 2230 | struct ec_params_temp_sensor_get_info { |
| 2231 | uint8_t id; |
| 2232 | } __packed; |
| 2233 | |
| 2234 | struct ec_response_temp_sensor_get_info { |
| 2235 | char sensor_name[32]; |
| 2236 | uint8_t sensor_type; |
| 2237 | } __packed; |
| 2238 | |
| 2239 | /*****************************************************************************/ |
| 2240 | |
| 2241 | /* |
| 2242 | * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI |
| 2243 | * commands accidentally sent to the wrong interface. See the ACPI section |
| 2244 | * below. |
| 2245 | */ |
| 2246 | |
| 2247 | /*****************************************************************************/ |
| 2248 | /* Host event commands */ |
| 2249 | |
| 2250 | /* |
| 2251 | * Host event mask params and response structures, shared by all of the host |
| 2252 | * event commands below. |
| 2253 | */ |
| 2254 | struct ec_params_host_event_mask { |
| 2255 | uint32_t mask; |
| 2256 | } __packed; |
| 2257 | |
| 2258 | struct ec_response_host_event_mask { |
| 2259 | uint32_t mask; |
| 2260 | } __packed; |
| 2261 | |
| 2262 | /* These all use ec_response_host_event_mask */ |
| 2263 | #define EC_CMD_HOST_EVENT_GET_B 0x87 |
| 2264 | #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88 |
| 2265 | #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89 |
| 2266 | #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d |
| 2267 | |
| 2268 | /* These all use ec_params_host_event_mask */ |
| 2269 | #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a |
| 2270 | #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b |
| 2271 | #define EC_CMD_HOST_EVENT_CLEAR 0x8c |
| 2272 | #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e |
| 2273 | #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f |
| 2274 | |
| 2275 | /*****************************************************************************/ |
| 2276 | /* Switch commands */ |
| 2277 | |
| 2278 | /* Enable/disable LCD backlight */ |
| 2279 | #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90 |
| 2280 | |
| 2281 | struct ec_params_switch_enable_backlight { |
| 2282 | uint8_t enabled; |
| 2283 | } __packed; |
| 2284 | |
| 2285 | /* Enable/disable WLAN/Bluetooth */ |
| 2286 | #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2287 | #define EC_VER_SWITCH_ENABLE_WIRELESS 1 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2288 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2289 | /* Version 0 params; no response */ |
| 2290 | struct ec_params_switch_enable_wireless_v0 { |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2291 | uint8_t enabled; |
| 2292 | } __packed; |
| 2293 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2294 | /* Version 1 params */ |
| 2295 | struct ec_params_switch_enable_wireless_v1 { |
| 2296 | /* Flags to enable now */ |
| 2297 | uint8_t now_flags; |
| 2298 | |
| 2299 | /* Which flags to copy from now_flags */ |
| 2300 | uint8_t now_mask; |
| 2301 | |
| 2302 | /* |
| 2303 | * Flags to leave enabled in S3, if they're on at the S0->S3 |
| 2304 | * transition. (Other flags will be disabled by the S0->S3 |
| 2305 | * transition.) |
| 2306 | */ |
| 2307 | uint8_t suspend_flags; |
| 2308 | |
| 2309 | /* Which flags to copy from suspend_flags */ |
| 2310 | uint8_t suspend_mask; |
| 2311 | } __packed; |
| 2312 | |
| 2313 | /* Version 1 response */ |
| 2314 | struct ec_response_switch_enable_wireless_v1 { |
| 2315 | /* Flags to enable now */ |
| 2316 | uint8_t now_flags; |
| 2317 | |
| 2318 | /* Flags to leave enabled in S3 */ |
| 2319 | uint8_t suspend_flags; |
| 2320 | } __packed; |
| 2321 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2322 | /*****************************************************************************/ |
| 2323 | /* GPIO commands. Only available on EC if write protect has been disabled. */ |
| 2324 | |
| 2325 | /* Set GPIO output value */ |
| 2326 | #define EC_CMD_GPIO_SET 0x92 |
| 2327 | |
| 2328 | struct ec_params_gpio_set { |
| 2329 | char name[32]; |
| 2330 | uint8_t val; |
| 2331 | } __packed; |
| 2332 | |
| 2333 | /* Get GPIO value */ |
| 2334 | #define EC_CMD_GPIO_GET 0x93 |
| 2335 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2336 | /* Version 0 of input params and response */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2337 | struct ec_params_gpio_get { |
| 2338 | char name[32]; |
| 2339 | } __packed; |
| 2340 | struct ec_response_gpio_get { |
| 2341 | uint8_t val; |
| 2342 | } __packed; |
| 2343 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2344 | /* Version 1 of input params and response */ |
| 2345 | struct ec_params_gpio_get_v1 { |
| 2346 | uint8_t subcmd; |
| 2347 | union { |
| 2348 | struct { |
| 2349 | char name[32]; |
| 2350 | } get_value_by_name; |
| 2351 | struct { |
| 2352 | uint8_t index; |
| 2353 | } get_info; |
| 2354 | }; |
| 2355 | } __packed; |
| 2356 | |
| 2357 | struct ec_response_gpio_get_v1 { |
| 2358 | union { |
| 2359 | struct { |
| 2360 | uint8_t val; |
| 2361 | } get_value_by_name, get_count; |
| 2362 | struct { |
| 2363 | uint8_t val; |
| 2364 | char name[32]; |
| 2365 | uint32_t flags; |
| 2366 | } get_info; |
| 2367 | }; |
| 2368 | } __packed; |
| 2369 | |
| 2370 | enum gpio_get_subcmd { |
| 2371 | EC_GPIO_GET_BY_NAME = 0, |
| 2372 | EC_GPIO_GET_COUNT = 1, |
| 2373 | EC_GPIO_GET_INFO = 2, |
| 2374 | }; |
| 2375 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2376 | /*****************************************************************************/ |
| 2377 | /* I2C commands. Only available when flash write protect is unlocked. */ |
| 2378 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2379 | /* |
| 2380 | * TODO(crosbug.com/p/23570): These commands are deprecated, and will be |
| 2381 | * removed soon. Use EC_CMD_I2C_XFER instead. |
| 2382 | */ |
| 2383 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2384 | /* Read I2C bus */ |
| 2385 | #define EC_CMD_I2C_READ 0x94 |
| 2386 | |
| 2387 | struct ec_params_i2c_read { |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2388 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2389 | uint8_t read_size; /* Either 8 or 16. */ |
| 2390 | uint8_t port; |
| 2391 | uint8_t offset; |
| 2392 | } __packed; |
| 2393 | struct ec_response_i2c_read { |
| 2394 | uint16_t data; |
| 2395 | } __packed; |
| 2396 | |
| 2397 | /* Write I2C bus */ |
| 2398 | #define EC_CMD_I2C_WRITE 0x95 |
| 2399 | |
| 2400 | struct ec_params_i2c_write { |
| 2401 | uint16_t data; |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2402 | uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2403 | uint8_t write_size; /* Either 8 or 16. */ |
| 2404 | uint8_t port; |
| 2405 | uint8_t offset; |
| 2406 | } __packed; |
| 2407 | |
| 2408 | /*****************************************************************************/ |
| 2409 | /* Charge state commands. Only available when flash write protect unlocked. */ |
| 2410 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2411 | /* Force charge state machine to stop charging the battery or force it to |
| 2412 | * discharge the battery. |
| 2413 | */ |
| 2414 | #define EC_CMD_CHARGE_CONTROL 0x96 |
| 2415 | #define EC_VER_CHARGE_CONTROL 1 |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2416 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2417 | enum ec_charge_control_mode { |
| 2418 | CHARGE_CONTROL_NORMAL = 0, |
| 2419 | CHARGE_CONTROL_IDLE, |
| 2420 | CHARGE_CONTROL_DISCHARGE, |
| 2421 | }; |
| 2422 | |
| 2423 | struct ec_params_charge_control { |
| 2424 | uint32_t mode; /* enum charge_control_mode */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2425 | } __packed; |
| 2426 | |
| 2427 | /*****************************************************************************/ |
| 2428 | /* Console commands. Only available when flash write protect is unlocked. */ |
| 2429 | |
| 2430 | /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ |
| 2431 | #define EC_CMD_CONSOLE_SNAPSHOT 0x97 |
| 2432 | |
| 2433 | /* |
Nicolas Boichat | 0aa877c | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 2434 | * Read data from the saved snapshot. If the subcmd parameter is |
| 2435 | * CONSOLE_READ_NEXT, this will return data starting from the beginning of |
| 2436 | * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the |
| 2437 | * end of the previous snapshot. |
| 2438 | * |
| 2439 | * The params are only looked at in version >= 1 of this command. Prior |
| 2440 | * versions will just default to CONSOLE_READ_NEXT behavior. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2441 | * |
| 2442 | * Response is null-terminated string. Empty string, if there is no more |
| 2443 | * remaining output. |
| 2444 | */ |
| 2445 | #define EC_CMD_CONSOLE_READ 0x98 |
| 2446 | |
Nicolas Boichat | 0aa877c | 2017-05-16 17:46:48 +0200 | [diff] [blame] | 2447 | enum ec_console_read_subcmd { |
| 2448 | CONSOLE_READ_NEXT = 0, |
| 2449 | CONSOLE_READ_RECENT |
| 2450 | }; |
| 2451 | |
| 2452 | struct ec_params_console_read_v1 { |
| 2453 | uint8_t subcmd; /* enum ec_console_read_subcmd */ |
| 2454 | } __packed; |
| 2455 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2456 | /*****************************************************************************/ |
| 2457 | |
| 2458 | /* |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2459 | * Cut off battery power immediately or after the host has shut down. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2460 | * |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2461 | * return EC_RES_INVALID_COMMAND if unsupported by a board/battery. |
| 2462 | * EC_RES_SUCCESS if the command was successful. |
| 2463 | * EC_RES_ERROR if the cut off command failed. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2464 | */ |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2465 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2466 | #define EC_CMD_BATTERY_CUT_OFF 0x99 |
| 2467 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2468 | #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0) |
| 2469 | |
| 2470 | struct ec_params_battery_cutoff { |
| 2471 | uint8_t flags; |
| 2472 | } __packed; |
| 2473 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2474 | /*****************************************************************************/ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2475 | /* USB port mux control. */ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2476 | |
| 2477 | /* |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2478 | * Switch USB mux or return to automatic switching. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2479 | */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2480 | #define EC_CMD_USB_MUX 0x9a |
| 2481 | |
| 2482 | struct ec_params_usb_mux { |
| 2483 | uint8_t mux; |
| 2484 | } __packed; |
| 2485 | |
| 2486 | /*****************************************************************************/ |
| 2487 | /* LDOs / FETs control. */ |
| 2488 | |
| 2489 | enum ec_ldo_state { |
| 2490 | EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */ |
| 2491 | EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */ |
| 2492 | }; |
| 2493 | |
| 2494 | /* |
| 2495 | * Switch on/off a LDO. |
| 2496 | */ |
| 2497 | #define EC_CMD_LDO_SET 0x9b |
| 2498 | |
| 2499 | struct ec_params_ldo_set { |
| 2500 | uint8_t index; |
| 2501 | uint8_t state; |
| 2502 | } __packed; |
| 2503 | |
| 2504 | /* |
| 2505 | * Get LDO state. |
| 2506 | */ |
| 2507 | #define EC_CMD_LDO_GET 0x9c |
| 2508 | |
| 2509 | struct ec_params_ldo_get { |
| 2510 | uint8_t index; |
| 2511 | } __packed; |
| 2512 | |
| 2513 | struct ec_response_ldo_get { |
| 2514 | uint8_t state; |
| 2515 | } __packed; |
| 2516 | |
| 2517 | /*****************************************************************************/ |
| 2518 | /* Power info. */ |
| 2519 | |
| 2520 | /* |
| 2521 | * Get power info. |
| 2522 | */ |
| 2523 | #define EC_CMD_POWER_INFO 0x9d |
| 2524 | |
| 2525 | struct ec_response_power_info { |
| 2526 | uint32_t usb_dev_type; |
| 2527 | uint16_t voltage_ac; |
| 2528 | uint16_t voltage_system; |
| 2529 | uint16_t current_system; |
| 2530 | uint16_t usb_current_limit; |
| 2531 | } __packed; |
| 2532 | |
| 2533 | /*****************************************************************************/ |
| 2534 | /* I2C passthru command */ |
| 2535 | |
| 2536 | #define EC_CMD_I2C_PASSTHRU 0x9e |
| 2537 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2538 | /* Read data; if not present, message is a write */ |
| 2539 | #define EC_I2C_FLAG_READ (1 << 15) |
| 2540 | |
| 2541 | /* Mask for address */ |
| 2542 | #define EC_I2C_ADDR_MASK 0x3ff |
| 2543 | |
| 2544 | #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */ |
| 2545 | #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */ |
| 2546 | |
| 2547 | /* Any error */ |
| 2548 | #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) |
| 2549 | |
| 2550 | struct ec_params_i2c_passthru_msg { |
| 2551 | uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */ |
| 2552 | uint16_t len; /* Number of bytes to read or write */ |
| 2553 | } __packed; |
| 2554 | |
| 2555 | struct ec_params_i2c_passthru { |
| 2556 | uint8_t port; /* I2C port number */ |
| 2557 | uint8_t num_msgs; /* Number of messages */ |
| 2558 | struct ec_params_i2c_passthru_msg msg[]; |
| 2559 | /* Data to write for all messages is concatenated here */ |
| 2560 | } __packed; |
| 2561 | |
| 2562 | struct ec_response_i2c_passthru { |
| 2563 | uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ |
| 2564 | uint8_t num_msgs; /* Number of messages processed */ |
| 2565 | uint8_t data[]; /* Data read by messages concatenated here */ |
| 2566 | } __packed; |
| 2567 | |
| 2568 | /*****************************************************************************/ |
| 2569 | /* Power button hang detect */ |
| 2570 | |
| 2571 | #define EC_CMD_HANG_DETECT 0x9f |
| 2572 | |
| 2573 | /* Reasons to start hang detection timer */ |
| 2574 | /* Power button pressed */ |
| 2575 | #define EC_HANG_START_ON_POWER_PRESS (1 << 0) |
| 2576 | |
| 2577 | /* Lid closed */ |
| 2578 | #define EC_HANG_START_ON_LID_CLOSE (1 << 1) |
| 2579 | |
| 2580 | /* Lid opened */ |
| 2581 | #define EC_HANG_START_ON_LID_OPEN (1 << 2) |
| 2582 | |
| 2583 | /* Start of AP S3->S0 transition (booting or resuming from suspend) */ |
| 2584 | #define EC_HANG_START_ON_RESUME (1 << 3) |
| 2585 | |
| 2586 | /* Reasons to cancel hang detection */ |
| 2587 | |
| 2588 | /* Power button released */ |
| 2589 | #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8) |
| 2590 | |
| 2591 | /* Any host command from AP received */ |
| 2592 | #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9) |
| 2593 | |
| 2594 | /* Stop on end of AP S0->S3 transition (suspending or shutting down) */ |
| 2595 | #define EC_HANG_STOP_ON_SUSPEND (1 << 10) |
| 2596 | |
| 2597 | /* |
| 2598 | * If this flag is set, all the other fields are ignored, and the hang detect |
| 2599 | * timer is started. This provides the AP a way to start the hang timer |
| 2600 | * without reconfiguring any of the other hang detect settings. Note that |
| 2601 | * you must previously have configured the timeouts. |
| 2602 | */ |
| 2603 | #define EC_HANG_START_NOW (1 << 30) |
| 2604 | |
| 2605 | /* |
| 2606 | * If this flag is set, all the other fields are ignored (including |
| 2607 | * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer |
| 2608 | * without reconfiguring any of the other hang detect settings. |
| 2609 | */ |
| 2610 | #define EC_HANG_STOP_NOW (1 << 31) |
| 2611 | |
| 2612 | struct ec_params_hang_detect { |
| 2613 | /* Flags; see EC_HANG_* */ |
| 2614 | uint32_t flags; |
| 2615 | |
| 2616 | /* Timeout in msec before generating host event, if enabled */ |
| 2617 | uint16_t host_event_timeout_msec; |
| 2618 | |
| 2619 | /* Timeout in msec before generating warm reboot, if enabled */ |
| 2620 | uint16_t warm_reboot_timeout_msec; |
| 2621 | } __packed; |
| 2622 | |
| 2623 | /*****************************************************************************/ |
| 2624 | /* Commands for battery charging */ |
| 2625 | |
| 2626 | /* |
| 2627 | * This is the single catch-all host command to exchange data regarding the |
| 2628 | * charge state machine (v2 and up). |
| 2629 | */ |
| 2630 | #define EC_CMD_CHARGE_STATE 0xa0 |
| 2631 | |
| 2632 | /* Subcommands for this host command */ |
| 2633 | enum charge_state_command { |
| 2634 | CHARGE_STATE_CMD_GET_STATE, |
| 2635 | CHARGE_STATE_CMD_GET_PARAM, |
| 2636 | CHARGE_STATE_CMD_SET_PARAM, |
| 2637 | CHARGE_STATE_NUM_CMDS |
| 2638 | }; |
| 2639 | |
| 2640 | /* |
| 2641 | * Known param numbers are defined here. Ranges are reserved for board-specific |
| 2642 | * params, which are handled by the particular implementations. |
| 2643 | */ |
| 2644 | enum charge_state_params { |
| 2645 | CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */ |
| 2646 | CS_PARAM_CHG_CURRENT, /* charger current limit */ |
| 2647 | CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ |
| 2648 | CS_PARAM_CHG_STATUS, /* charger-specific status */ |
| 2649 | CS_PARAM_CHG_OPTION, /* charger-specific options */ |
| 2650 | /* How many so far? */ |
| 2651 | CS_NUM_BASE_PARAMS, |
| 2652 | |
| 2653 | /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */ |
| 2654 | CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, |
| 2655 | CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, |
| 2656 | |
| 2657 | /* Other custom param ranges go here... */ |
| 2658 | }; |
| 2659 | |
| 2660 | struct ec_params_charge_state { |
| 2661 | uint8_t cmd; /* enum charge_state_command */ |
| 2662 | union { |
| 2663 | struct { |
| 2664 | /* no args */ |
| 2665 | } get_state; |
| 2666 | |
| 2667 | struct { |
| 2668 | uint32_t param; /* enum charge_state_param */ |
| 2669 | } get_param; |
| 2670 | |
| 2671 | struct { |
| 2672 | uint32_t param; /* param to set */ |
| 2673 | uint32_t value; /* value to set */ |
| 2674 | } set_param; |
| 2675 | }; |
| 2676 | } __packed; |
| 2677 | |
| 2678 | struct ec_response_charge_state { |
| 2679 | union { |
| 2680 | struct { |
| 2681 | int ac; |
| 2682 | int chg_voltage; |
| 2683 | int chg_current; |
| 2684 | int chg_input_current; |
| 2685 | int batt_state_of_charge; |
| 2686 | } get_state; |
| 2687 | |
| 2688 | struct { |
| 2689 | uint32_t value; |
| 2690 | } get_param; |
| 2691 | struct { |
| 2692 | /* no return values */ |
| 2693 | } set_param; |
| 2694 | }; |
| 2695 | } __packed; |
| 2696 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2697 | |
| 2698 | /* |
| 2699 | * Set maximum battery charging current. |
| 2700 | */ |
| 2701 | #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1 |
| 2702 | |
| 2703 | struct ec_params_current_limit { |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2704 | uint32_t limit; /* in mA */ |
| 2705 | } __packed; |
| 2706 | |
| 2707 | /* |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 2708 | * Set maximum external voltage / current. |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2709 | */ |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 2710 | #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2711 | |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 2712 | /* Command v0 is used only on Spring and is obsolete + unsupported */ |
| 2713 | struct ec_params_external_power_limit_v1 { |
| 2714 | uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ |
| 2715 | uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2716 | } __packed; |
| 2717 | |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 2718 | #define EC_POWER_LIMIT_NONE 0xffff |
| 2719 | |
Shawn Nematbakhsh | f00c06f | 2016-12-16 18:57:37 +0100 | [diff] [blame] | 2720 | /* Inform the EC when entering a sleep state */ |
| 2721 | #define EC_CMD_HOST_SLEEP_EVENT 0xa9 |
| 2722 | |
| 2723 | enum host_sleep_event { |
| 2724 | HOST_SLEEP_EVENT_S3_SUSPEND = 1, |
| 2725 | HOST_SLEEP_EVENT_S3_RESUME = 2, |
| 2726 | HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, |
| 2727 | HOST_SLEEP_EVENT_S0IX_RESUME = 4 |
| 2728 | }; |
| 2729 | |
| 2730 | struct ec_params_host_sleep_event { |
| 2731 | uint8_t sleep_event; |
| 2732 | } __packed; |
| 2733 | |
Evan Green | afe2bb5 | 2019-04-03 14:34:27 -0700 | [diff] [blame^] | 2734 | /* |
| 2735 | * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep |
| 2736 | * transition failures |
| 2737 | */ |
| 2738 | #define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0 |
| 2739 | |
| 2740 | /* Disable timeout detection for this sleep transition */ |
| 2741 | #define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF |
| 2742 | |
| 2743 | struct ec_params_host_sleep_event_v1 { |
| 2744 | /* The type of sleep being entered or exited. */ |
| 2745 | uint8_t sleep_event; |
| 2746 | |
| 2747 | /* Padding */ |
| 2748 | uint8_t reserved; |
| 2749 | union { |
| 2750 | /* Parameters that apply for suspend messages. */ |
| 2751 | struct { |
| 2752 | /* |
| 2753 | * The timeout in milliseconds between when this message |
| 2754 | * is received and when the EC will declare sleep |
| 2755 | * transition failure if the sleep signal is not |
| 2756 | * asserted. |
| 2757 | */ |
| 2758 | uint16_t sleep_timeout_ms; |
| 2759 | } suspend_params; |
| 2760 | |
| 2761 | /* No parameters for non-suspend messages. */ |
| 2762 | }; |
| 2763 | } __packed; |
| 2764 | |
| 2765 | /* A timeout occurred when this bit is set */ |
| 2766 | #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 |
| 2767 | |
| 2768 | /* |
| 2769 | * The mask defining which bits correspond to the number of sleep transitions, |
| 2770 | * as well as the maximum number of suspend line transitions that will be |
| 2771 | * reported back to the host. |
| 2772 | */ |
| 2773 | #define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF |
| 2774 | |
| 2775 | struct ec_response_host_sleep_event_v1 { |
| 2776 | union { |
| 2777 | /* Response fields that apply for resume messages. */ |
| 2778 | struct { |
| 2779 | /* |
| 2780 | * The number of sleep power signal transitions that |
| 2781 | * occurred since the suspend message. The high bit |
| 2782 | * indicates a timeout occurred. |
| 2783 | */ |
| 2784 | uint32_t sleep_transitions; |
| 2785 | } resume_response; |
| 2786 | |
| 2787 | /* No response fields for non-resume messages. */ |
| 2788 | }; |
| 2789 | } __packed; |
| 2790 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2791 | /*****************************************************************************/ |
| 2792 | /* Smart battery pass-through */ |
| 2793 | |
| 2794 | /* Get / Set 16-bit smart battery registers */ |
| 2795 | #define EC_CMD_SB_READ_WORD 0xb0 |
| 2796 | #define EC_CMD_SB_WRITE_WORD 0xb1 |
| 2797 | |
| 2798 | /* Get / Set string smart battery parameters |
| 2799 | * formatted as SMBUS "block". |
| 2800 | */ |
| 2801 | #define EC_CMD_SB_READ_BLOCK 0xb2 |
| 2802 | #define EC_CMD_SB_WRITE_BLOCK 0xb3 |
| 2803 | |
| 2804 | struct ec_params_sb_rd { |
| 2805 | uint8_t reg; |
| 2806 | } __packed; |
| 2807 | |
| 2808 | struct ec_response_sb_rd_word { |
| 2809 | uint16_t value; |
| 2810 | } __packed; |
| 2811 | |
| 2812 | struct ec_params_sb_wr_word { |
| 2813 | uint8_t reg; |
| 2814 | uint16_t value; |
| 2815 | } __packed; |
| 2816 | |
| 2817 | struct ec_response_sb_rd_block { |
| 2818 | uint8_t data[32]; |
| 2819 | } __packed; |
| 2820 | |
| 2821 | struct ec_params_sb_wr_block { |
| 2822 | uint8_t reg; |
| 2823 | uint16_t data[32]; |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2824 | } __packed; |
| 2825 | |
| 2826 | /*****************************************************************************/ |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 2827 | /* Battery vendor parameters |
| 2828 | * |
| 2829 | * Get or set vendor-specific parameters in the battery. Implementations may |
| 2830 | * differ between boards or batteries. On a set operation, the response |
| 2831 | * contains the actual value set, which may be rounded or clipped from the |
| 2832 | * requested value. |
| 2833 | */ |
| 2834 | |
| 2835 | #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4 |
| 2836 | |
| 2837 | enum ec_battery_vendor_param_mode { |
| 2838 | BATTERY_VENDOR_PARAM_MODE_GET = 0, |
| 2839 | BATTERY_VENDOR_PARAM_MODE_SET, |
| 2840 | }; |
| 2841 | |
| 2842 | struct ec_params_battery_vendor_param { |
| 2843 | uint32_t param; |
| 2844 | uint32_t value; |
| 2845 | uint8_t mode; |
| 2846 | } __packed; |
| 2847 | |
| 2848 | struct ec_response_battery_vendor_param { |
| 2849 | uint32_t value; |
| 2850 | } __packed; |
| 2851 | |
| 2852 | /*****************************************************************************/ |
Cheng-Yi Chiang | c1f3375 | 2018-12-18 17:06:26 +0800 | [diff] [blame] | 2853 | /* Commands for I2S recording on audio codec. */ |
| 2854 | |
| 2855 | #define EC_CMD_CODEC_I2S 0x00BC |
| 2856 | |
| 2857 | enum ec_codec_i2s_subcmd { |
| 2858 | EC_CODEC_SET_SAMPLE_DEPTH = 0x0, |
| 2859 | EC_CODEC_SET_GAIN = 0x1, |
| 2860 | EC_CODEC_GET_GAIN = 0x2, |
| 2861 | EC_CODEC_I2S_ENABLE = 0x3, |
| 2862 | EC_CODEC_I2S_SET_CONFIG = 0x4, |
| 2863 | EC_CODEC_I2S_SET_TDM_CONFIG = 0x5, |
| 2864 | EC_CODEC_I2S_SET_BCLK = 0x6, |
| 2865 | }; |
| 2866 | |
| 2867 | enum ec_sample_depth_value { |
| 2868 | EC_CODEC_SAMPLE_DEPTH_16 = 0, |
| 2869 | EC_CODEC_SAMPLE_DEPTH_24 = 1, |
| 2870 | }; |
| 2871 | |
| 2872 | enum ec_i2s_config { |
| 2873 | EC_DAI_FMT_I2S = 0, |
| 2874 | EC_DAI_FMT_RIGHT_J = 1, |
| 2875 | EC_DAI_FMT_LEFT_J = 2, |
| 2876 | EC_DAI_FMT_PCM_A = 3, |
| 2877 | EC_DAI_FMT_PCM_B = 4, |
| 2878 | EC_DAI_FMT_PCM_TDM = 5, |
| 2879 | }; |
| 2880 | |
| 2881 | struct ec_param_codec_i2s { |
| 2882 | /* |
| 2883 | * enum ec_codec_i2s_subcmd |
| 2884 | */ |
| 2885 | uint8_t cmd; |
| 2886 | union { |
| 2887 | /* |
| 2888 | * EC_CODEC_SET_SAMPLE_DEPTH |
| 2889 | * Value should be one of ec_sample_depth_value. |
| 2890 | */ |
| 2891 | uint8_t depth; |
| 2892 | |
| 2893 | /* |
| 2894 | * EC_CODEC_SET_GAIN |
| 2895 | * Value should be 0~43 for both channels. |
| 2896 | */ |
| 2897 | struct ec_param_codec_i2s_set_gain { |
| 2898 | uint8_t left; |
| 2899 | uint8_t right; |
| 2900 | } __packed gain; |
| 2901 | |
| 2902 | /* |
| 2903 | * EC_CODEC_I2S_ENABLE |
| 2904 | * 1 to enable, 0 to disable. |
| 2905 | */ |
| 2906 | uint8_t i2s_enable; |
| 2907 | |
| 2908 | /* |
| 2909 | * EC_CODEC_I2S_SET_COFNIG |
| 2910 | * Value should be one of ec_i2s_config. |
| 2911 | */ |
| 2912 | uint8_t i2s_config; |
| 2913 | |
| 2914 | /* |
| 2915 | * EC_CODEC_I2S_SET_TDM_CONFIG |
| 2916 | * Value should be one of ec_i2s_config. |
| 2917 | */ |
| 2918 | struct ec_param_codec_i2s_tdm { |
| 2919 | /* |
| 2920 | * 0 to 496 |
| 2921 | */ |
| 2922 | int16_t ch0_delay; |
| 2923 | /* |
| 2924 | * -1 to 496 |
| 2925 | */ |
| 2926 | int16_t ch1_delay; |
| 2927 | uint8_t adjacent_to_ch0; |
| 2928 | uint8_t adjacent_to_ch1; |
| 2929 | } __packed tdm_param; |
| 2930 | |
| 2931 | /* |
| 2932 | * EC_CODEC_I2S_SET_BCLK |
| 2933 | */ |
| 2934 | uint32_t bclk; |
| 2935 | }; |
| 2936 | } __packed; |
| 2937 | |
| 2938 | /* |
| 2939 | * For subcommand EC_CODEC_GET_GAIN. |
| 2940 | */ |
| 2941 | struct ec_response_codec_gain { |
| 2942 | uint8_t left; |
| 2943 | uint8_t right; |
| 2944 | } __packed; |
| 2945 | |
| 2946 | /*****************************************************************************/ |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2947 | /* System commands */ |
| 2948 | |
| 2949 | /* |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 2950 | * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't |
| 2951 | * necessarily reboot the EC. Rename to "image" or something similar? |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 2952 | */ |
| 2953 | #define EC_CMD_REBOOT_EC 0xd2 |
| 2954 | |
| 2955 | /* Command */ |
| 2956 | enum ec_reboot_cmd { |
| 2957 | EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ |
| 2958 | EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ |
| 2959 | EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */ |
| 2960 | /* (command 3 was jump to RW-B) */ |
| 2961 | EC_REBOOT_COLD = 4, /* Cold-reboot */ |
| 2962 | EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ |
| 2963 | EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */ |
| 2964 | }; |
| 2965 | |
| 2966 | /* Flags for ec_params_reboot_ec.reboot_flags */ |
| 2967 | #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */ |
| 2968 | #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */ |
| 2969 | |
| 2970 | struct ec_params_reboot_ec { |
| 2971 | uint8_t cmd; /* enum ec_reboot_cmd */ |
| 2972 | uint8_t flags; /* See EC_REBOOT_FLAG_* */ |
| 2973 | } __packed; |
| 2974 | |
| 2975 | /* |
| 2976 | * Get information on last EC panic. |
| 2977 | * |
| 2978 | * Returns variable-length platform-dependent panic information. See panic.h |
| 2979 | * for details. |
| 2980 | */ |
| 2981 | #define EC_CMD_GET_PANIC_INFO 0xd3 |
| 2982 | |
| 2983 | /*****************************************************************************/ |
| 2984 | /* |
| 2985 | * ACPI commands |
| 2986 | * |
| 2987 | * These are valid ONLY on the ACPI command/data port. |
| 2988 | */ |
| 2989 | |
| 2990 | /* |
| 2991 | * ACPI Read Embedded Controller |
| 2992 | * |
| 2993 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 2994 | * |
| 2995 | * Use the following sequence: |
| 2996 | * |
| 2997 | * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD |
| 2998 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 2999 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 3000 | * - Wait for EC_LPC_CMDR_DATA bit to set |
| 3001 | * - Read value from EC_LPC_ADDR_ACPI_DATA |
| 3002 | */ |
| 3003 | #define EC_CMD_ACPI_READ 0x80 |
| 3004 | |
| 3005 | /* |
| 3006 | * ACPI Write Embedded Controller |
| 3007 | * |
| 3008 | * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*). |
| 3009 | * |
| 3010 | * Use the following sequence: |
| 3011 | * |
| 3012 | * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD |
| 3013 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 3014 | * - Write address to EC_LPC_ADDR_ACPI_DATA |
| 3015 | * - Wait for EC_LPC_CMDR_PENDING bit to clear |
| 3016 | * - Write value to EC_LPC_ADDR_ACPI_DATA |
| 3017 | */ |
| 3018 | #define EC_CMD_ACPI_WRITE 0x81 |
| 3019 | |
| 3020 | /* |
| 3021 | * ACPI Query Embedded Controller |
| 3022 | * |
| 3023 | * This clears the lowest-order bit in the currently pending host events, and |
| 3024 | * sets the result code to the 1-based index of the bit (event 0x00000001 = 1, |
| 3025 | * event 0x80000000 = 32), or 0 if no event was pending. |
| 3026 | */ |
| 3027 | #define EC_CMD_ACPI_QUERY_EVENT 0x84 |
| 3028 | |
| 3029 | /* Valid addresses in ACPI memory space, for read/write commands */ |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 3030 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 3031 | /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ |
| 3032 | #define EC_ACPI_MEM_VERSION 0x00 |
| 3033 | /* |
| 3034 | * Test location; writing value here updates test compliment byte to (0xff - |
| 3035 | * value). |
| 3036 | */ |
| 3037 | #define EC_ACPI_MEM_TEST 0x01 |
| 3038 | /* Test compliment; writes here are ignored. */ |
| 3039 | #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 3040 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 3041 | /* Keyboard backlight brightness percent (0 - 100) */ |
| 3042 | #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 3043 | /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */ |
| 3044 | #define EC_ACPI_MEM_FAN_DUTY 0x04 |
| 3045 | |
| 3046 | /* |
| 3047 | * DPTF temp thresholds. Any of the EC's temp sensors can have up to two |
| 3048 | * independent thresholds attached to them. The current value of the ID |
| 3049 | * register determines which sensor is affected by the THRESHOLD and COMMIT |
| 3050 | * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme |
| 3051 | * as the memory-mapped sensors. The COMMIT register applies those settings. |
| 3052 | * |
| 3053 | * The spec does not mandate any way to read back the threshold settings |
| 3054 | * themselves, but when a threshold is crossed the AP needs a way to determine |
| 3055 | * which sensor(s) are responsible. Each reading of the ID register clears and |
| 3056 | * returns one sensor ID that has crossed one of its threshold (in either |
| 3057 | * direction) since the last read. A value of 0xFF means "no new thresholds |
| 3058 | * have tripped". Setting or enabling the thresholds for a sensor will clear |
| 3059 | * the unread event count for that sensor. |
| 3060 | */ |
| 3061 | #define EC_ACPI_MEM_TEMP_ID 0x05 |
| 3062 | #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06 |
| 3063 | #define EC_ACPI_MEM_TEMP_COMMIT 0x07 |
| 3064 | /* |
| 3065 | * Here are the bits for the COMMIT register: |
| 3066 | * bit 0 selects the threshold index for the chosen sensor (0/1) |
| 3067 | * bit 1 enables/disables the selected threshold (0 = off, 1 = on) |
| 3068 | * Each write to the commit register affects one threshold. |
| 3069 | */ |
| 3070 | #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0) |
| 3071 | #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1) |
| 3072 | /* |
| 3073 | * Example: |
| 3074 | * |
| 3075 | * Set the thresholds for sensor 2 to 50 C and 60 C: |
| 3076 | * write 2 to [0x05] -- select temp sensor 2 |
| 3077 | * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET |
| 3078 | * write 0x2 to [0x07] -- enable threshold 0 with this value |
| 3079 | * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET |
| 3080 | * write 0x3 to [0x07] -- enable threshold 1 with this value |
| 3081 | * |
| 3082 | * Disable the 60 C threshold, leaving the 50 C threshold unchanged: |
| 3083 | * write 2 to [0x05] -- select temp sensor 2 |
| 3084 | * write 0x1 to [0x07] -- disable threshold 1 |
| 3085 | */ |
| 3086 | |
| 3087 | /* DPTF battery charging current limit */ |
| 3088 | #define EC_ACPI_MEM_CHARGING_LIMIT 0x08 |
| 3089 | |
| 3090 | /* Charging limit is specified in 64 mA steps */ |
| 3091 | #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64 |
| 3092 | /* Value to disable DPTF battery charging limit */ |
| 3093 | #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 3094 | |
| 3095 | /* Current version of ACPI memory address space */ |
| 3096 | #define EC_ACPI_MEM_VERSION_CURRENT 1 |
| 3097 | |
| 3098 | |
| 3099 | /*****************************************************************************/ |
| 3100 | /* |
Neil Armstrong | f47674e | 2018-07-04 17:08:19 +0200 | [diff] [blame] | 3101 | * HDMI CEC commands |
| 3102 | * |
| 3103 | * These commands are for sending and receiving message via HDMI CEC |
| 3104 | */ |
| 3105 | #define EC_MAX_CEC_MSG_LEN 16 |
| 3106 | |
| 3107 | /* CEC message from the AP to be written on the CEC bus */ |
| 3108 | #define EC_CMD_CEC_WRITE_MSG 0x00B8 |
| 3109 | |
| 3110 | /** |
| 3111 | * struct ec_params_cec_write - Message to write to the CEC bus |
| 3112 | * @msg: message content to write to the CEC bus |
| 3113 | */ |
| 3114 | struct ec_params_cec_write { |
| 3115 | uint8_t msg[EC_MAX_CEC_MSG_LEN]; |
| 3116 | } __packed; |
| 3117 | |
| 3118 | /* Set various CEC parameters */ |
| 3119 | #define EC_CMD_CEC_SET 0x00BA |
| 3120 | |
| 3121 | /** |
| 3122 | * struct ec_params_cec_set - CEC parameters set |
| 3123 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 3124 | * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC |
| 3125 | * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS, |
| 3126 | * this field encodes the requested logical address between 0 and 15 |
| 3127 | * or 0xff to unregister |
| 3128 | */ |
| 3129 | struct ec_params_cec_set { |
| 3130 | uint8_t cmd; /* enum cec_command */ |
| 3131 | uint8_t val; |
| 3132 | } __packed; |
| 3133 | |
| 3134 | /* Read various CEC parameters */ |
| 3135 | #define EC_CMD_CEC_GET 0x00BB |
| 3136 | |
| 3137 | /** |
| 3138 | * struct ec_params_cec_get - CEC parameters get |
| 3139 | * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS |
| 3140 | */ |
| 3141 | struct ec_params_cec_get { |
| 3142 | uint8_t cmd; /* enum cec_command */ |
| 3143 | } __packed; |
| 3144 | |
| 3145 | /** |
| 3146 | * struct ec_response_cec_get - CEC parameters get response |
| 3147 | * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is |
| 3148 | * disabled or 1 if CEC functionality is enabled, |
| 3149 | * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the |
| 3150 | * configured logical address between 0 and 15 or 0xff if unregistered |
| 3151 | */ |
| 3152 | struct ec_response_cec_get { |
| 3153 | uint8_t val; |
| 3154 | } __packed; |
| 3155 | |
| 3156 | /* CEC parameters command */ |
| 3157 | enum ec_cec_command { |
| 3158 | /* CEC reading, writing and events enable */ |
| 3159 | CEC_CMD_ENABLE, |
| 3160 | /* CEC logical address */ |
| 3161 | CEC_CMD_LOGICAL_ADDRESS, |
| 3162 | }; |
| 3163 | |
| 3164 | /* Events from CEC to AP */ |
| 3165 | enum mkbp_cec_event { |
| 3166 | /* Outgoing message was acknowledged by a follower */ |
| 3167 | EC_MKBP_CEC_SEND_OK = BIT(0), |
| 3168 | /* Outgoing message was not acknowledged */ |
| 3169 | EC_MKBP_CEC_SEND_FAILED = BIT(1), |
| 3170 | }; |
| 3171 | |
| 3172 | /*****************************************************************************/ |
| 3173 | /* |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 3174 | * Special commands |
| 3175 | * |
| 3176 | * These do not follow the normal rules for commands. See each command for |
| 3177 | * details. |
| 3178 | */ |
| 3179 | |
| 3180 | /* |
| 3181 | * Reboot NOW |
| 3182 | * |
| 3183 | * This command will work even when the EC LPC interface is busy, because the |
| 3184 | * reboot command is processed at interrupt level. Note that when the EC |
| 3185 | * reboots, the host will reboot too, so there is no response to this command. |
| 3186 | * |
| 3187 | * Use EC_CMD_REBOOT_EC to reboot the EC more politely. |
| 3188 | */ |
| 3189 | #define EC_CMD_REBOOT 0xd1 /* Think "die" */ |
| 3190 | |
| 3191 | /* |
| 3192 | * Resend last response (not supported on LPC). |
| 3193 | * |
| 3194 | * Returns EC_RES_UNAVAILABLE if there is no response available - for example, |
| 3195 | * there was no previous command, or the previous command's response was too |
| 3196 | * big to save. |
| 3197 | */ |
| 3198 | #define EC_CMD_RESEND_RESPONSE 0xdb |
| 3199 | |
| 3200 | /* |
| 3201 | * This header byte on a command indicate version 0. Any header byte less |
| 3202 | * than this means that we are talking to an old EC which doesn't support |
| 3203 | * versioning. In that case, we assume version 0. |
| 3204 | * |
| 3205 | * Header bytes greater than this indicate a later version. For example, |
| 3206 | * EC_CMD_VERSION0 + 1 means we are using version 1. |
| 3207 | * |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 3208 | * The old EC interface must not use commands 0xdc or higher. |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 3209 | */ |
| 3210 | #define EC_CMD_VERSION0 0xdc |
| 3211 | |
| 3212 | #endif /* !__ACPI__ */ |
| 3213 | |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 3214 | /*****************************************************************************/ |
| 3215 | /* |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 3216 | * PD commands |
| 3217 | * |
| 3218 | * These commands are for PD MCU communication. |
| 3219 | */ |
| 3220 | |
| 3221 | /* EC to PD MCU exchange status command */ |
| 3222 | #define EC_CMD_PD_EXCHANGE_STATUS 0x100 |
| 3223 | |
| 3224 | /* Status of EC being sent to PD */ |
| 3225 | struct ec_params_pd_status { |
| 3226 | int8_t batt_soc; /* battery state of charge */ |
| 3227 | } __packed; |
| 3228 | |
| 3229 | /* Status of PD being sent back to EC */ |
| 3230 | struct ec_response_pd_status { |
| 3231 | int8_t status; /* PD MCU status */ |
| 3232 | uint32_t curr_lim_ma; /* input current limit */ |
| 3233 | } __packed; |
| 3234 | |
| 3235 | /* Set USB type-C port role and muxes */ |
| 3236 | #define EC_CMD_USB_PD_CONTROL 0x101 |
| 3237 | |
| 3238 | enum usb_pd_control_role { |
| 3239 | USB_PD_CTRL_ROLE_NO_CHANGE = 0, |
| 3240 | USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */ |
| 3241 | USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, |
| 3242 | USB_PD_CTRL_ROLE_FORCE_SINK = 3, |
| 3243 | USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, |
| 3244 | }; |
| 3245 | |
| 3246 | enum usb_pd_control_mux { |
| 3247 | USB_PD_CTRL_MUX_NO_CHANGE = 0, |
| 3248 | USB_PD_CTRL_MUX_NONE = 1, |
| 3249 | USB_PD_CTRL_MUX_USB = 2, |
| 3250 | USB_PD_CTRL_MUX_DP = 3, |
| 3251 | USB_PD_CTRL_MUX_DOCK = 4, |
| 3252 | USB_PD_CTRL_MUX_AUTO = 5, |
| 3253 | }; |
| 3254 | |
Benson Leung | c7eb47f | 2017-12-13 11:32:15 +0100 | [diff] [blame] | 3255 | enum usb_pd_control_swap { |
| 3256 | USB_PD_CTRL_SWAP_NONE = 0, |
| 3257 | USB_PD_CTRL_SWAP_DATA = 1, |
| 3258 | USB_PD_CTRL_SWAP_POWER = 2, |
| 3259 | USB_PD_CTRL_SWAP_VCONN = 3, |
| 3260 | USB_PD_CTRL_SWAP_COUNT |
| 3261 | }; |
| 3262 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 3263 | struct ec_params_usb_pd_control { |
| 3264 | uint8_t port; |
| 3265 | uint8_t role; |
| 3266 | uint8_t mux; |
Benson Leung | c7eb47f | 2017-12-13 11:32:15 +0100 | [diff] [blame] | 3267 | uint8_t swap; |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 3268 | } __packed; |
| 3269 | |
Benson Leung | c698316 | 2017-07-17 11:41:39 +0200 | [diff] [blame] | 3270 | #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */ |
| 3271 | #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */ |
| 3272 | #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */ |
| 3273 | |
Benson Leung | c7eb47f | 2017-12-13 11:32:15 +0100 | [diff] [blame] | 3274 | #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ |
| 3275 | #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ |
| 3276 | #define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */ |
| 3277 | #define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */ |
| 3278 | #define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */ |
| 3279 | #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ |
| 3280 | #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */ |
| 3281 | |
Benson Leung | c698316 | 2017-07-17 11:41:39 +0200 | [diff] [blame] | 3282 | struct ec_response_usb_pd_control_v1 { |
| 3283 | uint8_t enabled; |
| 3284 | uint8_t role; |
| 3285 | uint8_t polarity; |
| 3286 | char state[32]; |
| 3287 | } __packed; |
| 3288 | |
| 3289 | #define EC_CMD_USB_PD_PORTS 0x102 |
| 3290 | |
Shawn Nematbakhsh | b082b2e | 2018-03-23 18:42:46 +0100 | [diff] [blame] | 3291 | /* Maximum number of PD ports on a device, num_ports will be <= this */ |
| 3292 | #define EC_USB_PD_MAX_PORTS 8 |
| 3293 | |
Benson Leung | c698316 | 2017-07-17 11:41:39 +0200 | [diff] [blame] | 3294 | struct ec_response_usb_pd_ports { |
| 3295 | uint8_t num_ports; |
| 3296 | } __packed; |
| 3297 | |
| 3298 | #define EC_CMD_USB_PD_POWER_INFO 0x103 |
| 3299 | |
| 3300 | #define PD_POWER_CHARGING_PORT 0xff |
| 3301 | struct ec_params_usb_pd_power_info { |
| 3302 | uint8_t port; |
| 3303 | } __packed; |
| 3304 | |
| 3305 | enum usb_chg_type { |
| 3306 | USB_CHG_TYPE_NONE, |
| 3307 | USB_CHG_TYPE_PD, |
| 3308 | USB_CHG_TYPE_C, |
| 3309 | USB_CHG_TYPE_PROPRIETARY, |
| 3310 | USB_CHG_TYPE_BC12_DCP, |
| 3311 | USB_CHG_TYPE_BC12_CDP, |
| 3312 | USB_CHG_TYPE_BC12_SDP, |
| 3313 | USB_CHG_TYPE_OTHER, |
| 3314 | USB_CHG_TYPE_VBUS, |
| 3315 | USB_CHG_TYPE_UNKNOWN, |
| 3316 | }; |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 3317 | enum usb_power_roles { |
| 3318 | USB_PD_PORT_POWER_DISCONNECTED, |
| 3319 | USB_PD_PORT_POWER_SOURCE, |
| 3320 | USB_PD_PORT_POWER_SINK, |
| 3321 | USB_PD_PORT_POWER_SINK_NOT_CHARGING, |
| 3322 | }; |
Benson Leung | c698316 | 2017-07-17 11:41:39 +0200 | [diff] [blame] | 3323 | |
| 3324 | struct usb_chg_measures { |
| 3325 | uint16_t voltage_max; |
| 3326 | uint16_t voltage_now; |
| 3327 | uint16_t current_max; |
| 3328 | uint16_t current_lim; |
| 3329 | } __packed; |
| 3330 | |
| 3331 | struct ec_response_usb_pd_power_info { |
| 3332 | uint8_t role; |
| 3333 | uint8_t type; |
| 3334 | uint8_t dualrole; |
| 3335 | uint8_t reserved1; |
| 3336 | struct usb_chg_measures meas; |
| 3337 | uint32_t max_power; |
| 3338 | } __packed; |
| 3339 | |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 3340 | struct ec_params_usb_pd_info_request { |
| 3341 | uint8_t port; |
| 3342 | } __packed; |
| 3343 | |
Fabien Parent | 36f4738 | 2018-08-10 15:13:47 +0200 | [diff] [blame] | 3344 | /* |
| 3345 | * This command will return the number of USB PD charge port + the number |
| 3346 | * of dedicated port present. |
| 3347 | * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports |
| 3348 | */ |
| 3349 | #define EC_CMD_CHARGE_PORT_COUNT 0x0105 |
| 3350 | struct ec_response_charge_port_count { |
| 3351 | uint8_t port_count; |
| 3352 | } __packed; |
| 3353 | |
Sameer Nanda | 0663589 | 2018-05-02 17:44:16 +0200 | [diff] [blame] | 3354 | /* Read USB-PD Device discovery info */ |
| 3355 | #define EC_CMD_USB_PD_DISCOVERY 0x0113 |
| 3356 | struct ec_params_usb_pd_discovery_entry { |
| 3357 | uint16_t vid; /* USB-IF VID */ |
| 3358 | uint16_t pid; /* USB-IF PID */ |
| 3359 | uint8_t ptype; /* product type (hub,periph,cable,ama) */ |
| 3360 | } __packed; |
| 3361 | |
| 3362 | /* Override default charge behavior */ |
| 3363 | #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 |
| 3364 | |
| 3365 | /* Negative port parameters have special meaning */ |
| 3366 | enum usb_pd_override_ports { |
| 3367 | OVERRIDE_DONT_CHARGE = -2, |
| 3368 | OVERRIDE_OFF = -1, |
| 3369 | /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */ |
| 3370 | }; |
| 3371 | |
| 3372 | struct ec_params_charge_port_override { |
| 3373 | int16_t override_port; /* Override port# */ |
| 3374 | } __packed; |
| 3375 | |
| 3376 | /* Read (and delete) one entry of PD event log */ |
| 3377 | #define EC_CMD_PD_GET_LOG_ENTRY 0x0115 |
| 3378 | |
| 3379 | struct ec_response_pd_log { |
| 3380 | uint32_t timestamp; /* relative timestamp in milliseconds */ |
| 3381 | uint8_t type; /* event type : see PD_EVENT_xx below */ |
| 3382 | uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ |
| 3383 | uint16_t data; /* type-defined data payload */ |
| 3384 | uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ |
| 3385 | } __packed; |
| 3386 | |
| 3387 | /* The timestamp is the microsecond counter shifted to get about a ms. */ |
| 3388 | #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ |
| 3389 | |
| 3390 | #define PD_LOG_SIZE_MASK 0x1f |
| 3391 | #define PD_LOG_PORT_MASK 0xe0 |
| 3392 | #define PD_LOG_PORT_SHIFT 5 |
| 3393 | #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \ |
| 3394 | ((size) & PD_LOG_SIZE_MASK)) |
| 3395 | #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT) |
| 3396 | #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK) |
| 3397 | |
| 3398 | /* PD event log : entry types */ |
| 3399 | /* PD MCU events */ |
| 3400 | #define PD_EVENT_MCU_BASE 0x00 |
| 3401 | #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0) |
| 3402 | #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1) |
| 3403 | /* Reserved for custom board event */ |
| 3404 | #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2) |
| 3405 | /* PD generic accessory events */ |
| 3406 | #define PD_EVENT_ACC_BASE 0x20 |
| 3407 | #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0) |
| 3408 | #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1) |
| 3409 | /* PD power supply events */ |
| 3410 | #define PD_EVENT_PS_BASE 0x40 |
| 3411 | #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0) |
| 3412 | /* PD video dongles events */ |
| 3413 | #define PD_EVENT_VIDEO_BASE 0x60 |
| 3414 | #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0) |
| 3415 | #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1) |
| 3416 | /* Returned in the "type" field, when there is no entry available */ |
| 3417 | #define PD_EVENT_NO_ENTRY 0xff |
| 3418 | |
| 3419 | /* |
| 3420 | * PD_EVENT_MCU_CHARGE event definition : |
| 3421 | * the payload is "struct usb_chg_measures" |
| 3422 | * the data field contains the port state flags as defined below : |
| 3423 | */ |
| 3424 | /* Port partner is a dual role device */ |
| 3425 | #define CHARGE_FLAGS_DUAL_ROLE BIT(15) |
| 3426 | /* Port is the pending override port */ |
| 3427 | #define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14) |
| 3428 | /* Port is the override port */ |
| 3429 | #define CHARGE_FLAGS_OVERRIDE BIT(13) |
| 3430 | /* Charger type */ |
| 3431 | #define CHARGE_FLAGS_TYPE_SHIFT 3 |
| 3432 | #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT) |
| 3433 | /* Power delivery role */ |
| 3434 | #define CHARGE_FLAGS_ROLE_MASK (7 << 0) |
| 3435 | |
| 3436 | /* |
| 3437 | * PD_EVENT_PS_FAULT data field flags definition : |
| 3438 | */ |
| 3439 | #define PS_FAULT_OCP 1 |
| 3440 | #define PS_FAULT_FAST_OCP 2 |
| 3441 | #define PS_FAULT_OVP 3 |
| 3442 | #define PS_FAULT_DISCH 4 |
| 3443 | |
| 3444 | /* |
| 3445 | * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info". |
| 3446 | */ |
| 3447 | struct mcdp_version { |
| 3448 | uint8_t major; |
| 3449 | uint8_t minor; |
| 3450 | uint16_t build; |
| 3451 | } __packed; |
| 3452 | |
| 3453 | struct mcdp_info { |
| 3454 | uint8_t family[2]; |
| 3455 | uint8_t chipid[2]; |
| 3456 | struct mcdp_version irom; |
| 3457 | struct mcdp_version fw; |
| 3458 | } __packed; |
| 3459 | |
| 3460 | /* struct mcdp_info field decoding */ |
| 3461 | #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) |
| 3462 | #define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) |
| 3463 | |
Benson Leung | c698316 | 2017-07-17 11:41:39 +0200 | [diff] [blame] | 3464 | /* Get info about USB-C SS muxes */ |
| 3465 | #define EC_CMD_USB_PD_MUX_INFO 0x11a |
| 3466 | |
| 3467 | struct ec_params_usb_pd_mux_info { |
| 3468 | uint8_t port; /* USB-C port number */ |
| 3469 | } __packed; |
| 3470 | |
| 3471 | /* Flags representing mux state */ |
| 3472 | #define USB_PD_MUX_USB_ENABLED (1 << 0) |
| 3473 | #define USB_PD_MUX_DP_ENABLED (1 << 1) |
| 3474 | #define USB_PD_MUX_POLARITY_INVERTED (1 << 2) |
| 3475 | #define USB_PD_MUX_HPD_IRQ (1 << 3) |
| 3476 | |
| 3477 | struct ec_response_usb_pd_mux_info { |
| 3478 | uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ |
| 3479 | } __packed; |
| 3480 | |
Stephen Barber | 256ab95 | 2015-06-09 13:04:43 +0200 | [diff] [blame] | 3481 | /*****************************************************************************/ |
| 3482 | /* |
| 3483 | * Passthru commands |
| 3484 | * |
| 3485 | * Some platforms have sub-processors chained to each other. For example. |
| 3486 | * |
| 3487 | * AP <--> EC <--> PD MCU |
| 3488 | * |
| 3489 | * The top 2 bits of the command number are used to indicate which device the |
| 3490 | * command is intended for. Device 0 is always the device receiving the |
| 3491 | * command; other device mapping is board-specific. |
| 3492 | * |
| 3493 | * When a device receives a command to be passed to a sub-processor, it passes |
| 3494 | * it on with the device number set back to 0. This allows the sub-processor |
| 3495 | * to remain blissfully unaware of whether the command originated on the next |
| 3496 | * device up the chain, or was passed through from the AP. |
| 3497 | * |
| 3498 | * In the above example, if the AP wants to send command 0x0002 to the PD MCU, |
| 3499 | * AP sends command 0x4002 to the EC |
| 3500 | * EC sends command 0x0002 to the PD MCU |
| 3501 | * EC forwards PD MCU response back to the AP |
| 3502 | */ |
| 3503 | |
| 3504 | /* Offset and max command number for sub-device n */ |
| 3505 | #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n)) |
| 3506 | #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff) |
| 3507 | |
| 3508 | /*****************************************************************************/ |
| 3509 | /* |
Bill Richardson | 5271db2 | 2014-04-30 10:44:08 -0700 | [diff] [blame] | 3510 | * Deprecated constants. These constants have been renamed for clarity. The |
| 3511 | * meaning and size has not changed. Programs that use the old names should |
| 3512 | * switch to the new names soon, as the old names may not be carried forward |
| 3513 | * forever. |
| 3514 | */ |
| 3515 | #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE |
| 3516 | #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 |
| 3517 | #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE |
| 3518 | |
Simon Glass | deaf39e | 2013-02-25 14:08:36 -0800 | [diff] [blame] | 3519 | #endif /* __CROS_EC_COMMANDS_H */ |