blob: 39e1cec65d9f96107bc42bed6b7a8b49dbdf9123 [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001/* SPDX-License-Identifier: BSD-3-Clause */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002
3/* Host communication command constants for Chrome EC */
4
Duncan Laurieeb316852015-12-01 18:51:18 -08005#ifndef __CROS_EC_EC_COMMANDS_H
6#define __CROS_EC_EC_COMMANDS_H
Stefan Reinauerd6682e82013-02-21 15:39:35 -08007
Patrick Georgi0f6187a2017-07-28 15:57:23 +02008#if !defined(__ACPI__) && !defined(__KERNEL__)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07009#include <stdint.h>
10#endif
11
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080012#ifdef __cplusplus
13extern "C" {
14#endif
15
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070016#ifdef CHROMIUM_EC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080017/*
18 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
19 * It is used to not include macros that may cause conflicts in foreign
20 * projects (refer to crbug.com/984623).
21 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070022
Duncan Laurie67f26cc2017-06-29 23:17:22 -070023/*
24 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
25 * generates more efficient code for accessing request/response structures on
26 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
27 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -070028#include "common.h"
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080029#include "compile_time_macros.h"
30
31#else
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080032/* If BUILD_ASSERT isn't already defined, make it a no-op */
33#ifndef BUILD_ASSERT
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080034#define BUILD_ASSERT(_cond)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080035#endif /* !BUILD_ASSERT */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070036#endif /* CHROMIUM_EC */
37
38#ifdef __KERNEL__
39#include <linux/limits.h>
40#else
41/*
42 * Defines macros that may be needed but are for sure defined by the linux
43 * kernel. This section is removed when cros_ec_commands.h is generated (by
44 * util/make_linux_ec_commands_h.sh).
45 * cros_ec_commands.h looks more integrated to the kernel.
46 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080047
48#ifndef BIT
49#define BIT(nr) (1UL << (nr))
Duncan Laurie67f26cc2017-06-29 23:17:22 -070050#endif
51
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080052#ifndef BIT_ULL
53#define BIT_ULL(nr) (1ULL << (nr))
54#endif
55
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080056/*
57 * When building Zephyr, this file ends up being included before Zephyr's
58 * include/sys/util.h so causes a warning there. We don't want to add an #ifdef
59 * in that file since it won't be accepted upstream. So work around it here.
60 */
61#ifndef CONFIG_ZEPHYR
62#ifndef GENMASK
63#define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1))
64#endif
65
66#ifndef GENMASK_ULL
67#define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1))
68#endif
69#endif
70
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070071#endif /* __KERNEL__ */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080072
Stefan Reinauerd6682e82013-02-21 15:39:35 -080073/*
Duncan Laurie93e24442014-01-06 12:30:52 -080074 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080075 *
Duncan Laurie93e24442014-01-06 12:30:52 -080076 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
77 * determined in other ways. Remove this once the kernel code no longer
78 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080079 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080080#define EC_PROTO_VERSION 0x00000002
81
82/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080083#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -080084
85/* I/O addresses for ACPI commands */
86#define EC_LPC_ADDR_ACPI_DATA 0x62
87#define EC_LPC_ADDR_ACPI_CMD 0x66
88
89/* I/O addresses for host command */
90#define EC_LPC_ADDR_HOST_DATA 0x200
91#define EC_LPC_ADDR_HOST_CMD 0x204
92
93/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080094/* Protocol version 2 */
95#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
96#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080097 * EC_PROTO2_MAX_PARAM_SIZE
98 */
Duncan Laurie93e24442014-01-06 12:30:52 -080099/* Protocol version 3 */
100#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
101#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800102
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800103/*
104 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
105 * and they tell the kernel that so we have to think of it as two parts.
106 */
Bill Richardsone221aad2013-06-12 10:50:41 -0700107#define EC_HOST_CMD_REGION0 0x800
108#define EC_HOST_CMD_REGION1 0x880
109#define EC_HOST_CMD_REGION_SIZE 0x80
110
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800111/* EC command register bit functions */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800112#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
113#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
114#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
115#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
116#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
117#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
118#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800119
120#define EC_LPC_ADDR_MEMMAP 0x900
121#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
122#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
123
124/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700125#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
126#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
127#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
128#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800129#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
130#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
131#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
132#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
133#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700134#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
135/* Unused 0x28 - 0x2f */
136#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
137/* Unused 0x31 - 0x33 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600138#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
139/* Battery values are all 32 bits, unless otherwise noted. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800140#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
141#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
142#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600143#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
144#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
145#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
146/* Unused 0x4f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800147#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
148#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
149#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
150#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700151/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800152#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
153#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
154#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
155#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700156#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
157/* Unused 0x84 - 0x8f */
158#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
159/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800160#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
161/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
162/* 0x94 - 0x99: 1st Accelerometer */
163/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700164#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700165/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700166
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700167/*
168 * ACPI is unable to access memory mapped data at or above this offset due to
169 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
170 * which might be needed by ACPI.
171 */
172#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700173
174/* Define the format of the accelerometer mapped memory status byte. */
175#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800176#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
177#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800178
179/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
180#define EC_TEMP_SENSOR_ENTRIES 16
181/*
182 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
183 *
184 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
185 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700186#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800187
188/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700189#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
190#define EC_TEMP_SENSOR_ERROR 0xfe
191#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
192#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800193/*
194 * The offset of temperature value stored in mapped memory. This allows
195 * reporting a temperature range of 200K to 454K = -73C to 181C.
196 */
197#define EC_TEMP_SENSOR_OFFSET 200
198
Duncan Laurie93e24442014-01-06 12:30:52 -0800199/*
200 * Number of ALS readings at EC_MEMMAP_ALS
201 */
202#define EC_ALS_ENTRIES 2
203
204/*
205 * The default value a temperature sensor will return when it is present but
206 * has not been read this boot. This is a reasonable number to avoid
207 * triggering alarms on the host.
208 */
209#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
210
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800211#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
212#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
213#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
214
215/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
216#define EC_BATT_FLAG_AC_PRESENT 0x01
217#define EC_BATT_FLAG_BATT_PRESENT 0x02
218#define EC_BATT_FLAG_DISCHARGING 0x04
219#define EC_BATT_FLAG_CHARGING 0x08
220#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600221/* Set if some of the static/dynamic data is invalid (or outdated). */
222#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800223
224/* Switch flags at EC_MEMMAP_SWITCHES */
225#define EC_SWITCH_LID_OPEN 0x01
226#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
227#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700228/* Was recovery requested via keyboard; now unused. */
229#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800230/* Recovery requested via dedicated signal (from servo board) */
231#define EC_SWITCH_DEDICATED_RECOVERY 0x10
232/* Was fake developer mode switch; now unused. Remove in next refactor. */
233#define EC_SWITCH_IGNORE0 0x20
234
235/* Host command interface flags */
236/* Host command interface supports LPC args (LPC interface only) */
237#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800238/* Host command interface supports version 3 protocol */
239#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800240
241/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800242#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
243#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
244#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
245#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
246#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800247
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700248/*****************************************************************************/
249/*
250 * ACPI commands
251 *
252 * These are valid ONLY on the ACPI command/data port.
253 */
254
255/*
256 * ACPI Read Embedded Controller
257 *
258 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
259 *
260 * Use the following sequence:
261 *
262 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
263 * - Wait for EC_LPC_CMDR_PENDING bit to clear
264 * - Write address to EC_LPC_ADDR_ACPI_DATA
265 * - Wait for EC_LPC_CMDR_DATA bit to set
266 * - Read value from EC_LPC_ADDR_ACPI_DATA
267 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700268#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700269
270/*
271 * ACPI Write Embedded Controller
272 *
273 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
274 *
275 * Use the following sequence:
276 *
277 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
278 * - Wait for EC_LPC_CMDR_PENDING bit to clear
279 * - Write address to EC_LPC_ADDR_ACPI_DATA
280 * - Wait for EC_LPC_CMDR_PENDING bit to clear
281 * - Write value to EC_LPC_ADDR_ACPI_DATA
282 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700283#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700284
285/*
286 * ACPI Burst Enable Embedded Controller
287 *
288 * This enables burst mode on the EC to allow the host to issue several
289 * commands back-to-back. While in this mode, writes to mapped multi-byte
290 * data are locked out to ensure data consistency.
291 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700292#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700293
294/*
295 * ACPI Burst Disable Embedded Controller
296 *
297 * This disables burst mode on the EC and stops preventing EC writes to mapped
298 * multi-byte data.
299 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700300#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700301
302/*
303 * ACPI Query Embedded Controller
304 *
305 * This clears the lowest-order bit in the currently pending host events, and
306 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
307 * event 0x80000000 = 32), or 0 if no event was pending.
308 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700309#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700310
311/* Valid addresses in ACPI memory space, for read/write commands */
312
313/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
314#define EC_ACPI_MEM_VERSION 0x00
315/*
316 * Test location; writing value here updates test compliment byte to (0xff -
317 * value).
318 */
319#define EC_ACPI_MEM_TEST 0x01
320/* Test compliment; writes here are ignored. */
321#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
322
323/* Keyboard backlight brightness percent (0 - 100) */
324#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
325/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
326#define EC_ACPI_MEM_FAN_DUTY 0x04
327
328/*
329 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
330 * independent thresholds attached to them. The current value of the ID
331 * register determines which sensor is affected by the THRESHOLD and COMMIT
332 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
333 * as the memory-mapped sensors. The COMMIT register applies those settings.
334 *
335 * The spec does not mandate any way to read back the threshold settings
336 * themselves, but when a threshold is crossed the AP needs a way to determine
337 * which sensor(s) are responsible. Each reading of the ID register clears and
338 * returns one sensor ID that has crossed one of its threshold (in either
339 * direction) since the last read. A value of 0xFF means "no new thresholds
340 * have tripped". Setting or enabling the thresholds for a sensor will clear
341 * the unread event count for that sensor.
342 */
343#define EC_ACPI_MEM_TEMP_ID 0x05
344#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
345#define EC_ACPI_MEM_TEMP_COMMIT 0x07
346/*
347 * Here are the bits for the COMMIT register:
348 * bit 0 selects the threshold index for the chosen sensor (0/1)
349 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
350 * Each write to the commit register affects one threshold.
351 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800352#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
353#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700354/*
355 * Example:
356 *
357 * Set the thresholds for sensor 2 to 50 C and 60 C:
358 * write 2 to [0x05] -- select temp sensor 2
359 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
360 * write 0x2 to [0x07] -- enable threshold 0 with this value
361 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
362 * write 0x3 to [0x07] -- enable threshold 1 with this value
363 *
364 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
365 * write 2 to [0x05] -- select temp sensor 2
366 * write 0x1 to [0x07] -- disable threshold 1
367 */
368
369/* DPTF battery charging current limit */
370#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
371
372/* Charging limit is specified in 64 mA steps */
373#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
374/* Value to disable DPTF battery charging limit */
375#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700376
jiazi Yang51fc93f2016-07-28 05:15:01 -0400377/*
378 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800379 * Bits Definition
380 * 3:1 Device DPTF Profile Number (DDPN)
381 * 0 = Reserved for backward compatibility (indicates no valid
382 * profile number. Host should fall back to using TBMD).
383 * 1..7 = DPTF Profile number to indicate to host which table needs
384 * to be loaded.
385 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400386 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700387#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800388#define EC_ACPI_MEM_TBMD_SHIFT 0
389#define EC_ACPI_MEM_TBMD_MASK 0x1
390#define EC_ACPI_MEM_DDPN_SHIFT 1
391#define EC_ACPI_MEM_DDPN_MASK 0x7
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700392
393/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600394 * Report device features. Uses the same format as the host command, except:
395 *
396 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
397 * of features", which is of limited interest when the system is already
398 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
399 * these are supported, it defaults to 0.
400 * This allows detecting the presence of this field since older versions of
401 * the EC codebase would simply return 0xff to that unknown address. Check
402 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
403 * are valid.
404 */
405#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
406#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
407#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
408#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
409#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
410#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
411#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
412#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
413
414#define EC_ACPI_MEM_BATTERY_INDEX 0x12
415
416/*
417 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
418 * is enabled (1) or disabled (0).
419 * bit 0 USB port ID 0
420 * ...
421 * bit 7 USB port ID 7
422 */
423#define EC_ACPI_MEM_USB_PORT_POWER 0x13
424
425/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700426 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
427 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
428 */
429#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
430#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
431
432/* Current version of ACPI memory address space */
433#define EC_ACPI_MEM_VERSION_CURRENT 2
434
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -0600435
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800436/*
437 * This header file is used in coreboot both in C and ACPI code. The ACPI code
438 * is pre-processed to handle constants but the ASL compiler is unable to
439 * handle actual C code so keep it separate.
440 */
441#ifndef __ACPI__
442
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800443#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800444/*
445 * Define __packed if someone hasn't beat us to it. Linux kernel style
446 * checking prefers __packed over __attribute__((packed)).
447 */
448#ifndef __packed
449#define __packed __attribute__((packed))
450#endif
451
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700452#ifndef __aligned
453#define __aligned(x) __attribute__((aligned(x)))
454#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800455#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700456
457/*
458 * Attributes for EC request and response packets. Just defining __packed
459 * results in inefficient assembly code on ARM, if the structure is actually
460 * 32-bit aligned, as it should be for all buffers.
461 *
462 * Be very careful when adding these to existing structures. They will round
463 * up the structure size to the specified boundary.
464 *
465 * Also be very careful to make that if a structure is included in some other
466 * parent structure that the alignment will still be true given the packing of
467 * the parent structure. This is particularly important if the sub-structure
468 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200469 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700470 *
471 * Also be very careful using __packed - particularly when nesting non-packed
472 * structures inside packed ones. In fact, DO NOT use __packed directly;
473 * always use one of these attributes.
474 *
475 * Once everything is annotated properly, the following search strings should
476 * not return ANY matches in this file other than right here:
477 *
478 * "__packed" - generates inefficient code; all sub-structs must also be packed
479 *
480 * "struct [^_]" - all structs should be annotated, except for structs that are
481 * members of other structs/unions (and their original declarations should be
482 * annotated).
483 */
484#ifdef CONFIG_HOSTCMD_ALIGNED
485
486/*
487 * Packed structures where offset and size are always aligned to 1, 2, or 4
488 * byte boundary.
489 */
490#define __ec_align1 __packed
491#define __ec_align2 __packed __aligned(2)
492#define __ec_align4 __packed __aligned(4)
493
494/*
495 * Packed structure which must be under-aligned, because its size is not a
496 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
497 * of all multi-byte fields in it, even though they are themselves aligned.
498 *
499 * In theory, we could duplicate the structure with __aligned(4) for accessing
500 * its members, but use the __packed version for sizeof().
501 */
502#define __ec_align_size1 __packed
503
504/*
505 * Packed structure which must be under-aligned, because its offset inside a
506 * parent structure is not a 4-byte multiple.
507 */
508#define __ec_align_offset1 __packed
509#define __ec_align_offset2 __packed __aligned(2)
510
511/*
512 * Structures which are complicated enough that I'm skipping them on the first
513 * pass. They are effectively unchanged from their previous definitions.
514 *
515 * TODO(rspangler): Figure out what to do with these. It's likely necessary
516 * to work out the size and offset of each member and add explicit padding to
517 * maintain those.
518 */
519#define __ec_todo_packed __packed
520#define __ec_todo_unpacked
521
522#else /* !CONFIG_HOSTCMD_ALIGNED */
523
524/*
525 * Packed structures make no assumption about alignment, so they do inefficient
526 * byte-wise reads.
527 */
528#define __ec_align1 __packed
529#define __ec_align2 __packed
530#define __ec_align4 __packed
531#define __ec_align_size1 __packed
532#define __ec_align_offset1 __packed
533#define __ec_align_offset2 __packed
534#define __ec_todo_packed __packed
535#define __ec_todo_unpacked
536
537#endif /* !CONFIG_HOSTCMD_ALIGNED */
538
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800539/* LPC command status byte masks */
540/* EC has written a byte in the data register and host hasn't read it yet */
541#define EC_LPC_STATUS_TO_HOST 0x01
542/* Host has written a command/data byte and the EC hasn't read it yet */
543#define EC_LPC_STATUS_FROM_HOST 0x02
544/* EC is processing a command */
545#define EC_LPC_STATUS_PROCESSING 0x04
546/* Last write to EC was a command, not data */
547#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700548/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800549#define EC_LPC_STATUS_BURST_MODE 0x10
550/* SCI event is pending (requesting SCI query) */
551#define EC_LPC_STATUS_SCI_PENDING 0x20
552/* SMI event is pending (requesting SMI query) */
553#define EC_LPC_STATUS_SMI_PENDING 0x40
554/* (reserved) */
555#define EC_LPC_STATUS_RESERVED 0x80
556
557/*
558 * EC is busy. This covers both the EC processing a command, and the host has
559 * written a new command but the EC hasn't picked it up yet.
560 */
561#define EC_LPC_STATUS_BUSY_MASK \
562 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
563
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800564/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700565 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700566 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800567enum ec_status {
568 EC_RES_SUCCESS = 0,
569 EC_RES_INVALID_COMMAND = 1,
570 EC_RES_ERROR = 2,
571 EC_RES_INVALID_PARAM = 3,
572 EC_RES_ACCESS_DENIED = 4,
573 EC_RES_INVALID_RESPONSE = 5,
574 EC_RES_INVALID_VERSION = 6,
575 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700576 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
577 EC_RES_UNAVAILABLE = 9, /* No response available */
578 EC_RES_TIMEOUT = 10, /* We got a timeout */
579 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800580 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
581 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700582 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700583 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600584 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
585 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
586 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
587 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
588 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700589
590 EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */
591} __packed;
592BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800593
594/*
595 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
596 * EC command uses code 0 to mean "no event pending". We explicitly specify
597 * each value in the enum listing so they won't change if we delete/insert an
598 * item or rearrange the list (it needs to be stable across platforms, not
599 * just within a single compiled instance).
600 */
601enum host_event_code {
602 EC_HOST_EVENT_LID_CLOSED = 1,
603 EC_HOST_EVENT_LID_OPEN = 2,
604 EC_HOST_EVENT_POWER_BUTTON = 3,
605 EC_HOST_EVENT_AC_CONNECTED = 4,
606 EC_HOST_EVENT_AC_DISCONNECTED = 5,
607 EC_HOST_EVENT_BATTERY_LOW = 6,
608 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
609 EC_HOST_EVENT_BATTERY = 8,
610 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700611 /* Event generated by a device attached to the EC */
612 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800613 EC_HOST_EVENT_THERMAL = 11,
614 EC_HOST_EVENT_USB_CHARGER = 12,
615 EC_HOST_EVENT_KEY_PRESSED = 13,
616 /*
617 * EC has finished initializing the host interface. The host can check
618 * for this event following sending a EC_CMD_REBOOT_EC command to
619 * determine when the EC is ready to accept subsequent commands.
620 */
621 EC_HOST_EVENT_INTERFACE_READY = 14,
622 /* Keyboard recovery combo has been pressed */
623 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
624
625 /* Shutdown due to thermal overload */
626 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
627 /* Shutdown due to battery level too low */
628 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
629
Duncan Laurie93e24442014-01-06 12:30:52 -0800630 /* Suggest that the AP throttle itself */
631 EC_HOST_EVENT_THROTTLE_START = 18,
632 /* Suggest that the AP resume normal speed */
633 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700634
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800635 /* Hang detect logic detected a hang and host event timeout expired */
636 EC_HOST_EVENT_HANG_DETECT = 20,
637 /* Hang detect logic detected a hang and warm rebooted the AP */
638 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700639
640 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700641 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800642
Duncan Lauried8401182014-09-29 08:32:19 -0700643 /* Battery Status flags have changed */
644 EC_HOST_EVENT_BATTERY_STATUS = 23,
645
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700646 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800647 EC_HOST_EVENT_PANIC = 24,
648
Furquan Shaikh066cc852015-06-20 15:53:03 -0700649 /* Keyboard fastboot combo has been pressed */
650 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
651
Gwendal Grignou880b4582016-06-20 08:49:25 -0700652 /* EC RTC event occurred */
653 EC_HOST_EVENT_RTC = 26,
654
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700655 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700656 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700657
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700658 /* EC desires to change state of host-controlled USB mux */
659 EC_HOST_EVENT_USB_MUX = 28,
660
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800661 /*
662 * The device has changed "modes". This can be one of the following:
663 *
664 * - TABLET/LAPTOP mode
665 * - detachable base attach/detach event
666 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400667 EC_HOST_EVENT_MODE_CHANGE = 29,
668
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700669 /* Keyboard recovery combo with hardware reinitialization */
670 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
671
Jett Rinkba2edaf2020-01-14 11:49:06 -0700672 /* WoV */
673 EC_HOST_EVENT_WOV = 31,
674
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700675 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800676 * The high bit of the event mask is not used as a host event code. If
677 * it reads back as set, then the entire event mask should be
678 * considered invalid by the host. This can happen when reading the
679 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
680 * not initialized on the EC, or improperly configured on the host.
681 */
682 EC_HOST_EVENT_INVALID = 32
683};
684/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800685#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800686
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800687/**
688 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
689 * @flags: The host argument flags.
690 * @command_version: Command version.
691 * @data_size: The length of data.
692 * @checksum: Checksum; sum of command + flags + command_version + data_size +
693 * all params/response data bytes.
694 */
695struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800696 uint8_t flags;
697 uint8_t command_version;
698 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800699 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800700} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800701
702/* Flags for ec_lpc_host_args.flags */
703/*
704 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
705 * params.
706 *
707 * If EC gets a command and this flag is not set, this is an old-style command.
708 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
709 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700710 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800711 */
712#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
713/*
714 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
715 *
716 * If EC responds to a command and this flag is not set, this is an old-style
717 * response. Command version is 0 and response data from EC is at
718 * EC_LPC_ADDR_OLD_PARAM with unknown length.
719 */
720#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
721
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800722/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800723/*
724 * Byte codes returned by EC over SPI interface.
725 *
726 * These can be used by the AP to debug the EC interface, and to determine
727 * when the EC is not in a state where it will ever get around to responding
728 * to the AP.
729 *
730 * Example of sequence of bytes read from EC for a current good transfer:
731 * 1. - - AP asserts chip select (CS#)
732 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
733 * 3. - - EC starts handling CS# interrupt
734 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
735 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
736 * bytes looking for EC_SPI_FRAME_START
737 * 6. - - EC finishes processing and sets up response
738 * 7. EC_SPI_FRAME_START - AP reads frame byte
739 * 8. (response packet) - AP reads response packet
740 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
741 * 10 - - AP deasserts chip select
742 * 11 - - EC processes CS# interrupt and sets up DMA for
743 * next request
744 *
745 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
746 * the following byte values:
747 * EC_SPI_OLD_READY
748 * EC_SPI_RX_READY
749 * EC_SPI_RECEIVING
750 * EC_SPI_PROCESSING
751 *
752 * Then the EC found an error in the request, or was not ready for the request
753 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
754 * because the EC is unable to tell when the AP is done sending its request.
755 */
756
757/*
758 * Framing byte which precedes a response packet from the EC. After sending a
759 * request, the AP will clock in bytes until it sees the framing byte, then
760 * clock in the response packet.
761 */
762#define EC_SPI_FRAME_START 0xec
763
764/*
765 * Padding bytes which are clocked out after the end of a response packet.
766 */
767#define EC_SPI_PAST_END 0xed
768
769/*
770 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
771 * that the AP will send a valid packet header (starting with
772 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
773 */
774#define EC_SPI_RX_READY 0xf8
775
776/*
777 * EC has started receiving the request from the AP, but hasn't started
778 * processing it yet.
779 */
780#define EC_SPI_RECEIVING 0xf9
781
782/* EC has received the entire request from the AP and is processing it. */
783#define EC_SPI_PROCESSING 0xfa
784
785/*
786 * EC received bad data from the AP, such as a packet header with an invalid
787 * length. EC will ignore all data until chip select deasserts.
788 */
789#define EC_SPI_RX_BAD_DATA 0xfb
790
791/*
792 * EC received data from the AP before it was ready. That is, the AP asserted
793 * chip select and started clocking data before the EC was ready to receive it.
794 * EC will ignore all data until chip select deasserts.
795 */
796#define EC_SPI_NOT_READY 0xfc
797
798/*
799 * EC was ready to receive a request from the AP. EC has treated the byte sent
800 * by the AP as part of a request packet, or (for old-style ECs) is processing
801 * a fully received packet but is not ready to respond yet.
802 */
803#define EC_SPI_OLD_READY 0xfd
804
805/*****************************************************************************/
806
807/*
808 * Protocol version 2 for I2C and SPI send a request this way:
809 *
810 * 0 EC_CMD_VERSION0 + (command version)
811 * 1 Command number
812 * 2 Length of params = N
813 * 3..N+2 Params, if any
814 * N+3 8-bit checksum of bytes 0..N+2
815 *
816 * The corresponding response is:
817 *
818 * 0 Result code (EC_RES_*)
819 * 1 Length of params = M
820 * 2..M+1 Params, if any
821 * M+2 8-bit checksum of bytes 0..M+1
822 */
823#define EC_PROTO2_REQUEST_HEADER_BYTES 3
824#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
825#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
826 EC_PROTO2_REQUEST_TRAILER_BYTES)
827
828#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
829#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
830#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
831 EC_PROTO2_RESPONSE_TRAILER_BYTES)
832
833/* Parameter length was limited by the LPC interface */
834#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
835
836/* Maximum request and response packet sizes for protocol version 2 */
837#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
838 EC_PROTO2_MAX_PARAM_SIZE)
839#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
840 EC_PROTO2_MAX_PARAM_SIZE)
841
842/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800843
844/*
845 * Value written to legacy command port / prefix byte to indicate protocol
846 * 3+ structs are being used. Usage is bus-dependent.
847 */
848#define EC_COMMAND_PROTOCOL_3 0xda
849
850#define EC_HOST_REQUEST_VERSION 3
851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800852/**
853 * struct ec_host_request - Version 3 request from host.
854 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
855 * receives a header with a version it doesn't know how to
856 * parse.
857 * @checksum: Checksum of request and data; sum of all bytes including checksum
858 * should total to 0.
859 * @command: Command to send (EC_CMD_...)
860 * @command_version: Command version.
861 * @reserved: Unused byte in current protocol version; set to 0.
862 * @data_len: Length of data which follows this header.
863 */
864struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800865 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800866 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800867 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800868 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800869 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800870 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800871} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800872
873#define EC_HOST_RESPONSE_VERSION 3
874
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800875/**
876 * struct ec_host_response - Version 3 response from EC.
877 * @struct_version: Struct version (=3).
878 * @checksum: Checksum of response and data; sum of all bytes including
879 * checksum should total to 0.
880 * @result: EC's response to the command (separate from communication failure)
881 * @data_len: Length of data which follows this header.
882 * @reserved: Unused bytes in current protocol version; set to 0.
883 */
884struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800885 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800886 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800887 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800888 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800889 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800890} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800891
892/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600893
894/*
895 * Host command protocol V4.
896 *
897 * Packets always start with a request or response header. They are followed
898 * by data_len bytes of data. If the data_crc_present flag is set, the data
899 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
900 * polynomial.
901 *
902 * Host algorithm when sending a request q:
903 *
904 * 101) tries_left=(some value, e.g. 3);
905 * 102) q.seq_num++
906 * 103) q.seq_dup=0
907 * 104) Calculate q.header_crc.
908 * 105) Send request q to EC.
909 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
910 *
911 * 201) If r.struct_version != 4, go to 301.
912 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
913 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
914 * 204) If r.seq_num != q.seq_num, go to 301.
915 * 205) If r.seq_dup == q.seq_dup, return success.
916 * 207) If r.seq_dup == 1, go to 301.
917 * 208) Return error.
918 *
919 * 301) If --tries_left <= 0, return error.
920 * 302) If q.seq_dup == 1, go to 105.
921 * 303) q.seq_dup = 1
922 * 304) Go to 104.
923 *
924 * EC algorithm when receiving a request q.
925 * EC has response buffer r, error buffer e.
926 *
927 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
928 * and go to 301
929 * 102) If q.header_crc mismatches calculated CRC, set e.result =
930 * EC_RES_INVALID_HEADER_CRC and go to 301
931 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
932 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
933 * and go to 301.
934 * 104) If q.seq_dup == 0, go to 201.
935 * 105) If q.seq_num != r.seq_num, go to 201.
936 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
937 *
938 * 201) Process request q into response r.
939 * 202) r.seq_num = q.seq_num
940 * 203) r.seq_dup = q.seq_dup
941 * 204) Calculate r.header_crc
942 * 205) If r.data_len > 0 and data is no longer available, set e.result =
943 * EC_RES_DUP_UNAVAILABLE and go to 301.
944 * 206) Send response r.
945 *
946 * 301) e.seq_num = q.seq_num
947 * 302) e.seq_dup = q.seq_dup
948 * 303) Calculate e.header_crc.
949 * 304) Send error response e.
950 */
951
952/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800953struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600954 /*
955 * bits 0-3: struct_version: Structure version (=4)
956 * bit 4: is_response: Is response (=0)
957 * bits 5-6: seq_num: Sequence number
958 * bit 7: seq_dup: Sequence duplicate flag
959 */
960 uint8_t fields0;
961
962 /*
963 * bits 0-4: command_version: Command version
964 * bits 5-6: Reserved (set 0, ignore on read)
965 * bit 7: data_crc_present: Is data CRC present after data
966 */
967 uint8_t fields1;
968
969 /* Command code (EC_CMD_*) */
970 uint16_t command;
971
972 /* Length of data which follows this header (not including data CRC) */
973 uint16_t data_len;
974
975 /* Reserved (set 0, ignore on read) */
976 uint8_t reserved;
977
978 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
979 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800980} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600981
982/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800983struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600984 /*
985 * bits 0-3: struct_version: Structure version (=4)
986 * bit 4: is_response: Is response (=1)
987 * bits 5-6: seq_num: Sequence number
988 * bit 7: seq_dup: Sequence duplicate flag
989 */
990 uint8_t fields0;
991
992 /*
993 * bits 0-6: Reserved (set 0, ignore on read)
994 * bit 7: data_crc_present: Is data CRC present after data
995 */
996 uint8_t fields1;
997
998 /* Result code (EC_RES_*) */
999 uint16_t result;
1000
1001 /* Length of data which follows this header (not including data CRC) */
1002 uint16_t data_len;
1003
1004 /* Reserved (set 0, ignore on read) */
1005 uint8_t reserved;
1006
1007 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1008 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001009} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001010
1011/* Fields in fields0 byte */
1012#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1013#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1014#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1015#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1016#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1017
1018/* Fields in fields1 byte */
1019#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1020#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1021
1022/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001023/*
1024 * Notes on commands:
1025 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001026 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001027 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001028 * specified, the command does not input or output data, respectively.
1029 * Parameter/response length is implicit in the structs. Some underlying
1030 * communication protocols (I2C, SPI) may add length or checksum headers, but
1031 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001032 *
1033 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1034 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001035 */
1036
1037/*****************************************************************************/
1038/* General / test commands */
1039
1040/*
1041 * Get protocol version, used to deal with non-backward compatible protocol
1042 * changes.
1043 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001044#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001045
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001046/**
1047 * struct ec_response_proto_version - Response to the proto version command.
1048 * @version: The protocol version.
1049 */
1050struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001051 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001052} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001053
1054/*
1055 * Hello. This is a simple command to test the EC is responsive to
1056 * commands.
1057 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001058#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001059
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001060/**
1061 * struct ec_params_hello - Parameters to the hello command.
1062 * @in_data: Pass anything here.
1063 */
1064struct ec_params_hello {
1065 uint32_t in_data;
1066} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001067
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001068/**
1069 * struct ec_response_hello - Response to the hello command.
1070 * @out_data: Output will be in_data + 0x01020304.
1071 */
1072struct ec_response_hello {
1073 uint32_t out_data;
1074} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001075
1076/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001077#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001078
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001079#if !defined(CHROMIUM_EC) && !defined(__KERNEL__)
1080/*
1081 * enum ec_current_image is deprecated and replaced by enum ec_image. This
1082 * macro exists for backwards compatibility of external projects until they
1083 * have been updated: b/149987779.
1084 */
1085#define ec_current_image ec_image
1086#endif
1087
1088enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001089 EC_IMAGE_UNKNOWN = 0,
1090 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001091 EC_IMAGE_RW,
1092 EC_IMAGE_RW_A = EC_IMAGE_RW,
1093 EC_IMAGE_RO_B,
1094 EC_IMAGE_RW_B
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001095};
1096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001097/**
1098 * struct ec_response_get_version - Response to the get version command.
1099 * @version_string_ro: Null-terminated RO firmware version string.
1100 * @version_string_rw: Null-terminated RW firmware version string.
1101 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001102 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001103 */
1104struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001105 char version_string_ro[32];
1106 char version_string_rw[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001107 char reserved[32];
1108 uint32_t current_image;
1109} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001110
1111/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001112#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001114/**
1115 * struct ec_params_read_test - Parameters for the read test command.
1116 * @offset: Starting value for read buffer.
1117 * @size: Size to read in bytes.
1118 */
1119struct ec_params_read_test {
1120 uint32_t offset;
1121 uint32_t size;
1122} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001124/**
1125 * struct ec_response_read_test - Response to the read test command.
1126 * @data: Data returned by the read test command.
1127 */
1128struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001129 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001130} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001131
1132/*
1133 * Get build information
1134 *
1135 * Response is null-terminated string.
1136 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001137#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001138
1139/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001140#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001141
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001142/**
1143 * struct ec_response_get_chip_info - Response to the get chip info command.
1144 * @vendor: Null-terminated string for chip vendor.
1145 * @name: Null-terminated string for chip name.
1146 * @revision: Null-terminated string for chip mask version.
1147 */
1148struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001149 char vendor[32];
1150 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001151 char revision[32];
1152} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001153
1154/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001155#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001156
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001157/**
1158 * struct ec_response_board_version - Response to the board version command.
1159 * @board_version: A monotonously incrementing number.
1160 */
1161struct ec_response_board_version {
1162 uint16_t board_version;
1163} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001164
1165/*
1166 * Read memory-mapped data.
1167 *
1168 * This is an alternate interface to memory-mapped data for bus protocols
1169 * which don't support direct-mapped memory - I2C, SPI, etc.
1170 *
1171 * Response is params.size bytes of data.
1172 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001173#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001174
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001175/**
1176 * struct ec_params_read_memmap - Parameters for the read memory map command.
1177 * @offset: Offset in memmap (EC_MEMMAP_*).
1178 * @size: Size to read in bytes.
1179 */
1180struct ec_params_read_memmap {
1181 uint8_t offset;
1182 uint8_t size;
1183} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001184
1185/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001186#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001187
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001188/**
1189 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1190 * @cmd: Command to check.
1191 */
1192struct ec_params_get_cmd_versions {
1193 uint8_t cmd;
1194} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001195
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001196/**
1197 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1198 * versions (v1)
1199 * @cmd: Command to check.
1200 */
1201struct ec_params_get_cmd_versions_v1 {
1202 uint16_t cmd;
1203} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001204
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001205/**
1206 * struct ec_response_get_cmd_version - Response to the get command versions.
1207 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1208 * a desired version.
1209 */
1210struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001211 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001212} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001213
Duncan Laurie433432b2013-06-03 10:38:22 -07001214/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001215 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001216 * on lpc since it has its own out-of-band busy indicator.
1217 *
1218 * lpc must read the status from the command register. Attempting this on
1219 * lpc will overwrite the args/parameter space and corrupt its data.
1220 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001221#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001222
1223/* Avoid using ec_status which is for return values */
1224enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001225 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001226};
1227
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001228/**
1229 * struct ec_response_get_comms_status - Response to the get comms status
1230 * command.
1231 * @flags: Mask of enum ec_comms_status.
1232 */
1233struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001234 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001235} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001236
Duncan Laurie93e24442014-01-06 12:30:52 -08001237/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001238#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001239
1240/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001241struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001242 uint32_t ec_result;
1243 uint32_t ret_len;
1244 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001245} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001246
1247/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001248struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001249 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001250} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001251
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001252/* Get protocol information */
1253#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001254
1255/* Flags for ec_response_get_protocol_info.flags */
1256/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001257#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001258
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001259/**
1260 * struct ec_response_get_protocol_info - Response to the get protocol info.
1261 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1262 * version n).
1263 * @max_request_packet_size: Maximum request packet size in bytes.
1264 * @max_response_packet_size: Maximum response packet size in bytes.
1265 * @flags: see EC_PROTOCOL_INFO_*
1266 */
1267struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001268 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001269 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001270 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001271 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001272 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001273} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001274
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001275
Duncan Laurie93e24442014-01-06 12:30:52 -08001276/*****************************************************************************/
1277/* Get/Set miscellaneous values */
1278
1279/* The upper byte of .flags tells what to do (nothing means "get") */
1280#define EC_GSV_SET 0x80000000
1281
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001282/*
1283 * The lower three bytes of .flags identifies the parameter, if that has
1284 * meaning for an individual command.
1285 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001286#define EC_GSV_PARAM_MASK 0x00ffffff
1287
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001288struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001289 uint32_t flags;
1290 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001291} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001292
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001293struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001294 uint32_t flags;
1295 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001296} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001297
Duncan Laurieeb316852015-12-01 18:51:18 -08001298/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001299#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001300
Duncan Laurieeb316852015-12-01 18:51:18 -08001301/*****************************************************************************/
1302/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001303#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001304
1305/* Supported features */
1306enum ec_feature_code {
1307 /*
1308 * This image contains a limited set of features. Another image
1309 * in RW partition may support more features.
1310 */
1311 EC_FEATURE_LIMITED = 0,
1312 /*
1313 * Commands for probing/reading/writing/erasing the flash in the
1314 * EC are present.
1315 */
1316 EC_FEATURE_FLASH = 1,
1317 /*
1318 * Can control the fan speed directly.
1319 */
1320 EC_FEATURE_PWM_FAN = 2,
1321 /*
1322 * Can control the intensity of the keyboard backlight.
1323 */
1324 EC_FEATURE_PWM_KEYB = 3,
1325 /*
1326 * Support Google lightbar, introduced on Pixel.
1327 */
1328 EC_FEATURE_LIGHTBAR = 4,
1329 /* Control of LEDs */
1330 EC_FEATURE_LED = 5,
1331 /* Exposes an interface to control gyro and sensors.
1332 * The host goes through the EC to access these sensors.
1333 * In addition, the EC may provide composite sensors, like lid angle.
1334 */
1335 EC_FEATURE_MOTION_SENSE = 6,
1336 /* The keyboard is controlled by the EC */
1337 EC_FEATURE_KEYB = 7,
1338 /* The AP can use part of the EC flash as persistent storage. */
1339 EC_FEATURE_PSTORE = 8,
1340 /* The EC monitors BIOS port 80h, and can return POST codes. */
1341 EC_FEATURE_PORT80 = 9,
1342 /*
1343 * Thermal management: include TMP specific commands.
1344 * Higher level than direct fan control.
1345 */
1346 EC_FEATURE_THERMAL = 10,
1347 /* Can switch the screen backlight on/off */
1348 EC_FEATURE_BKLIGHT_SWITCH = 11,
1349 /* Can switch the wifi module on/off */
1350 EC_FEATURE_WIFI_SWITCH = 12,
1351 /* Monitor host events, through for example SMI or SCI */
1352 EC_FEATURE_HOST_EVENTS = 13,
1353 /* The EC exposes GPIO commands to control/monitor connected devices. */
1354 EC_FEATURE_GPIO = 14,
1355 /* The EC can send i2c messages to downstream devices. */
1356 EC_FEATURE_I2C = 15,
1357 /* Command to control charger are included */
1358 EC_FEATURE_CHARGER = 16,
1359 /* Simple battery support. */
1360 EC_FEATURE_BATTERY = 17,
1361 /*
1362 * Support Smart battery protocol
1363 * (Common Smart Battery System Interface Specification)
1364 */
1365 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001366 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001367 EC_FEATURE_HANG_DETECT = 19,
1368 /* Report power information, for pit only */
1369 EC_FEATURE_PMU = 20,
1370 /* Another Cros EC device is present downstream of this one */
1371 EC_FEATURE_SUB_MCU = 21,
1372 /* Support USB Power delivery (PD) commands */
1373 EC_FEATURE_USB_PD = 22,
1374 /* Control USB multiplexer, for audio through USB port for instance. */
1375 EC_FEATURE_USB_MUX = 23,
1376 /* Motion Sensor code has an internal software FIFO */
1377 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1378 /* Support temporary secure vstore */
1379 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001380 /* EC decides on USB-C SS mux state, muxes configured by host */
1381 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1382 /* EC has RTC feature that can be controlled by host commands */
1383 EC_FEATURE_RTC = 27,
1384 /* The MCU exposes a Fingerprint sensor */
1385 EC_FEATURE_FINGERPRINT = 28,
1386 /* The MCU exposes a Touchpad */
1387 EC_FEATURE_TOUCHPAD = 29,
1388 /* The MCU has RWSIG task enabled */
1389 EC_FEATURE_RWSIG = 30,
1390 /* EC has device events support */
1391 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001392 /* EC supports the unified wake masks for LPC/eSPI systems */
1393 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001394 /* EC supports 64-bit host events */
1395 EC_FEATURE_HOST_EVENT64 = 33,
1396 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1397 EC_FEATURE_EXEC_IN_RAM = 34,
1398 /* EC supports CEC commands */
1399 EC_FEATURE_CEC = 35,
1400 /* EC supports tight sensor timestamping. */
1401 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001402 /*
1403 * EC supports tablet mode detection aligned to Chrome and allows
1404 * setting of threshold by host command using
1405 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1406 */
1407 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001408 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001409 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001410 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1411 * be sent to RO to be precise.
1412 */
1413 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001414 /* The MCU is a System Companion Processor (SCP). */
1415 EC_FEATURE_SCP = 39,
1416 /* The MCU is an Integrated Sensor Hub */
1417 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001418 /* New TCPMv2 TYPEC_ prefaced commands supported */
1419 EC_FEATURE_TYPEC_CMD = 41,
1420 /*
1421 * The EC will wait for direction from the AP to enter Type-C alternate
1422 * modes or USB4.
1423 */
1424 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1425 /*
1426 * The EC will wait for an acknowledge from the AP after setting the
1427 * mux.
1428 */
1429 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Duncan Laurieeb316852015-12-01 18:51:18 -08001430};
1431
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001432#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1433#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1434
1435struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001436 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001437} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001438
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001439/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001440/* Get the board's SKU ID from EC */
1441#define EC_CMD_GET_SKU_ID 0x000E
1442
Kevin Chiue2bb0592017-09-12 09:13:41 +08001443/* Set SKU ID from AP */
1444#define EC_CMD_SET_SKU_ID 0x000F
1445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001446struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001447 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001448} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001449
1450/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001451/* Flash commands */
1452
1453/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001454#define EC_CMD_FLASH_INFO 0x0010
1455#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001456
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001457/**
1458 * struct ec_response_flash_info - Response to the flash info command.
1459 * @flash_size: Usable flash size in bytes.
1460 * @write_block_size: Write block size. Write offset and size must be a
1461 * multiple of this.
1462 * @erase_block_size: Erase block size. Erase offset and size must be a
1463 * multiple of this.
1464 * @protect_block_size: Protection block size. Protection offset and size
1465 * must be a multiple of this.
1466 *
1467 * Version 0 returns these fields.
1468 */
1469struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001470 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001471 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001472 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001473 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001474} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001475
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001476/*
1477 * Flags for version 1+ flash info command
1478 * EC flash erases bits to 0 instead of 1.
1479 */
1480#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001481
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001482/*
1483 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001484 * be necessary on a chip where write/erase can be corrupted by other board
1485 * activity, or where the chip needs to enable some sort of programming voltage,
1486 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001487 * chip functionality.
1488 */
1489#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001490
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001491/**
1492 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1493 * @flash_size: Usable flash size in bytes.
1494 * @write_block_size: Write block size. Write offset and size must be a
1495 * multiple of this.
1496 * @erase_block_size: Erase block size. Erase offset and size must be a
1497 * multiple of this.
1498 * @protect_block_size: Protection block size. Protection offset and size
1499 * must be a multiple of this.
1500 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1501 * size is exactly this and offset is a multiple of this.
1502 * For example, an EC may have a write buffer which can do
1503 * half-page operations if data is aligned, and a slower
1504 * word-at-a-time write mode.
1505 * @flags: Flags; see EC_FLASH_INFO_*
1506 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001507 * Version 1 returns the same initial fields as version 0, with additional
1508 * fields following.
1509 *
1510 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001511 * if they did we'd define the version 0 structure as a sub-structure of this
1512 * one.
1513 *
1514 * Version 2 supports flash banks of different sizes:
1515 * The caller specified the number of banks it has preallocated
1516 * (num_banks_desc)
1517 * The EC returns the number of banks describing the flash memory.
1518 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001519 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001520struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001521 /* Version 0 fields; see above for description */
1522 uint32_t flash_size;
1523 uint32_t write_block_size;
1524 uint32_t erase_block_size;
1525 uint32_t protect_block_size;
1526
1527 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001528 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001529 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001530} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001531
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001532struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001533 /* Number of banks to describe */
1534 uint16_t num_banks_desc;
1535 /* Reserved; set 0; ignore on read */
1536 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001537} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001538
1539struct ec_flash_bank {
1540 /* Number of sector is in this bank. */
1541 uint16_t count;
1542 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1543 uint8_t size_exp;
1544 /* Minimal write size for the sectors in this bank */
1545 uint8_t write_size_exp;
1546 /* Erase size for the sectors in this bank */
1547 uint8_t erase_size_exp;
1548 /* Size for write protection, usually identical to erase size. */
1549 uint8_t protect_size_exp;
1550 /* Reserved; set 0; ignore on read */
1551 uint8_t reserved[2];
1552};
1553
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001554struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001555 /* Total flash in the EC. */
1556 uint32_t flash_size;
1557 /* Flags; see EC_FLASH_INFO_* */
1558 uint32_t flags;
1559 /* Maximum size to use to send data to write to the EC. */
1560 uint32_t write_ideal_size;
1561 /* Number of banks present in the EC. */
1562 uint16_t num_banks_total;
1563 /* Number of banks described in banks array. */
1564 uint16_t num_banks_desc;
1565 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001566} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001567
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001568/*
1569 * Read flash
1570 *
1571 * Response is params.size bytes of data.
1572 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001573#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001574
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001575/**
1576 * struct ec_params_flash_read - Parameters for the flash read command.
1577 * @offset: Byte offset to read.
1578 * @size: Size to read in bytes.
1579 */
1580struct ec_params_flash_read {
1581 uint32_t offset;
1582 uint32_t size;
1583} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001584
1585/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001586#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001587#define EC_VER_FLASH_WRITE 1
1588
1589/* Version 0 of the flash command supported only 64 bytes of data */
1590#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001591
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001592/**
1593 * struct ec_params_flash_write - Parameters for the flash write command.
1594 * @offset: Byte offset to write.
1595 * @size: Size to write in bytes.
1596 */
1597struct ec_params_flash_write {
1598 uint32_t offset;
1599 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001600 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001601} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001602
1603/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001604#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001605
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001606/**
1607 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1608 * @offset: Byte offset to erase.
1609 * @size: Size to erase in bytes.
1610 */
1611struct ec_params_flash_erase {
1612 uint32_t offset;
1613 uint32_t size;
1614} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001615
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001616/*
1617 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001618 * subcommands can returns:
1619 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1620 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1621 * EC_RES_ERROR : other errors.
1622 * EC_RES_BUSY : an existing erase operation is in progress.
1623 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1624 *
1625 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1626 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1627 * the proper result.
1628 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1629 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1630 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1631 * permitted while erasing. (For instance, STM32F4).
1632 */
1633enum ec_flash_erase_cmd {
1634 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1635 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1636 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1637};
1638
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001639/**
1640 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1641 * @cmd: One of ec_flash_erase_cmd.
1642 * @reserved: Pad byte; currently always contains 0.
1643 * @flag: No flags defined yet; set to 0.
1644 * @params: Same as v0 parameters.
1645 */
1646struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001647 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001648 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001649 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001650 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001651} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001652
1653/*
1654 * Get/set flash protection.
1655 *
1656 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1657 * firmware write protect GPIO, not all flags will take effect immediately;
1658 * some flags require a subsequent hard reset to take effect. Check the
1659 * returned flags bits to see what actually happened.
1660 *
1661 * If mask=0, simply returns the current flags state.
1662 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001663#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001664#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1665
1666/* Flags for flash protection */
1667/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001668#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001669/*
1670 * RO flash code protected now. If this bit is set, at-boot status cannot
1671 * be changed.
1672 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001673#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001674/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001675#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001676/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001677#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001678/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001679#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001680/*
1681 * Error - flash protection is in inconsistent state. At least one bank of
1682 * flash which should be protected is not protected. Usually fixed by
1683 * re-requesting the desired flags, or by a hard reset if that fails.
1684 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001685#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001686/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001687#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001688/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001689#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001690/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001691#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001692/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001693#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001694/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001695#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001696
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001697
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001698/**
1699 * struct ec_params_flash_protect - Parameters for the flash protect command.
1700 * @mask: Bits in flags to apply.
1701 * @flags: New flags to apply.
1702 */
1703struct ec_params_flash_protect {
1704 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001705 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001706} __ec_align4;
1707
1708/**
1709 * struct ec_response_flash_protect - Response to the flash protect command.
1710 * @flags: Current value of flash protect flags.
1711 * @valid_flags: Flags which are valid on this platform. This allows the
1712 * caller to distinguish between flags which aren't set vs. flags
1713 * which can't be set on this platform.
1714 * @writable_flags: Flags which can be changed given the current protection
1715 * state.
1716 */
1717struct ec_response_flash_protect {
1718 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001719 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001720 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001721} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001722
1723/*
1724 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1725 * write protect. These commands may be reused with version > 0.
1726 */
1727
1728/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001729#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001730#define EC_VER_FLASH_REGION_INFO 1
1731
1732enum ec_flash_region {
1733 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001734 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001735 /*
1736 * Region which holds active RW image. 'Active' is different from
1737 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1738 * scheduled to run, active/non-active applies only to RW images (for
1739 * the same reason 'update' applies only to RW images. It's a state of
1740 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1741 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1742 * doesn't enter 'running' state but it's still active on a flash.
1743 */
1744 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001745 /*
1746 * Region which should be write-protected in the factory (a superset of
1747 * EC_FLASH_REGION_RO)
1748 */
1749 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001750 /* Region which holds updatable (non-active) RW image */
1751 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001752 /* Number of regions */
1753 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001754};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001755/*
1756 * 'RW' is vague if there are multiple RW images; we mean the active one,
1757 * so the old constant is deprecated.
1758 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001759#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001760
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001761/**
1762 * struct ec_params_flash_region_info - Parameters for the flash region info
1763 * command.
1764 * @region: Flash region; see EC_FLASH_REGION_*
1765 */
1766struct ec_params_flash_region_info {
1767 uint32_t region;
1768} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001769
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001770struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001771 uint32_t offset;
1772 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001773} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001774
Duncan Laurie433432b2013-06-03 10:38:22 -07001775/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001776#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001777#define EC_VER_VBNV_CONTEXT 1
1778#define EC_VBNV_BLOCK_SIZE 16
1779
1780enum ec_vbnvcontext_op {
1781 EC_VBNV_CONTEXT_OP_READ,
1782 EC_VBNV_CONTEXT_OP_WRITE,
1783};
1784
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001785struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001786 uint32_t op;
1787 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001788} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001789
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001790struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001791 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001792} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001793
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001794
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001795/* Get SPI flash information */
1796#define EC_CMD_FLASH_SPI_INFO 0x0018
1797
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001798struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001799 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1800 uint8_t jedec[3];
1801
1802 /* Pad byte; currently always contains 0 */
1803 uint8_t reserved0;
1804
1805 /* Manufacturer / device ID from command 0x90 */
1806 uint8_t mfr_dev_id[2];
1807
1808 /* Status registers from command 0x05 and 0x35 */
1809 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001810} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001811
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001812
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001813/* Select flash during flash operations */
1814#define EC_CMD_FLASH_SELECT 0x0019
1815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001816/**
1817 * struct ec_params_flash_select - Parameters for the flash select command.
1818 * @select: 1 to select flash, 0 to deselect flash
1819 */
1820struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001821 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001822} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001823
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001824
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001825/**
1826 * Request random numbers to be generated and returned.
1827 * Can be used to test the random number generator is truly random.
1828 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1829 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1830 */
1831#define EC_CMD_RAND_NUM 0x001A
1832#define EC_VER_RAND_NUM 0
1833
1834struct ec_params_rand_num {
1835 uint16_t num_rand_bytes; /**< num random bytes to generate */
1836} __ec_align4;
1837
1838struct ec_response_rand_num {
1839 uint8_t rand[0]; /**< generated random numbers */
1840} __ec_align4;
1841
1842BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1843
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001844/**
1845 * Get information about the key used to sign the RW firmware.
1846 * For more details on the fields, see "struct vb21_packed_key".
1847 */
1848#define EC_CMD_RWSIG_INFO 0x001B
1849#define EC_VER_RWSIG_INFO 0
1850
1851#define VBOOT2_KEY_ID_BYTES 20
1852
1853#ifdef CHROMIUM_EC
1854/* Don't force external projects to depend on the vboot headers. */
1855#include "vb21_struct.h"
1856BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1857#endif
1858
1859struct ec_response_rwsig_info {
1860 /**
1861 * Signature algorithm used by the key
1862 * (enum vb2_signature_algorithm).
1863 */
1864 uint16_t sig_alg;
1865
1866 /**
1867 * Hash digest algorithm used with the key
1868 * (enum vb2_hash_algorithm).
1869 */
1870 uint16_t hash_alg;
1871
1872 /** Key version. */
1873 uint32_t key_version;
1874
1875 /** Key ID (struct vb2_id). */
1876 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
1877
1878 uint8_t key_is_valid;
1879
1880 /** Alignment padding. */
1881 uint8_t reserved[3];
1882} __ec_align4;
1883
1884BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
1885
1886/**
1887 * Get information about the system, such as reset flags, locked state, etc.
1888 */
1889#define EC_CMD_SYSINFO 0x001C
1890#define EC_VER_SYSINFO 0
1891
1892enum sysinfo_flags {
1893 SYSTEM_IS_LOCKED = BIT(0),
1894 SYSTEM_IS_FORCE_LOCKED = BIT(1),
1895 SYSTEM_JUMP_ENABLED = BIT(2),
1896 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
1897 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4)
1898};
1899
1900struct ec_response_sysinfo {
1901 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
1902 uint32_t current_image; /**< enum ec_current_image */
1903 uint32_t flags; /**< enum sysinfo_flags */
1904} __ec_align4;
1905
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001906/*****************************************************************************/
1907/* PWM commands */
1908
1909/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001910#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001911
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001912struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001913 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001914} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001915
1916/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001917#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001918
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001919/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001920struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001921 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001922} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001923
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001924/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001925struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001926 uint32_t rpm;
1927 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001928} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001929
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001930/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001931/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001932#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001933
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001934struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001935 uint8_t percent;
1936 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001937} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001938
1939/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001940/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001941#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001942
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001943struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001944 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001945} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001946
1947/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001948#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001949
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001950/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001951struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001952 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001953} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001954
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001955/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001956struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001957 uint32_t percent;
1958 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001959} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001960
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001961#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001962/* 16 bit duty cycle, 0xffff = 100% */
1963#define EC_PWM_MAX_DUTY 0xffff
1964
1965enum ec_pwm_type {
1966 /* All types, indexed by board-specific enum pwm_channel */
1967 EC_PWM_TYPE_GENERIC = 0,
1968 /* Keyboard backlight */
1969 EC_PWM_TYPE_KB_LIGHT,
1970 /* Display backlight */
1971 EC_PWM_TYPE_DISPLAY_LIGHT,
1972 EC_PWM_TYPE_COUNT,
1973};
1974
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001975struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001976 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1977 uint8_t pwm_type; /* ec_pwm_type */
1978 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001979} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001980
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001981#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001982
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001983struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001984 uint8_t pwm_type; /* ec_pwm_type */
1985 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001986} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001987
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001988struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001989 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001990} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001991
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001992/*****************************************************************************/
1993/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001994 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001995 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1996 * into a subcommand. We'll make separate structs for subcommands with
1997 * different input args, so that we know how much to expect.
1998 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001999#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002000
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002001struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002002 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002003} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002004
Duncan Laurie433432b2013-06-03 10:38:22 -07002005#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002006
2007/*
2008 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002009 * host command, but the alignment is the same regardless. Keep it that way.
2010 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002011struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002012 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002013 int32_t google_ramp_up;
2014 int32_t google_ramp_down;
2015 int32_t s3s0_ramp_up;
2016 int32_t s0_tick_delay[2]; /* AC=0/1 */
2017 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2018 int32_t s0s3_ramp_down;
2019 int32_t s3_sleep_for;
2020 int32_t s3_ramp_up;
2021 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002022
2023 /* Oscillation */
2024 uint8_t new_s0;
2025 uint8_t osc_min[2]; /* AC=0/1 */
2026 uint8_t osc_max[2]; /* AC=0/1 */
2027 uint8_t w_ofs[2]; /* AC=0/1 */
2028
2029 /* Brightness limits based on the backlight and AC. */
2030 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2031 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2032 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2033
2034 /* Battery level thresholds */
2035 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2036
2037 /* Map [AC][battery_level] to color index */
2038 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2039 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2040
2041 /* Color palette */
2042 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002043} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002044
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002045struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002046 /* Timing */
2047 int32_t google_ramp_up;
2048 int32_t google_ramp_down;
2049 int32_t s3s0_ramp_up;
2050 int32_t s0_tick_delay[2]; /* AC=0/1 */
2051 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2052 int32_t s0s3_ramp_down;
2053 int32_t s3_sleep_for;
2054 int32_t s3_ramp_up;
2055 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002056 int32_t s5_ramp_up;
2057 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002058 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002059 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002060 int32_t tap_display_time;
2061
2062 /* Tap-for-battery params */
2063 uint8_t tap_pct_red;
2064 uint8_t tap_pct_green;
2065 uint8_t tap_seg_min_on;
2066 uint8_t tap_seg_max_on;
2067 uint8_t tap_seg_osc;
2068 uint8_t tap_idx[3];
2069
2070 /* Oscillation */
2071 uint8_t osc_min[2]; /* AC=0/1 */
2072 uint8_t osc_max[2]; /* AC=0/1 */
2073 uint8_t w_ofs[2]; /* AC=0/1 */
2074
2075 /* Brightness limits based on the backlight and AC. */
2076 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2077 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2078 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2079
2080 /* Battery level thresholds */
2081 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2082
2083 /* Map [AC][battery_level] to color index */
2084 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2085 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2086
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002087 /* s5: single color pulse on inhibited power-up */
2088 uint8_t s5_idx;
2089
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002090 /* Color palette */
2091 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002092} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002093
Duncan Laurieeb316852015-12-01 18:51:18 -08002094/* Lightbar command params v2
2095 * crbug.com/467716
2096 *
2097 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2098 * logical groups to make it more manageable ( < 120 bytes).
2099 *
2100 * NOTE: Each of these groups must be less than 120 bytes.
2101 */
2102
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002103struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002104 /* Timing */
2105 int32_t google_ramp_up;
2106 int32_t google_ramp_down;
2107 int32_t s3s0_ramp_up;
2108 int32_t s0_tick_delay[2]; /* AC=0/1 */
2109 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2110 int32_t s0s3_ramp_down;
2111 int32_t s3_sleep_for;
2112 int32_t s3_ramp_up;
2113 int32_t s3_ramp_down;
2114 int32_t s5_ramp_up;
2115 int32_t s5_ramp_down;
2116 int32_t tap_tick_delay;
2117 int32_t tap_gate_delay;
2118 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002119} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002120
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002121struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002122 /* Tap-for-battery params */
2123 uint8_t tap_pct_red;
2124 uint8_t tap_pct_green;
2125 uint8_t tap_seg_min_on;
2126 uint8_t tap_seg_max_on;
2127 uint8_t tap_seg_osc;
2128 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002129} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002130
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002131struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002132 /* Oscillation */
2133 uint8_t osc_min[2]; /* AC=0/1 */
2134 uint8_t osc_max[2]; /* AC=0/1 */
2135 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002136} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002137
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002138struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002139 /* Brightness limits based on the backlight and AC. */
2140 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2141 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2142 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002143} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002144
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002145struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002146 /* Battery level thresholds */
2147 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002148} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002150struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002151 /* Map [AC][battery_level] to color index */
2152 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2153 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2154
2155 /* s5: single color pulse on inhibited power-up */
2156 uint8_t s5_idx;
2157
2158 /* Color palette */
2159 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002160} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002161
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002162/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002163#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002164struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002165 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002166 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002167} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002168
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002169struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002170 uint8_t cmd; /* Command (see enum lightbar_command) */
2171 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002172 /*
2173 * The following commands have no args:
2174 *
2175 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2176 * version, get_brightness, get_demo, suspend, resume,
2177 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2178 * get_params_v2_bright, get_params_v2_thlds,
2179 * get_params_v2_colors
2180 *
2181 * Don't use an empty struct, because C++ hates that.
2182 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002183
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002184 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002185 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002186 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002187
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002188 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002189 uint8_t ctrl, reg, value;
2190 } reg;
2191
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002192 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002193 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002194 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002195
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002196 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002197 uint8_t led;
2198 } get_rgb;
2199
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002200 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002201 uint8_t enable;
2202 } manual_suspend_ctrl;
2203
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002204 struct lightbar_params_v0 set_params_v0;
2205 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002206
2207 struct lightbar_params_v2_timing set_v2par_timing;
2208 struct lightbar_params_v2_tap set_v2par_tap;
2209 struct lightbar_params_v2_oscillation set_v2par_osc;
2210 struct lightbar_params_v2_brightness set_v2par_bright;
2211 struct lightbar_params_v2_thresholds set_v2par_thlds;
2212 struct lightbar_params_v2_colors set_v2par_colors;
2213
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002214 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002215 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002216} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002218struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002219 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002220 struct __ec_todo_unpacked {
2221 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002222 uint8_t reg;
2223 uint8_t ic0;
2224 uint8_t ic1;
2225 } vals[23];
2226 } dump;
2227
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002228 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002229 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002230 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002231
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002232 struct lightbar_params_v0 get_params_v0;
2233 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002234
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002235
Duncan Laurieeb316852015-12-01 18:51:18 -08002236 struct lightbar_params_v2_timing get_params_v2_timing;
2237 struct lightbar_params_v2_tap get_params_v2_tap;
2238 struct lightbar_params_v2_oscillation get_params_v2_osc;
2239 struct lightbar_params_v2_brightness get_params_v2_bright;
2240 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2241 struct lightbar_params_v2_colors get_params_v2_colors;
2242
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002243 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002244 uint32_t num;
2245 uint32_t flags;
2246 } version;
2247
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002248 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002249 uint8_t red, green, blue;
2250 } get_rgb;
2251
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002252 /*
2253 * The following commands have no response:
2254 *
2255 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2256 * set_params_v0, set_params_v1, set_program,
2257 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2258 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2259 * set_v2par_thlds, set_v2par_colors
2260 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002261 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002262} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002263
2264/* Lightbar commands */
2265enum lightbar_command {
2266 LIGHTBAR_CMD_DUMP = 0,
2267 LIGHTBAR_CMD_OFF = 1,
2268 LIGHTBAR_CMD_ON = 2,
2269 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002270 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002271 LIGHTBAR_CMD_SEQ = 5,
2272 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002273 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002274 LIGHTBAR_CMD_GET_SEQ = 8,
2275 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002276 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2277 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002278 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002279 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2280 LIGHTBAR_CMD_GET_RGB = 14,
2281 LIGHTBAR_CMD_GET_DEMO = 15,
2282 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2283 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002284 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002285 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2286 LIGHTBAR_CMD_SUSPEND = 20,
2287 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002288 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2289 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2290 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2291 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2292 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2293 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2294 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2295 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2296 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2297 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2298 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2299 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002300 LIGHTBAR_NUM_CMDS
2301};
2302
2303/*****************************************************************************/
2304/* LED control commands */
2305
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002306#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002307
Bill Richardsone221aad2013-06-12 10:50:41 -07002308enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002309 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002310 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002311 /*
2312 * LED to indicate system power state (on or in suspend).
2313 * May be on power button or on C-panel.
2314 */
2315 EC_LED_ID_POWER_LED,
2316 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002317 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002318 /* LED to indicate left side */
2319 EC_LED_ID_LEFT_LED,
2320 /* LED to indicate right side */
2321 EC_LED_ID_RIGHT_LED,
2322 /* LED to indicate recovery mode with HW_REINIT */
2323 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2324 /* LED to indicate sysrq debug mode. */
2325 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002326
2327 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002328};
Duncan Laurie433432b2013-06-03 10:38:22 -07002329
Bill Richardsone221aad2013-06-12 10:50:41 -07002330/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002331#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2332#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002333
2334enum ec_led_colors {
2335 EC_LED_COLOR_RED = 0,
2336 EC_LED_COLOR_GREEN,
2337 EC_LED_COLOR_BLUE,
2338 EC_LED_COLOR_YELLOW,
2339 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002340 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002341
2342 EC_LED_COLOR_COUNT
2343};
2344
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002345struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002346 uint8_t led_id; /* Which LED to control */
2347 uint8_t flags; /* Control flags */
2348
2349 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002350} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002351
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002352struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002353 /*
2354 * Available brightness value range.
2355 *
2356 * Range 0 means color channel not present.
2357 * Range 1 means on/off control.
2358 * Other values means the LED is control by PWM.
2359 */
2360 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002361} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002362
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002363/*****************************************************************************/
2364/* Verified boot commands */
2365
2366/*
2367 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2368 * reused for other purposes with version > 0.
2369 */
2370
2371/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002372#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002373
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002374struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002375 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2376 uint8_t hash_type; /* enum ec_vboot_hash_type */
2377 uint8_t nonce_size; /* Nonce size; may be 0 */
2378 uint8_t reserved0; /* Reserved; set 0 */
2379 uint32_t offset; /* Offset in flash to hash */
2380 uint32_t size; /* Number of bytes to hash */
2381 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002382} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002383
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002384struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002385 uint8_t status; /* enum ec_vboot_hash_status */
2386 uint8_t hash_type; /* enum ec_vboot_hash_type */
2387 uint8_t digest_size; /* Size of hash digest in bytes */
2388 uint8_t reserved0; /* Ignore; will be 0 */
2389 uint32_t offset; /* Offset in flash which was hashed */
2390 uint32_t size; /* Number of bytes hashed */
2391 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002392} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002393
2394enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002395 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2396 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2397 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2398 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002399};
2400
2401enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002402 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002403};
2404
2405enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002406 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2407 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2408 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002409};
2410
Duncan Laurie433432b2013-06-03 10:38:22 -07002411/*
2412 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2413 * If one of these is specified, the EC will automatically update offset and
2414 * size to the correct values for the specified image (RO or RW).
2415 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002416#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2417#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2418#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2419
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002420/*
2421 * 'RW' is vague if there are multiple RW images; we mean the active one,
2422 * so the old constant is deprecated.
2423 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002424#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002425
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002426/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002427/*
2428 * Motion sense commands. We'll make separate structs for sub-commands with
2429 * different input args, so that we know how much to expect.
2430 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002431#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002432
2433/* Motion sense commands */
2434enum motionsense_command {
2435 /*
2436 * Dump command returns all motion sensor data including motion sense
2437 * module flags and individual sensor flags.
2438 */
2439 MOTIONSENSE_CMD_DUMP = 0,
2440
2441 /*
2442 * Info command returns data describing the details of a given sensor,
2443 * including enum motionsensor_type, enum motionsensor_location, and
2444 * enum motionsensor_chip.
2445 */
2446 MOTIONSENSE_CMD_INFO = 1,
2447
2448 /*
2449 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002450 * in milliseconds.
2451 * It is per sensor, the EC run sample task at the minimum of all
2452 * sensors EC_RATE.
2453 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2454 * to collect all the sensor samples.
2455 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2456 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002457 */
2458 MOTIONSENSE_CMD_EC_RATE = 2,
2459
2460 /*
2461 * Sensor ODR command is a setter/getter command for the output data
2462 * rate of a specific motion sensor in millihertz.
2463 */
2464 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2465
2466 /*
2467 * Sensor range command is a setter/getter command for the range of
2468 * a specified motion sensor in +/-G's or +/- deg/s.
2469 */
2470 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2471
2472 /*
2473 * Setter/getter command for the keyboard wake angle. When the lid
2474 * angle is greater than this value, keyboard wake is disabled in S3,
2475 * and when the lid angle goes less than this value, keyboard wake is
2476 * enabled. Note, the lid angle measurement is an approximate,
2477 * un-calibrated value, hence the wake angle isn't exact.
2478 */
2479 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2480
Duncan Laurieeb316852015-12-01 18:51:18 -08002481 /*
2482 * Returns a single sensor data.
2483 */
2484 MOTIONSENSE_CMD_DATA = 6,
2485
2486 /*
2487 * Return sensor fifo info.
2488 */
2489 MOTIONSENSE_CMD_FIFO_INFO = 7,
2490
2491 /*
2492 * Insert a flush element in the fifo and return sensor fifo info.
2493 * The host can use that element to synchronize its operation.
2494 */
2495 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2496
2497 /*
2498 * Return a portion of the fifo.
2499 */
2500 MOTIONSENSE_CMD_FIFO_READ = 9,
2501
2502 /*
2503 * Perform low level calibration.
2504 * On sensors that support it, ask to do offset calibration.
2505 */
2506 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2507
2508 /*
2509 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002510 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002511 * The offsets can be calculated by the host, or via
2512 * PERFORM_CALIB command.
2513 */
2514 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2515
2516 /*
2517 * List available activities for a MOTION sensor.
2518 * Indicates if they are enabled or disabled.
2519 */
2520 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2521
2522 /*
2523 * Activity management
2524 * Enable/Disable activity recognition.
2525 */
2526 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2527
2528 /*
2529 * Lid Angle
2530 */
2531 MOTIONSENSE_CMD_LID_ANGLE = 14,
2532
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002533 /*
2534 * Allow the FIFO to trigger interrupt via MKBP events.
2535 * By default the FIFO does not send interrupt to process the FIFO
2536 * until the AP is ready or it is coming from a wakeup sensor.
2537 */
2538 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2539
2540 /*
2541 * Spoof the readings of the sensors. The spoofed readings can be set
2542 * to arbitrary values, or will lock to the last read actual values.
2543 */
2544 MOTIONSENSE_CMD_SPOOF = 16,
2545
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002546 /* Set lid angle for tablet mode detection. */
2547 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2548
2549 /*
2550 * Sensor Scale command is a setter/getter command for the calibration
2551 * scale.
2552 */
2553 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2554
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002555 /*
2556 * Read the current online calibration values (if available).
2557 */
2558 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2559
Yidi Lin42f79592020-09-21 18:04:10 +08002560 /*
2561 * Activity management
2562 * Retrieve current status of given activity.
2563 */
2564 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2565
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002566 /* Number of motionsense sub-commands. */
2567 MOTIONSENSE_NUM_CMDS
2568};
2569
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002570/* List of motion sensor types. */
2571enum motionsensor_type {
2572 MOTIONSENSE_TYPE_ACCEL = 0,
2573 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002574 MOTIONSENSE_TYPE_MAG = 2,
2575 MOTIONSENSE_TYPE_PROX = 3,
2576 MOTIONSENSE_TYPE_LIGHT = 4,
2577 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002578 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002579 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002580 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002581 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002582};
2583
2584/* List of motion sensor locations. */
2585enum motionsensor_location {
2586 MOTIONSENSE_LOC_BASE = 0,
2587 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002588 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002589 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002590};
2591
2592/* List of motion sensor chips. */
2593enum motionsensor_chip {
2594 MOTIONSENSE_CHIP_KXCJ9 = 0,
2595 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002596 MOTIONSENSE_CHIP_BMI160 = 2,
2597 MOTIONSENSE_CHIP_SI1141 = 3,
2598 MOTIONSENSE_CHIP_SI1142 = 4,
2599 MOTIONSENSE_CHIP_SI1143 = 5,
2600 MOTIONSENSE_CHIP_KX022 = 6,
2601 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002602 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002603 MOTIONSENSE_CHIP_BMP280 = 9,
2604 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002605 MOTIONSENSE_CHIP_BH1730 = 11,
2606 MOTIONSENSE_CHIP_GPIO = 12,
2607 MOTIONSENSE_CHIP_LIS2DH = 13,
2608 MOTIONSENSE_CHIP_LSM6DSM = 14,
2609 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002610 MOTIONSENSE_CHIP_LIS2MDL = 16,
2611 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2612 MOTIONSENSE_CHIP_LSM6DSO = 18,
2613 MOTIONSENSE_CHIP_LNG2DM = 19,
2614 MOTIONSENSE_CHIP_TCS3400 = 20,
2615 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2616 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002617 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002618 MOTIONSENSE_CHIP_BMI260 = 24,
2619 MOTIONSENSE_CHIP_ICM426XX = 25,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002620 MOTIONSENSE_CHIP_MAX,
2621};
2622
2623/* List of orientation positions */
2624enum motionsensor_orientation {
2625 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2626 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2627 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2628 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2629 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002630};
2631
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002632struct ec_response_activity_data {
2633 uint8_t activity; /* motionsensor_activity */
2634 uint8_t state;
2635} __ec_todo_packed;
2636
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002637struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002638 /* Flags for each sensor. */
2639 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002640 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002641 uint8_t sensor_num;
2642 /* Each sensor is up to 3-axis. */
2643 union {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002644 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002645 /* for sensors using unsigned data */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002646 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002647 struct __ec_todo_packed {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002648 uint16_t reserved;
2649 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002650 };
2651 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002652 struct ec_response_activity_data activity_data;
2653 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002654 };
2655 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002656} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002657
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002658/* Response to AP reporting calibration data for a given sensor. */
2659struct ec_response_online_calibration_data {
2660 /** The calibration values. */
2661 int16_t data[3];
2662};
2663
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002664/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002665struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002666 /* Size of the fifo */
2667 uint16_t size;
2668 /* Amount of space used in the fifo */
2669 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002670 /* Timestamp recorded in us.
2671 * aka accurate timestamp when host event was triggered.
2672 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002673 uint32_t timestamp;
2674 /* Total amount of vector lost */
2675 uint16_t total_lost;
2676 /* Lost events since the last fifo_info, per sensors */
2677 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002678} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002679
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002680struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002681 uint32_t number_data;
2682 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002683} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002684
2685/* List supported activity recognition */
2686enum motionsensor_activity {
2687 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2688 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2689 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002690 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002691 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002692};
2693
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002694struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002695 uint8_t sensor_num;
2696 uint8_t activity; /* one of enum motionsensor_activity */
2697 uint8_t enable; /* 1: enable, 0: disable */
2698 uint8_t reserved;
2699 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002700} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002701
2702/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002703#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002704
2705/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002706#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002707
2708/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002709 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002710 * data contains time stamp
2711 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002712#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2713#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2714#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2715#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2716#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002717
2718/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002719 * Send this value for the data element to only perform a read. If you
2720 * send any other value, the EC will interpret it as data to set and will
2721 * return the actual value set.
2722 */
2723#define EC_MOTION_SENSE_NO_VALUE -1
2724
Duncan Laurieeb316852015-12-01 18:51:18 -08002725#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2726
2727/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2728/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002729#define MOTION_SENSE_SET_OFFSET BIT(0)
2730
2731/* Default Scale value, factor 1. */
2732#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002733
2734#define LID_ANGLE_UNRELIABLE 500
2735
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002736enum motionsense_spoof_mode {
2737 /* Disable spoof mode. */
2738 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2739
2740 /* Enable spoof mode, but use provided component values. */
2741 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2742
2743 /* Enable spoof mode, but use the current sensor values. */
2744 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2745
2746 /* Query the current spoof mode status for the sensor. */
2747 MOTIONSENSE_SPOOF_MODE_QUERY,
2748};
2749
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002750struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002751 uint8_t cmd;
2752 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002753 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002754 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002755 /*
2756 * Maximal number of sensor the host is expecting.
2757 * 0 means the host is only interested in the number
2758 * of sensors controlled by the EC.
2759 */
2760 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002761 } dump;
2762
2763 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002764 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002765 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002766 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002767 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2768 * kb_wake_angle: angle to wakup AP.
2769 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002770 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002771 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002772
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002773 /*
2774 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2775 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002776 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002777 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002778 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002779
2780 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002781 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2782 * Allow entering/exiting the calibration mode.
2783 */
2784 struct __ec_todo_unpacked {
2785 uint8_t sensor_num;
2786 uint8_t enable;
2787 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002788
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002789 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002790 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2791 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002792 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002793 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002794 uint8_t sensor_num;
2795
2796 /* Rounding flag, true for round-up, false for down. */
2797 uint8_t roundup;
2798
2799 uint16_t reserved;
2800
2801 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2802 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002803 } ec_rate, sensor_odr, sensor_range;
2804
2805 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002806 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002807 uint8_t sensor_num;
2808
2809 /*
2810 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2811 * the calibration information in the EC.
2812 * If unset, just retrieve calibration information.
2813 */
2814 uint16_t flags;
2815
2816 /*
2817 * Temperature at calibration, in units of 0.01 C
2818 * 0x8000: invalid / unknown.
2819 * 0x0: 0C
2820 * 0x7fff: +327.67C
2821 */
2822 int16_t temp;
2823
2824 /*
2825 * Offset for calibration.
2826 * Unit:
2827 * Accelerometer: 1/1024 g
2828 * Gyro: 1/1024 deg/s
2829 * Compass: 1/16 uT
2830 */
2831 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002832 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002833
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002834 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2835 struct __ec_todo_packed {
2836 uint8_t sensor_num;
2837
2838 /*
2839 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2840 * the calibration information in the EC.
2841 * If unset, just retrieve calibration information.
2842 */
2843 uint16_t flags;
2844
2845 /*
2846 * Temperature at calibration, in units of 0.01 C
2847 * 0x8000: invalid / unknown.
2848 * 0x0: 0C
2849 * 0x7fff: +327.67C
2850 */
2851 int16_t temp;
2852
2853 /*
2854 * Scale for calibration:
2855 * By default scale is 1, it is encoded on 16bits:
2856 * 1 = BIT(15)
2857 * ~2 = 0xFFFF
2858 * ~0 = 0.
2859 */
2860 uint16_t scale[3];
2861 } sensor_scale;
2862
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002863
Duncan Laurieeb316852015-12-01 18:51:18 -08002864 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002865 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002866
2867 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002868 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002869 /*
2870 * Number of expected vector to return.
2871 * EC may return less or 0 if none available.
2872 */
2873 uint32_t max_data_vector;
2874 } fifo_read;
2875
Yidi Lin42f79592020-09-21 18:04:10 +08002876 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08002877 struct ec_motion_sense_activity set_activity;
2878
2879 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002880 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002881
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002882 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2883 struct __ec_todo_unpacked {
2884 /*
2885 * 1: enable, 0 disable fifo,
2886 * EC_MOTION_SENSE_NO_VALUE return value.
2887 */
2888 int8_t enable;
2889 } fifo_int_enable;
2890
2891 /* Used for MOTIONSENSE_CMD_SPOOF */
2892 struct __ec_todo_packed {
2893 uint8_t sensor_id;
2894
2895 /* See enum motionsense_spoof_mode. */
2896 uint8_t spoof_enable;
2897
2898 /* Ignored, used for alignment. */
2899 uint8_t reserved;
2900
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002901 union {
2902 /* Individual component values to spoof. */
2903 int16_t components[3];
2904
2905 /* Used when spoofing an activity */
2906 struct {
2907 /* enum motionsensor_activity */
2908 uint8_t activity_num;
2909
2910 /* spoof activity state */
2911 uint8_t activity_state;
2912 };
2913 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002914 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002915
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002916 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2917 struct __ec_todo_unpacked {
2918 /*
2919 * Lid angle threshold for switching between tablet and
2920 * clamshell mode.
2921 */
2922 int16_t lid_angle;
2923
2924 /*
2925 * Hysteresis degree to prevent fluctuations between
2926 * clamshell and tablet mode if lid angle keeps
2927 * changing around the threshold. Lid motion driver will
2928 * use lid_angle + hys_degree to trigger tablet mode and
2929 * lid_angle - hys_degree to trigger clamshell mode.
2930 */
2931 int16_t hys_degree;
2932 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002933
2934 /*
2935 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
2936 * Allow reading a single sensor's online calibration value.
2937 */
2938 struct __ec_todo_unpacked {
2939 uint8_t sensor_num;
2940 } online_calib_read;
2941
Yidi Lin42f79592020-09-21 18:04:10 +08002942 /*
2943 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
2944 */
2945 struct __ec_todo_unpacked {
2946 uint8_t sensor_num;
2947 uint8_t activity; /* enum motionsensor_activity */
2948 } get_activity;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002949 };
2950} __ec_todo_packed;
2951
Jett Rinkba2edaf2020-01-14 11:49:06 -07002952enum motion_sense_cmd_info_flags {
2953 /* The sensor supports online calibration */
2954 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
2955};
2956
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002957struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002958 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002959 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002960 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002961 /* Flags representing the motion sensor module. */
2962 uint8_t module_flags;
2963
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002964 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002965 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002966
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002967 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002968 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002969 * for holding all the data.
2970 */
2971 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002972 } dump;
2973
2974 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002975 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002976 /* Should be element of enum motionsensor_type. */
2977 uint8_t type;
2978
2979 /* Should be element of enum motionsensor_location. */
2980 uint8_t location;
2981
2982 /* Should be element of enum motionsensor_chip. */
2983 uint8_t chip;
2984 } info;
2985
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002986 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2987 struct __ec_todo_unpacked {
2988 /* Should be element of enum motionsensor_type. */
2989 uint8_t type;
2990
2991 /* Should be element of enum motionsensor_location. */
2992 uint8_t location;
2993
2994 /* Should be element of enum motionsensor_chip. */
2995 uint8_t chip;
2996
2997 /* Minimum sensor sampling frequency */
2998 uint32_t min_frequency;
2999
3000 /* Maximum sensor sampling frequency */
3001 uint32_t max_frequency;
3002
3003 /* Max number of sensor events that could be in fifo */
3004 uint32_t fifo_max_event_count;
3005 } info_3;
3006
Jett Rinkba2edaf2020-01-14 11:49:06 -07003007 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3008 struct __ec_align4 {
3009 /* Should be element of enum motionsensor_type. */
3010 uint8_t type;
3011
3012 /* Should be element of enum motionsensor_location. */
3013 uint8_t location;
3014
3015 /* Should be element of enum motionsensor_chip. */
3016 uint8_t chip;
3017
3018 /* Minimum sensor sampling frequency */
3019 uint32_t min_frequency;
3020
3021 /* Maximum sensor sampling frequency */
3022 uint32_t max_frequency;
3023
3024 /* Max number of sensor events that could be in fifo */
3025 uint32_t fifo_max_event_count;
3026
3027 /*
3028 * Should be elements of
3029 * enum motion_sense_cmd_info_flags
3030 */
3031 uint32_t flags;
3032 } info_4;
3033
Duncan Laurieeb316852015-12-01 18:51:18 -08003034 /* Used for MOTIONSENSE_CMD_DATA */
3035 struct ec_response_motion_sensor_data data;
3036
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003037 /*
3038 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003039 * MOTIONSENSE_CMD_SENSOR_RANGE,
3040 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3041 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3042 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003043 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003044 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003045 /* Current value of the parameter queried. */
3046 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003047 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
3048 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003050 /*
3051 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3052 * PERFORM_CALIB.
3053 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003054 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003055 int16_t temp;
3056 int16_t offset[3];
3057 } sensor_offset, perform_calib;
3058
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003059 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3060 struct __ec_todo_unpacked {
3061 int16_t temp;
3062 uint16_t scale[3];
3063 } sensor_scale;
3064
Duncan Laurieeb316852015-12-01 18:51:18 -08003065 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3066
3067 struct ec_response_motion_sense_fifo_data fifo_read;
3068
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003069 struct ec_response_online_calibration_data online_calib_read;
3070
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003071 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003072 uint16_t reserved;
3073 uint32_t enabled;
3074 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003075 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003076
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003077 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003078
Duncan Laurieeb316852015-12-01 18:51:18 -08003079 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003080 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003081 /*
3082 * Angle between 0 and 360 degree if available,
3083 * LID_ANGLE_UNRELIABLE otherwise.
3084 */
3085 uint16_t value;
3086 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003087
3088 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3089 struct __ec_todo_unpacked {
3090 /*
3091 * Lid angle threshold for switching between tablet and
3092 * clamshell mode.
3093 */
3094 uint16_t lid_angle;
3095
3096 /* Hysteresis degree. */
3097 uint16_t hys_degree;
3098 } tablet_mode_threshold;
3099
Yidi Lin42f79592020-09-21 18:04:10 +08003100 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3101 struct __ec_todo_unpacked {
3102 uint8_t state;
3103 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003104 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003105} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003106
3107/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003108/* Force lid open command */
3109
3110/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003111#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003112
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003113struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003114 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003115} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003116
3117/*****************************************************************************/
3118/* Configure the behavior of the power button */
3119#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3120
3121enum ec_config_power_button_flags {
3122 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003123 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003124};
3125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003126struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003127 /* See enum ec_config_power_button_flags */
3128 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003129} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003130
3131/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003132/* USB charging control commands */
3133
3134/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003135#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003136
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003137enum usb_charge_mode {
3138 /* Disable USB port. */
3139 USB_CHARGE_MODE_DISABLED,
3140 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3141 USB_CHARGE_MODE_SDP2,
3142 /* Set USB port to Charging Downstream Port, BC 1.2. */
3143 USB_CHARGE_MODE_CDP,
3144 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3145 USB_CHARGE_MODE_DCP_SHORT,
3146 /* Enable USB port (for dumb ports). */
3147 USB_CHARGE_MODE_ENABLED,
3148 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3149 USB_CHARGE_MODE_DEFAULT,
3150
3151 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003152};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003153
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003154enum usb_suspend_charge {
3155 /* Enable charging in suspend */
3156 USB_ALLOW_SUSPEND_CHARGE,
3157 /* Disable charging in suspend */
3158 USB_DISALLOW_SUSPEND_CHARGE
3159};
3160
3161struct ec_params_usb_charge_set_mode {
3162 uint8_t usb_port_id;
3163 uint8_t mode:7; /* enum usb_charge_mode */
3164 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
3165} __ec_align1;
3166
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003167/*****************************************************************************/
3168/* Persistent storage for host */
3169
3170/* Maximum bytes that can be read/written in a single command */
3171#define EC_PSTORE_SIZE_MAX 64
3172
3173/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003174#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003175
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003176struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003177 /* Persistent storage size, in bytes */
3178 uint32_t pstore_size;
3179 /* Access size; read/write offset and size must be a multiple of this */
3180 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003181} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003182
3183/*
3184 * Read persistent storage
3185 *
3186 * Response is params.size bytes of data.
3187 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003188#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003189
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003190struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003191 uint32_t offset; /* Byte offset to read */
3192 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003193} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003194
3195/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003196#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003197
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003198struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003199 uint32_t offset; /* Byte offset to write */
3200 uint32_t size; /* Size to write in bytes */
3201 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003202} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003203
3204/*****************************************************************************/
3205/* Real-time clock */
3206
3207/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003208struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003209 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003210} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003211
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003212struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003213 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003214} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003215
3216/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003217#define EC_CMD_RTC_GET_VALUE 0x0044
3218#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003219
3220/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003221#define EC_CMD_RTC_SET_VALUE 0x0046
3222#define EC_CMD_RTC_SET_ALARM 0x0047
3223
3224/* Pass as time param to SET_ALARM to clear the current alarm */
3225#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003226
3227/*****************************************************************************/
3228/* Port80 log access */
3229
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003230/* Maximum entries that can be read/written in a single command */
3231#define EC_PORT80_SIZE_MAX 32
3232
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003233/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003234#define EC_CMD_PORT80_LAST_BOOT 0x0048
3235#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003236
3237enum ec_port80_subcmd {
3238 EC_PORT80_GET_INFO = 0,
3239 EC_PORT80_READ_BUFFER,
3240};
3241
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003242struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003243 uint16_t subcmd;
3244 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003245 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003246 uint32_t offset;
3247 uint32_t num_entries;
3248 } read_buffer;
3249 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003250} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003251
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003252struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003253 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003254 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003255 uint32_t writes;
3256 uint32_t history_size;
3257 uint32_t last_boot;
3258 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003259 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003260 uint16_t codes[EC_PORT80_SIZE_MAX];
3261 } data;
3262 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003263} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003264
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003265struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003266 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003267} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003268
3269/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003270/* Temporary secure storage for host verified boot use */
3271
3272/* Number of bytes in a vstore slot */
3273#define EC_VSTORE_SLOT_SIZE 64
3274
3275/* Maximum number of vstore slots */
3276#define EC_VSTORE_SLOT_MAX 32
3277
3278/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003279#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003280struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003281 /* Indicates which slots are locked */
3282 uint32_t slot_locked;
3283 /* Total number of slots available */
3284 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003285} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003286
3287/*
3288 * Read temporary secure storage
3289 *
3290 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3291 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003292#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003293
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003294struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003295 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003296} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003297
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003298struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003299 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003300} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003301
3302/*
3303 * Write temporary secure storage and lock it.
3304 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003305#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003306
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003307struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003308 uint8_t slot; /* Slot to write to */
3309 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003310} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003311
3312/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003313/* Thermal engine commands. Note that there are two implementations. We'll
3314 * reuse the command number, but the data and behavior is incompatible.
3315 * Version 0 is what originally shipped on Link.
3316 * Version 1 separates the CPU thermal limits from the fan control.
3317 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003318
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003319#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3320#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003321
Duncan Laurie93e24442014-01-06 12:30:52 -08003322/* The version 0 structs are opaque. You have to know what they are for
3323 * the get/set commands to make any sense.
3324 */
3325
3326/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003327struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003328 uint8_t sensor_type;
3329 uint8_t threshold_id;
3330 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003331} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003332
Duncan Laurie93e24442014-01-06 12:30:52 -08003333/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003334struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003335 uint8_t sensor_type;
3336 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003337} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003338
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003339struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003340 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003341} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003342
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003343
Duncan Laurie93e24442014-01-06 12:30:52 -08003344/* The version 1 structs are visible. */
3345enum ec_temp_thresholds {
3346 EC_TEMP_THRESH_WARN = 0,
3347 EC_TEMP_THRESH_HIGH,
3348 EC_TEMP_THRESH_HALT,
3349
3350 EC_TEMP_THRESH_COUNT
3351};
3352
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003353/*
3354 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003355 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003356 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003357 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3358 * hysteresis.
3359 * For example,
3360 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3361 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3362 * EC will throttle ap when temperature >= 301 K, and release throttling when
3363 * temperature <= 299 K.
3364 *
3365 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3366 * For example,
3367 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3368 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3369 * EC will throttle ap when temperature >= 301 K, and release throttling when
3370 * temperature <= 294 K.
3371 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003372 * Note that this structure is a sub-structure of
3373 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003374 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003375struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003376 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003377 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003378 uint32_t temp_fan_off; /* no active cooling needed */
3379 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003380} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003381
3382/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003383struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003384 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003385} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003386/* This returns a struct ec_thermal_config */
3387
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003388/*
3389 * Version 1 - set config for one sensor.
3390 * Use read-modify-write for best results!
3391 */
3392struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003393 uint32_t sensor_num;
3394 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003395} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003396/* This returns no data */
3397
3398/****************************************************************************/
3399
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003400/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003401#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003402
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003403/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003404struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003405 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003406} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003407
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003408/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003409#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3410#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003411
3412/*
3413 * The original TMP006 calibration only needed four params, but now we need
3414 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3415 * the params opaque. The v1 "get" response will include the algorithm number
3416 * and how many params it requires. That way we can change the EC code without
3417 * needing to update this file. We can also use a different algorithm on each
3418 * sensor.
3419 */
3420
3421/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003422struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003423 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003424} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003425
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003426/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003427struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003428 float s0;
3429 float b0;
3430 float b1;
3431 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003432} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003433
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003434struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003435 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003436 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003437 float s0;
3438 float b0;
3439 float b1;
3440 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003441} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003442
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003443/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003444struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003445 uint8_t algorithm;
3446 uint8_t num_params;
3447 uint8_t reserved[2];
3448 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003449} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003450
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003451struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003452 uint8_t index;
3453 uint8_t algorithm;
3454 uint8_t num_params;
3455 uint8_t reserved;
3456 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003457} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003458
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003459
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003460/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003461#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003462
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003463struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003464 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003465} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003466
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003467struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003468 int32_t t; /* In 1/100 K */
3469 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003470} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003471
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003472/*****************************************************************************/
3473/* MKBP - Matrix KeyBoard Protocol */
3474
3475/*
3476 * Read key state
3477 *
3478 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3479 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003480 *
3481 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3482 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3483 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003484 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003485#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003486
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003487/*
3488 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3489 */
3490#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003491
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003492struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003493 uint32_t rows;
3494 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003495 /* Formerly "switches", which was 0. */
3496 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003497} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003498
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003499struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003500 uint8_t info_type;
3501 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003502} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003503
3504enum ec_mkbp_info_type {
3505 /*
3506 * Info about the keyboard matrix: number of rows and columns.
3507 *
3508 * Returns struct ec_response_mkbp_info.
3509 */
3510 EC_MKBP_INFO_KBD = 0,
3511
3512 /*
3513 * For buttons and switches, info about which specifically are
3514 * supported. event_type must be set to one of the values in enum
3515 * ec_mkbp_event.
3516 *
3517 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3518 * bitmask indicating which buttons or switches are present. See the
3519 * bit inidices below.
3520 */
3521 EC_MKBP_INFO_SUPPORTED = 1,
3522
3523 /*
3524 * Instantaneous state of buttons and switches.
3525 *
3526 * event_type must be set to one of the values in enum ec_mkbp_event.
3527 *
3528 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3529 * indicating the current state of the keyboard matrix.
3530 *
3531 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3532 * event state.
3533 *
3534 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3535 * state of supported buttons.
3536 *
3537 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3538 * state of supported switches.
3539 */
3540 EC_MKBP_INFO_CURRENT = 2,
3541};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003542
3543/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003544#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003545
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003546struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003547 uint8_t col;
3548 uint8_t row;
3549 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003550} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003551
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003552#define EC_CMD_GET_KEYBOARD_ID 0x0063
3553
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003554struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003555 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003556} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003557
3558enum keyboard_id {
3559 KEYBOARD_ID_UNSUPPORTED = 0,
3560 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3561};
3562
Duncan Laurie433432b2013-06-03 10:38:22 -07003563/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003564#define EC_CMD_MKBP_SET_CONFIG 0x0064
3565#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003566
3567/* flags */
3568enum mkbp_config_flags {
3569 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3570};
3571
3572enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003573 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3574 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3575 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3576 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3577 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3578 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3579 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003580};
3581
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003582/*
3583 * Configuration for our key scanning algorithm.
3584 *
3585 * Note that this is used as a sub-structure of
3586 * ec_{params/response}_mkbp_get_config.
3587 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003588struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003589 uint32_t valid_mask; /* valid fields */
3590 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3591 uint8_t valid_flags; /* which flags are valid */
3592 uint16_t scan_period_us; /* period between start of scans */
3593 /* revert to interrupt mode after no activity for this long */
3594 uint32_t poll_timeout_us;
3595 /*
3596 * minimum post-scan relax time. Once we finish a scan we check
3597 * the time until we are due to start the next one. If this time is
3598 * shorter this field, we use this instead.
3599 */
3600 uint16_t min_post_scan_delay_us;
3601 /* delay between setting up output and waiting for it to settle */
3602 uint16_t output_settle_us;
3603 uint16_t debounce_down_us; /* time for debounce on key down */
3604 uint16_t debounce_up_us; /* time for debounce on key up */
3605 /* maximum depth to allow for fifo (0 = no keyscan output) */
3606 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003607} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003608
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003609struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003610 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003611} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003612
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003613struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003614 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003615} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003616
3617/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003618#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003619
3620enum ec_keyscan_seq_cmd {
3621 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3622 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3623 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3624 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3625 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3626};
3627
3628enum ec_collect_flags {
3629 /*
3630 * Indicates this scan was processed by the EC. Due to timing, some
3631 * scans may be skipped.
3632 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003633 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003634};
3635
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003636struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003637 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003638} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003639
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003640struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003641 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3642 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003643 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003644 uint8_t active; /* still active */
3645 uint8_t num_items; /* number of items */
3646 /* Current item being presented */
3647 uint8_t cur_item;
3648 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003649 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003650 /*
3651 * Absolute time for this scan, measured from the
3652 * start of the sequence.
3653 */
3654 uint32_t time_us;
3655 uint8_t scan[0]; /* keyscan data */
3656 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003657 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003658 uint8_t start_item; /* First item to return */
3659 uint8_t num_items; /* Number of items to return */
3660 } collect;
3661 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003662} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003663
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003664struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003665 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003666 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003667 uint8_t num_items; /* Number of items */
3668 /* Data for each item */
3669 struct ec_collect_item item[0];
3670 } collect;
3671 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003672} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003673
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003674/*
3675 * Get the next pending MKBP event.
3676 *
3677 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3678 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003679#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003680
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003681#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3682
3683/*
3684 * We use the most significant bit of the event type to indicate to the host
3685 * that the EC has more MKBP events available to provide.
3686 */
3687#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3688
3689/* The mask to apply to get the raw event type */
3690#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3691
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003692enum ec_mkbp_event {
3693 /* Keyboard matrix changed. The event data is the new matrix state. */
3694 EC_MKBP_EVENT_KEY_MATRIX = 0,
3695
3696 /* New host event. The event data is 4 bytes of host event flags. */
3697 EC_MKBP_EVENT_HOST_EVENT = 1,
3698
Duncan Laurieeb316852015-12-01 18:51:18 -08003699 /* New Sensor FIFO data. The event data is fifo_info structure. */
3700 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3701
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003702 /* The state of the non-matrixed buttons have changed. */
3703 EC_MKBP_EVENT_BUTTON = 3,
3704
3705 /* The state of the switches have changed. */
3706 EC_MKBP_EVENT_SWITCH = 4,
3707
3708 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3709 EC_MKBP_EVENT_FINGERPRINT = 5,
3710
3711 /*
3712 * Sysrq event: send emulated sysrq. The event data is sysrq,
3713 * corresponding to the key to be pressed.
3714 */
3715 EC_MKBP_EVENT_SYSRQ = 6,
3716
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003717 /*
3718 * New 64-bit host event.
3719 * The event data is 8 bytes of host event flags.
3720 */
3721 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3722
3723 /* Notify the AP that something happened on CEC */
3724 EC_MKBP_EVENT_CEC_EVENT = 8,
3725
3726 /* Send an incoming CEC message to the AP */
3727 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3728
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003729 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3730 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3731
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003732 /* New online calibration values are available. */
3733 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3734
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003735 /* Number of MKBP events */
3736 EC_MKBP_EVENT_COUNT,
3737};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003738BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003739
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003740union __ec_align_offset1 ec_response_get_next_data {
3741 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003742
3743 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003744 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003745 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003746
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003747 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003748 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003749 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003750 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003751 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003752
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003753 uint32_t buttons;
3754
3755 uint32_t switches;
3756
3757 uint32_t fp_events;
3758
3759 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003760
3761 /* CEC events from enum mkbp_cec_event */
3762 uint32_t cec_events;
3763};
3764
3765union __ec_align_offset1 ec_response_get_next_data_v1 {
3766 uint8_t key_matrix[16];
3767
3768 /* Unaligned */
3769 uint32_t host_event;
3770 uint64_t host_event64;
3771
3772 struct __ec_todo_unpacked {
3773 /* For aligning the fifo_info */
3774 uint8_t reserved[3];
3775 struct ec_response_motion_sense_fifo_info info;
3776 } sensor_fifo;
3777
3778 uint32_t buttons;
3779
3780 uint32_t switches;
3781
3782 uint32_t fp_events;
3783
3784 uint32_t sysrq;
3785
3786 /* CEC events from enum mkbp_cec_event */
3787 uint32_t cec_events;
3788
3789 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003790};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003791BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003792
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003793struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003794 uint8_t event_type;
3795 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003796 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003797} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003798
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003799struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003800 uint8_t event_type;
3801 /* Followed by event data if any */
3802 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003803} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003804
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003805/* Bit indices for buttons and switches.*/
3806/* Buttons */
3807#define EC_MKBP_POWER_BUTTON 0
3808#define EC_MKBP_VOL_UP 1
3809#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003810#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003811
3812/* Switches */
3813#define EC_MKBP_LID_OPEN 0
3814#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003815#define EC_MKBP_BASE_ATTACHED 2
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003816#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003817
Gwendal Grignou880b4582016-06-20 08:49:25 -07003818/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003819#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003820
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003821struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003822 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003823} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003824
3825/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3826#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003827#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3828#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3829#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3830 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3831#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3832#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3833#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3834 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003835#define EC_MKBP_FP_ENROLL BIT(27)
3836#define EC_MKBP_FP_MATCH BIT(28)
3837#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3838#define EC_MKBP_FP_FINGER_UP BIT(30)
3839#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003840/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3841#define EC_MKBP_FP_ERR_ENROLL_OK 0
3842#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3843#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3844#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3845#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3846/* Can be used to detect if image was usable for enrollment or not. */
3847#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3848/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3849#define EC_MKBP_FP_ERR_MATCH_NO 0
3850#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003851#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003852#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3853#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3854#define EC_MKBP_FP_ERR_MATCH_YES 1
3855#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3856#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3857
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003859#define EC_CMD_MKBP_WAKE_MASK 0x0069
3860enum ec_mkbp_event_mask_action {
3861 /* Retrieve the value of a wake mask. */
3862 GET_WAKE_MASK = 0,
3863
3864 /* Set the value of a wake mask. */
3865 SET_WAKE_MASK,
3866};
3867
3868enum ec_mkbp_mask_type {
3869 /*
3870 * These are host events sent via MKBP.
3871 *
3872 * Some examples are:
3873 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3874 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3875 *
3876 * The only things that should be in this mask are:
3877 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3878 */
3879 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3880
3881 /*
3882 * These are MKBP events. Some examples are:
3883 *
3884 * EC_MKBP_EVENT_KEY_MATRIX
3885 * EC_MKBP_EVENT_SWITCH
3886 *
3887 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3888 */
3889 EC_MKBP_EVENT_WAKE_MASK,
3890};
3891
3892struct ec_params_mkbp_event_wake_mask {
3893 /* One of enum ec_mkbp_event_mask_action */
3894 uint8_t action;
3895
3896 /*
3897 * Which MKBP mask are you interested in acting upon? This is one of
3898 * ec_mkbp_mask_type.
3899 */
3900 uint8_t mask_type;
3901
3902 /* If setting a new wake mask, this contains the mask to set. */
3903 uint32_t new_wake_mask;
3904};
3905
3906struct ec_response_mkbp_event_wake_mask {
3907 uint32_t wake_mask;
3908};
3909
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003910/*****************************************************************************/
3911/* Temperature sensor commands */
3912
3913/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003914#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003915
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003916struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003917 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003918} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003919
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003920struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003921 char sensor_name[32];
3922 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003923} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003924
3925/*****************************************************************************/
3926
3927/*
3928 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3929 * commands accidentally sent to the wrong interface. See the ACPI section
3930 * below.
3931 */
3932
3933/*****************************************************************************/
3934/* Host event commands */
3935
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003936
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003937/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003938/*
3939 * Host event mask params and response structures, shared by all of the host
3940 * event commands below.
3941 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003942struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003943 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003944} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003945
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003946struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003947 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003948} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003949
3950/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003951#define EC_CMD_HOST_EVENT_GET_B 0x0087
3952#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3953#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3954#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003955
3956/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003957#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3958#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3959#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3960#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3961#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003962
Jenny TC1dfc2c32017-12-14 14:24:39 +05303963/*
3964 * Unified host event programming interface - Should be used by newer versions
3965 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003966 *
3967 * EC returns:
3968 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
3969 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05303970 */
3971
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003972struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303973
3974 /* Action requested by host - one of enum ec_host_event_action. */
3975 uint8_t action;
3976
3977 /*
3978 * Mask type that the host requested the action on - one of
3979 * enum ec_host_event_mask_type.
3980 */
3981 uint8_t mask_type;
3982
3983 /* Set to 0, ignore on read */
3984 uint16_t reserved;
3985
3986 /* Value to be used in case of set operations. */
3987 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003988} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303989
3990/*
3991 * Response structure returned by EC_CMD_HOST_EVENT.
3992 * Update the value on a GET request. Set to 0 on GET/CLEAR
3993 */
3994
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003995struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303996
3997 /* Mask value in case of get operation */
3998 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003999} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304000
4001enum ec_host_event_action {
4002 /*
4003 * params.value is ignored. Value of mask_type populated
4004 * in response.value
4005 */
4006 EC_HOST_EVENT_GET,
4007
4008 /* Bits in params.value are set */
4009 EC_HOST_EVENT_SET,
4010
4011 /* Bits in params.value are cleared */
4012 EC_HOST_EVENT_CLEAR,
4013};
4014
4015enum ec_host_event_mask_type {
4016
4017 /* Main host event copy */
4018 EC_HOST_EVENT_MAIN,
4019
4020 /* Copy B of host events */
4021 EC_HOST_EVENT_B,
4022
4023 /* SCI Mask */
4024 EC_HOST_EVENT_SCI_MASK,
4025
4026 /* SMI Mask */
4027 EC_HOST_EVENT_SMI_MASK,
4028
4029 /* Mask of events that should be always reported in hostevents */
4030 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4031
4032 /* Active wake mask */
4033 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4034
4035 /* Lazy wake mask for S0ix */
4036 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4037
4038 /* Lazy wake mask for S3 */
4039 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4040
4041 /* Lazy wake mask for S5 */
4042 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4043};
4044
4045#define EC_CMD_HOST_EVENT 0x00A4
4046
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004047/*****************************************************************************/
4048/* Switch commands */
4049
4050/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004051#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004053struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004054 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004055} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004056
4057/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004058#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004059#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004060
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004061/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004062struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004063 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004064} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004065
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004066/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004067struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004068 /* Flags to enable now */
4069 uint8_t now_flags;
4070
4071 /* Which flags to copy from now_flags */
4072 uint8_t now_mask;
4073
4074 /*
4075 * Flags to leave enabled in S3, if they're on at the S0->S3
4076 * transition. (Other flags will be disabled by the S0->S3
4077 * transition.)
4078 */
4079 uint8_t suspend_flags;
4080
4081 /* Which flags to copy from suspend_flags */
4082 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004083} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004084
4085/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004086struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004087 /* Flags to enable now */
4088 uint8_t now_flags;
4089
4090 /* Flags to leave enabled in S3 */
4091 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004092} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004094/*****************************************************************************/
4095/* GPIO commands. Only available on EC if write protect has been disabled. */
4096
4097/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004098#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004099
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004100struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004101 char name[32];
4102 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004103} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004104
4105/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004106#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004107
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004108/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004109struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004110 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004111} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004112
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004113struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004114 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004115} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004116
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004117/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004118struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004119 uint8_t subcmd;
4120 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004121 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004122 char name[32];
4123 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004124 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004125 uint8_t index;
4126 } get_info;
4127 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004128} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004129
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004130struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004131 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004132 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004133 uint8_t val;
4134 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004135 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004136 uint8_t val;
4137 char name[32];
4138 uint32_t flags;
4139 } get_info;
4140 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004141} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004142
4143enum gpio_get_subcmd {
4144 EC_GPIO_GET_BY_NAME = 0,
4145 EC_GPIO_GET_COUNT = 1,
4146 EC_GPIO_GET_INFO = 2,
4147};
4148
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004149/*****************************************************************************/
4150/* I2C commands. Only available when flash write protect is unlocked. */
4151
Duncan Laurie93e24442014-01-06 12:30:52 -08004152/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004153 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4154 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4155 *
4156 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004157 */
4158
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004159/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004160#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004161
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004162struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004163 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004164 uint8_t read_size; /* Either 8 or 16. */
4165 uint8_t port;
4166 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004167} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004168
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004169struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004170 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004171} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004172
4173/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004174#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004175
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004176struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004177 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004178 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004179 uint8_t write_size; /* Either 8 or 16. */
4180 uint8_t port;
4181 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004182} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004183
4184/*****************************************************************************/
4185/* Charge state commands. Only available when flash write protect unlocked. */
4186
Duncan Laurie93e24442014-01-06 12:30:52 -08004187/* Force charge state machine to stop charging the battery or force it to
4188 * discharge the battery.
4189 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004190#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08004191#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004192
Duncan Laurie93e24442014-01-06 12:30:52 -08004193enum ec_charge_control_mode {
4194 CHARGE_CONTROL_NORMAL = 0,
4195 CHARGE_CONTROL_IDLE,
4196 CHARGE_CONTROL_DISCHARGE,
4197};
4198
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004199struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004200 uint32_t mode; /* enum charge_control_mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004201} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004202
4203/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004204
4205/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004206#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004207
4208/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004209 * Read data from the saved snapshot. If the subcmd parameter is
4210 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4211 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4212 * end of the previous snapshot.
4213 *
4214 * The params are only looked at in version >= 1 of this command. Prior
4215 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004216 *
4217 * Response is null-terminated string. Empty string, if there is no more
4218 * remaining output.
4219 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004220#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004221
Duncan Laurieeb316852015-12-01 18:51:18 -08004222enum ec_console_read_subcmd {
4223 CONSOLE_READ_NEXT = 0,
4224 CONSOLE_READ_RECENT
4225};
4226
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004227struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004228 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004229} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004230
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004231/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004232
4233/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004234 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004235 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004236 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4237 * EC_RES_SUCCESS if the command was successful.
4238 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004239 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004240#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004241
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004242#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004243
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004244struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004245 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004246} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004247
Duncan Laurie433432b2013-06-03 10:38:22 -07004248/*****************************************************************************/
4249/* USB port mux control. */
4250
4251/*
4252 * Switch USB mux or return to automatic switching.
4253 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004254#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004255
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004256struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004257 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004258} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004259
4260/*****************************************************************************/
4261/* LDOs / FETs control. */
4262
4263enum ec_ldo_state {
4264 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4265 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4266};
4267
4268/*
4269 * Switch on/off a LDO.
4270 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004271#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004272
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004273struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004274 uint8_t index;
4275 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004276} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004277
4278/*
4279 * Get LDO state.
4280 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004281#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004282
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004283struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004284 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004285} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004286
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004287struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004288 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004289} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004290
4291/*****************************************************************************/
4292/* Power info. */
4293
4294/*
4295 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004296 *
4297 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004298 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004299#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004300
Jett Rinkba2edaf2020-01-14 11:49:06 -07004301/*
4302 * v1 of EC_CMD_POWER_INFO
4303 */
4304enum system_power_source {
4305 /*
4306 * Haven't established which power source is used yet,
4307 * or no presence signals are available
4308 */
4309 POWER_SOURCE_UNKNOWN = 0,
4310 /* System is running on battery alone */
4311 POWER_SOURCE_BATTERY = 1,
4312 /* System is running on A/C alone */
4313 POWER_SOURCE_AC = 2,
4314 /* System is running on A/C and battery */
4315 POWER_SOURCE_AC_BATTERY = 3,
4316};
4317
4318struct ec_response_power_info_v1 {
4319 /* enum system_power_source */
4320 uint8_t system_power_source;
4321 /* Battery state-of-charge, 0-100, 0 if not present */
4322 uint8_t battery_soc;
4323 /* AC Adapter 100% rating, Watts */
4324 uint8_t ac_adapter_100pct;
4325 /* AC Adapter 10ms rating, Watts */
4326 uint8_t ac_adapter_10ms;
4327 /* Battery 1C rating, derated */
4328 uint8_t battery_1cd;
4329 /* Rest of Platform average, Watts */
4330 uint8_t rop_avg;
4331 /* Rest of Platform peak, Watts */
4332 uint8_t rop_peak;
4333 /* Nominal charger efficiency, % */
4334 uint8_t nominal_charger_eff;
4335 /* Rest of Platform VR Average Efficiency, % */
4336 uint8_t rop_avg_eff;
4337 /* Rest of Platform VR Peak Efficiency, % */
4338 uint8_t rop_peak_eff;
4339 /* SoC VR Efficiency at Average level, % */
4340 uint8_t soc_avg_eff;
4341 /* SoC VR Efficiency at Peak level, % */
4342 uint8_t soc_peak_eff;
4343 /* Intel-specific items */
4344 struct {
4345 /* Battery's level of DBPT support: 0, 2 */
4346 uint8_t batt_dbpt_support_level;
4347 /*
4348 * Maximum peak power from battery (10ms), Watts
4349 * If DBPT is not supported, this is 0
4350 */
4351 uint8_t batt_dbpt_max_peak_power;
4352 /*
4353 * Sustained peak power from battery, Watts
4354 * If DBPT is not supported, this is 0
4355 */
4356 uint8_t batt_dbpt_sus_peak_power;
4357 } intel;
4358} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004359
4360/*****************************************************************************/
4361/* I2C passthru command */
4362
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004363#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004364
Duncan Laurie433432b2013-06-03 10:38:22 -07004365/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004366#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004367
4368/* Mask for address */
4369#define EC_I2C_ADDR_MASK 0x3ff
4370
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004371#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4372#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004373
4374/* Any error */
4375#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4376
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004377struct ec_params_i2c_passthru_msg {
4378 uint16_t addr_flags; /* I2C slave address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004379 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004380} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004381
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004382struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004383 uint8_t port; /* I2C port number */
4384 uint8_t num_msgs; /* Number of messages */
4385 struct ec_params_i2c_passthru_msg msg[];
4386 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004387} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004388
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004389struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004390 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4391 uint8_t num_msgs; /* Number of messages processed */
4392 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004393} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004394
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004395/*****************************************************************************/
4396/* Power button hang detect */
4397
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004398#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004399
4400/* Reasons to start hang detection timer */
4401/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004402#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004403
4404/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004405#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004406
4407 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004408#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004409
4410/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004411#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004412
4413/* Reasons to cancel hang detection */
4414
4415/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004416#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004417
4418/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004419#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004420
4421/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004422#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004423
4424/*
4425 * If this flag is set, all the other fields are ignored, and the hang detect
4426 * timer is started. This provides the AP a way to start the hang timer
4427 * without reconfiguring any of the other hang detect settings. Note that
4428 * you must previously have configured the timeouts.
4429 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004430#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004431
4432/*
4433 * If this flag is set, all the other fields are ignored (including
4434 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4435 * without reconfiguring any of the other hang detect settings.
4436 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004437#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004438
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004439struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004440 /* Flags; see EC_HANG_* */
4441 uint32_t flags;
4442
4443 /* Timeout in msec before generating host event, if enabled */
4444 uint16_t host_event_timeout_msec;
4445
4446 /* Timeout in msec before generating warm reboot, if enabled */
4447 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004448} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004449
4450/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004451/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004452
4453/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004454 * This is the single catch-all host command to exchange data regarding the
4455 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004456 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004457#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004458
4459/* Subcommands for this host command */
4460enum charge_state_command {
4461 CHARGE_STATE_CMD_GET_STATE,
4462 CHARGE_STATE_CMD_GET_PARAM,
4463 CHARGE_STATE_CMD_SET_PARAM,
4464 CHARGE_STATE_NUM_CMDS
4465};
4466
4467/*
4468 * Known param numbers are defined here. Ranges are reserved for board-specific
4469 * params, which are handled by the particular implementations.
4470 */
4471enum charge_state_params {
4472 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4473 CS_PARAM_CHG_CURRENT, /* charger current limit */
4474 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4475 CS_PARAM_CHG_STATUS, /* charger-specific status */
4476 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004477 CS_PARAM_LIMIT_POWER, /*
4478 * Check if power is limited due to
4479 * low battery and / or a weak external
4480 * charger. READ ONLY.
4481 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004482 /* How many so far? */
4483 CS_NUM_BASE_PARAMS,
4484
4485 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4486 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4487 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4488
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004489 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4490 CS_PARAM_DEBUG_MIN = 0x20000,
4491 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4492 CS_PARAM_DEBUG_MANUAL_MODE,
4493 CS_PARAM_DEBUG_SEEMS_DEAD,
4494 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4495 CS_PARAM_DEBUG_BATT_REMOVED,
4496 CS_PARAM_DEBUG_MANUAL_CURRENT,
4497 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4498 CS_PARAM_DEBUG_MAX = 0x2ffff,
4499
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004500 /* Other custom param ranges go here... */
4501};
4502
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004503struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004504 uint8_t cmd; /* enum charge_state_command */
4505 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004506 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004507
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004508 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004509 uint32_t param; /* enum charge_state_param */
4510 } get_param;
4511
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004512 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004513 uint32_t param; /* param to set */
4514 uint32_t value; /* value to set */
4515 } set_param;
4516 };
Yidi Lin42f79592020-09-21 18:04:10 +08004517 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004518} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004519
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004520struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004521 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004522 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004523 int ac;
4524 int chg_voltage;
4525 int chg_current;
4526 int chg_input_current;
4527 int batt_state_of_charge;
4528 } get_state;
4529
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004530 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004531 uint32_t value;
4532 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004533
4534 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004535 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004536} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004537
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004538
Duncan Laurie433432b2013-06-03 10:38:22 -07004539/*
4540 * Set maximum battery charging current.
4541 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004542#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004543
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004544struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004545 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004546} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004547
4548/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004549 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004550 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004551#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004552
Duncan Laurieeb316852015-12-01 18:51:18 -08004553/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004554struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004555 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4556 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004557} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004558
Duncan Laurieeb316852015-12-01 18:51:18 -08004559#define EC_POWER_LIMIT_NONE 0xffff
4560
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004561/*
4562 * Set maximum voltage & current of a dedicated charge port
4563 */
4564#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4565
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004566struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004567 uint16_t current_lim; /* in mA */
4568 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004569} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004570
Duncan Laurieeb316852015-12-01 18:51:18 -08004571/*****************************************************************************/
4572/* Hibernate/Deep Sleep Commands */
4573
4574/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004575#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004576
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004577struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004578 /*
4579 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4580 * current settings without changing them.
4581 */
4582 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004583} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004584
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004585struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004586 /*
4587 * The current time in seconds in which the system has been in the G3
4588 * state. This value is reset if the EC transitions out of G3.
4589 */
4590 uint32_t time_g3;
4591
4592 /*
4593 * The current time remaining in seconds until the EC should hibernate.
4594 * This value is also reset if the EC transitions out of G3.
4595 */
4596 uint32_t time_remaining;
4597
4598 /*
4599 * The current time in seconds that the EC should wait in G3 before
4600 * hibernating.
4601 */
4602 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004603} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004604
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004605/* Inform the EC when entering a sleep state */
4606#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4607
4608enum host_sleep_event {
4609 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4610 HOST_SLEEP_EVENT_S3_RESUME = 2,
4611 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004612 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4613 /* S3 suspend with additional enabled wake sources */
4614 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004615};
4616
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004617struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004618 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004619} __ec_align1;
4620
4621/*
4622 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4623 * transition failures
4624 */
4625#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4626
4627/* Disable timeout detection for this sleep transition */
4628#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4629
4630struct ec_params_host_sleep_event_v1 {
4631 /* The type of sleep being entered or exited. */
4632 uint8_t sleep_event;
4633
4634 /* Padding */
4635 uint8_t reserved;
4636 union {
4637 /* Parameters that apply for suspend messages. */
4638 struct {
4639 /*
4640 * The timeout in milliseconds between when this message
4641 * is received and when the EC will declare sleep
4642 * transition failure if the sleep signal is not
4643 * asserted.
4644 */
4645 uint16_t sleep_timeout_ms;
4646 } suspend_params;
4647
4648 /* No parameters for non-suspend messages. */
4649 };
4650} __ec_align2;
4651
4652/* A timeout occurred when this bit is set */
4653#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4654
4655/*
4656 * The mask defining which bits correspond to the number of sleep transitions,
4657 * as well as the maximum number of suspend line transitions that will be
4658 * reported back to the host.
4659 */
4660#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4661
4662struct ec_response_host_sleep_event_v1 {
4663 union {
4664 /* Response fields that apply for resume messages. */
4665 struct {
4666 /*
4667 * The number of sleep power signal transitions that
4668 * occurred since the suspend message. The high bit
4669 * indicates a timeout occurred.
4670 */
4671 uint32_t sleep_transitions;
4672 } resume_response;
4673
4674 /* No response fields for non-resume messages. */
4675 };
4676} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004677
4678/*****************************************************************************/
4679/* Device events */
4680#define EC_CMD_DEVICE_EVENT 0x00AA
4681
4682enum ec_device_event {
4683 EC_DEVICE_EVENT_TRACKPAD,
4684 EC_DEVICE_EVENT_DSP,
4685 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004686 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004687};
4688
4689enum ec_device_event_param {
4690 /* Get and clear pending device events */
4691 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4692 /* Get device event mask */
4693 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4694 /* Set device event mask */
4695 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4696};
4697
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004698#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004699
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004700struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004701 uint32_t event_mask;
4702 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004703} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004705struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004706 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004707} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004708
Duncan Laurie433432b2013-06-03 10:38:22 -07004709/*****************************************************************************/
4710/* Smart battery pass-through */
4711
4712/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004713#define EC_CMD_SB_READ_WORD 0x00B0
4714#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004715
4716/* Get / Set string smart battery parameters
4717 * formatted as SMBUS "block".
4718 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004719#define EC_CMD_SB_READ_BLOCK 0x00B2
4720#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004721
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004722struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004723 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004724} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004725
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004726struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004727 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004728} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004729
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004730struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004731 uint8_t reg;
4732 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004733} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004734
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004735struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004736 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004737} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004738
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004739struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004740 uint8_t reg;
4741 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004742} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004743
4744/*****************************************************************************/
4745/* Battery vendor parameters
4746 *
4747 * Get or set vendor-specific parameters in the battery. Implementations may
4748 * differ between boards or batteries. On a set operation, the response
4749 * contains the actual value set, which may be rounded or clipped from the
4750 * requested value.
4751 */
4752
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004753#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004754
4755enum ec_battery_vendor_param_mode {
4756 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4757 BATTERY_VENDOR_PARAM_MODE_SET,
4758};
4759
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004760struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004761 uint32_t param;
4762 uint32_t value;
4763 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004764} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004765
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004766struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004767 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004768} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004769
4770/*****************************************************************************/
4771/*
4772 * Smart Battery Firmware Update Commands
4773 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004774#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004775
4776enum ec_sb_fw_update_subcmd {
4777 EC_SB_FW_UPDATE_PREPARE = 0x0,
4778 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4779 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4780 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4781 EC_SB_FW_UPDATE_END = 0x4,
4782 EC_SB_FW_UPDATE_STATUS = 0x5,
4783 EC_SB_FW_UPDATE_PROTECT = 0x6,
4784 EC_SB_FW_UPDATE_MAX = 0x7,
4785};
4786
4787#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4788#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4789#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4790
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004791struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004792 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4793 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004794} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004795
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004796struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004797 struct ec_sb_fw_update_header hdr;
4798 union {
4799 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4800 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4801 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4802 /* EC_SB_FW_UPDATE_END = 0x4 */
4803 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4804 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004805 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004806
4807 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004808 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004809 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4810 } write;
4811 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004812} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004813
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004814struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004815 union {
4816 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004817 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004818 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4819 } info;
4820
4821 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004822 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004823 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4824 } status;
4825 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004826} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004827
4828/*
4829 * Entering Verified Boot Mode Command
4830 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4831 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004832 *
4833 * EC no longer needs to know what mode vboot has entered,
4834 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004835 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004836#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004837
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004838struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004839 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004840} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004841
4842#define VBOOT_MODE_NORMAL 0
4843#define VBOOT_MODE_DEVELOPER 1
4844#define VBOOT_MODE_RECOVERY 2
4845
Duncan Laurie433432b2013-06-03 10:38:22 -07004846/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004847/*
4848 * I2C passthru protection command: Protects I2C tunnels against access on
4849 * certain addresses (board-specific).
4850 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004851#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004852
4853enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004854 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
4855 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
4856 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07004857};
4858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004859struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004860 uint8_t subcmd;
4861 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004862} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004863
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004864struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004865 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004866} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004867
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004868
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004869/*****************************************************************************/
4870/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004871 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004872 *
4873 * These commands are for sending and receiving message via HDMI CEC
4874 */
4875
4876#define MAX_CEC_MSG_LEN 16
4877
4878/* CEC message from the AP to be written on the CEC bus */
4879#define EC_CMD_CEC_WRITE_MSG 0x00B8
4880
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004881/**
4882 * struct ec_params_cec_write - Message to write to the CEC bus
4883 * @msg: message content to write to the CEC bus
4884 */
4885struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004886 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004887} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004888
4889/* Set various CEC parameters */
4890#define EC_CMD_CEC_SET 0x00BA
4891
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004892/**
4893 * struct ec_params_cec_set - CEC parameters set
4894 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4895 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4896 * or 1 to enable CEC functionality, in case cmd is
4897 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4898 * address between 0 and 15 or 0xff to unregister
4899 */
4900struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004901 uint8_t cmd; /* enum cec_command */
4902 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004903} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004904
4905/* Read various CEC parameters */
4906#define EC_CMD_CEC_GET 0x00BB
4907
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004908/**
4909 * struct ec_params_cec_get - CEC parameters get
4910 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4911 */
4912struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004913 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004914} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004915
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004916/**
4917 * struct ec_response_cec_get - CEC parameters get response
4918 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4919 * disabled or 1 if CEC functionality is enabled,
4920 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4921 * configured logical address between 0 and 15 or 0xff if unregistered
4922 */
4923struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004924 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004925} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004926
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004927/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004928enum cec_command {
4929 /* CEC reading, writing and events enable */
4930 CEC_CMD_ENABLE,
4931 /* CEC logical address */
4932 CEC_CMD_LOGICAL_ADDRESS,
4933};
4934
4935/* Events from CEC to AP */
4936enum mkbp_cec_event {
4937 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004938 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004939 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004940 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004941};
4942
Gwendal Grignou880b4582016-06-20 08:49:25 -07004943/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004944
Jett Rinkba2edaf2020-01-14 11:49:06 -07004945/* Commands for audio codec. */
4946#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004947
Jett Rinkba2edaf2020-01-14 11:49:06 -07004948enum ec_codec_subcmd {
4949 EC_CODEC_GET_CAPABILITIES = 0x0,
4950 EC_CODEC_GET_SHM_ADDR = 0x1,
4951 EC_CODEC_SET_SHM_ADDR = 0x2,
4952 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004953};
4954
Jett Rinkba2edaf2020-01-14 11:49:06 -07004955enum ec_codec_cap {
4956 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
4957 EC_CODEC_CAP_WOV_LANG_SHM = 1,
4958 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004959};
4960
Jett Rinkba2edaf2020-01-14 11:49:06 -07004961enum ec_codec_shm_id {
4962 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
4963 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
4964 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004965};
4966
Jett Rinkba2edaf2020-01-14 11:49:06 -07004967enum ec_codec_shm_type {
4968 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
4969 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004970};
4971
Jett Rinkba2edaf2020-01-14 11:49:06 -07004972struct __ec_align1 ec_param_ec_codec_get_shm_addr {
4973 uint8_t shm_id;
4974 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004975};
4976
Jett Rinkba2edaf2020-01-14 11:49:06 -07004977struct __ec_align4 ec_param_ec_codec_set_shm_addr {
4978 uint64_t phys_addr;
4979 uint32_t len;
4980 uint8_t shm_id;
4981 uint8_t reserved[3];
4982};
4983
4984struct __ec_align4 ec_param_ec_codec {
4985 uint8_t cmd; /* enum ec_codec_subcmd */
4986 uint8_t reserved[3];
4987
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004988 union {
Jett Rinkba2edaf2020-01-14 11:49:06 -07004989 struct ec_param_ec_codec_get_shm_addr
4990 get_shm_addr_param;
4991 struct ec_param_ec_codec_set_shm_addr
4992 set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004993 };
4994};
4995
Jett Rinkba2edaf2020-01-14 11:49:06 -07004996struct __ec_align4 ec_response_ec_codec_get_capabilities {
4997 uint32_t capabilities;
4998};
4999
5000struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5001 uint64_t phys_addr;
5002 uint32_t len;
5003 uint8_t type;
5004 uint8_t reserved[3];
5005};
5006
5007/*****************************************************************************/
5008
5009/* Commands for DMIC on audio codec. */
5010#define EC_CMD_EC_CODEC_DMIC 0x00BD
5011
5012enum ec_codec_dmic_subcmd {
5013 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5014 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5015 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5016 EC_CODEC_DMIC_SUBCMD_COUNT,
5017};
5018
5019enum ec_codec_dmic_channel {
5020 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5021 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5022 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5023 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5024 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5025 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5026 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5027 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5028 EC_CODEC_DMIC_CHANNEL_COUNT,
5029};
5030
5031struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5032 uint8_t channel; /* enum ec_codec_dmic_channel */
5033 uint8_t gain;
5034 uint8_t reserved[2];
5035};
5036
5037struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5038 uint8_t channel; /* enum ec_codec_dmic_channel */
5039 uint8_t reserved[3];
5040};
5041
5042struct __ec_align4 ec_param_ec_codec_dmic {
5043 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5044 uint8_t reserved[3];
5045
5046 union {
5047 struct ec_param_ec_codec_dmic_set_gain_idx
5048 set_gain_idx_param;
5049 struct ec_param_ec_codec_dmic_get_gain_idx
5050 get_gain_idx_param;
5051 };
5052};
5053
5054struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5055 uint8_t max_gain;
5056};
5057
5058struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5059 uint8_t gain;
5060};
5061
5062/*****************************************************************************/
5063
5064/* Commands for I2S RX on audio codec. */
5065
5066#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5067
5068enum ec_codec_i2s_rx_subcmd {
5069 EC_CODEC_I2S_RX_ENABLE = 0x0,
5070 EC_CODEC_I2S_RX_DISABLE = 0x1,
5071 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5072 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5073 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005074 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005075 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5076};
5077
5078enum ec_codec_i2s_rx_sample_depth {
5079 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5080 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5081 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5082};
5083
5084enum ec_codec_i2s_rx_daifmt {
5085 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5086 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5087 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5088 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5089};
5090
5091struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5092 uint8_t depth;
5093 uint8_t reserved[3];
5094};
5095
5096struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5097 uint8_t left;
5098 uint8_t right;
5099 uint8_t reserved[2];
5100};
5101
5102struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5103 uint8_t daifmt;
5104 uint8_t reserved[3];
5105};
5106
5107struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5108 uint32_t bclk;
5109};
5110
5111struct __ec_align4 ec_param_ec_codec_i2s_rx {
5112 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5113 uint8_t reserved[3];
5114
5115 union {
5116 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5117 set_sample_depth_param;
5118 struct ec_param_ec_codec_i2s_rx_set_daifmt
5119 set_daifmt_param;
5120 struct ec_param_ec_codec_i2s_rx_set_bclk
5121 set_bclk_param;
5122 };
5123};
5124
5125/*****************************************************************************/
5126/* Commands for WoV on audio codec. */
5127
5128#define EC_CMD_EC_CODEC_WOV 0x00BF
5129
5130enum ec_codec_wov_subcmd {
5131 EC_CODEC_WOV_SET_LANG = 0x0,
5132 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5133 EC_CODEC_WOV_GET_LANG = 0x2,
5134 EC_CODEC_WOV_ENABLE = 0x3,
5135 EC_CODEC_WOV_DISABLE = 0x4,
5136 EC_CODEC_WOV_READ_AUDIO = 0x5,
5137 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5138 EC_CODEC_WOV_SUBCMD_COUNT,
5139};
5140
5141/*
5142 * @hash is SHA256 of the whole language model.
5143 * @total_len indicates the length of whole language model.
5144 * @offset is the cursor from the beginning of the model.
5145 * @buf is the packet buffer.
5146 * @len denotes how many bytes in the buf.
5147 */
5148struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5149 uint8_t hash[32];
5150 uint32_t total_len;
5151 uint32_t offset;
5152 uint8_t buf[128];
5153 uint32_t len;
5154};
5155
5156struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5157 uint8_t hash[32];
5158 uint32_t total_len;
5159};
5160
5161struct __ec_align4 ec_param_ec_codec_wov {
5162 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5163 uint8_t reserved[3];
5164
5165 union {
5166 struct ec_param_ec_codec_wov_set_lang
5167 set_lang_param;
5168 struct ec_param_ec_codec_wov_set_lang_shm
5169 set_lang_shm_param;
5170 };
5171};
5172
5173struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5174 uint8_t hash[32];
5175};
5176
5177struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5178 uint8_t buf[128];
5179 uint32_t len;
5180};
5181
5182struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5183 uint32_t offset;
5184 uint32_t len;
5185};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005186
5187/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005188/* Commands for PoE PSE controller */
5189
5190#define EC_CMD_PSE 0x00C0
5191
5192enum ec_pse_subcmd {
5193 EC_PSE_STATUS = 0x0,
5194 EC_PSE_ENABLE = 0x1,
5195 EC_PSE_DISABLE = 0x2,
5196 EC_PSE_SUBCMD_COUNT,
5197};
5198
5199struct __ec_align1 ec_params_pse {
5200 uint8_t cmd; /* enum ec_pse_subcmd */
5201 uint8_t port; /* PSE port */
5202};
5203
5204enum ec_pse_status {
5205 EC_PSE_STATUS_DISABLED = 0x0,
5206 EC_PSE_STATUS_ENABLED = 0x1,
5207 EC_PSE_STATUS_POWERED = 0x2,
5208};
5209
5210struct __ec_align1 ec_response_pse_status {
5211 uint8_t status; /* enum ec_pse_status */
5212};
5213
5214/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005215/* System commands */
5216
5217/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005218 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5219 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005220 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005221#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005222
5223/* Command */
5224enum ec_reboot_cmd {
5225 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005226 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005227 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005228 /* (command 3 was jump to RW-B) */
5229 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005230 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08005231 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Yidi Lin42f79592020-09-21 18:04:10 +08005232 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_IDLE flag */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005233 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005234};
5235
5236/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005237#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5238#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5239#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005240
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005241struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005242 uint8_t cmd; /* enum ec_reboot_cmd */
5243 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005244} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005245
Duncan Laurie433432b2013-06-03 10:38:22 -07005246/*
5247 * Get information on last EC panic.
5248 *
5249 * Returns variable-length platform-dependent panic information. See panic.h
5250 * for details.
5251 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005252#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005253
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005254/*****************************************************************************/
5255/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005256 * Special commands
5257 *
5258 * These do not follow the normal rules for commands. See each command for
5259 * details.
5260 */
5261
5262/*
5263 * Reboot NOW
5264 *
5265 * This command will work even when the EC LPC interface is busy, because the
5266 * reboot command is processed at interrupt level. Note that when the EC
5267 * reboots, the host will reboot too, so there is no response to this command.
5268 *
5269 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5270 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005271#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005272
5273/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005274 * Resend last response (not supported on LPC).
5275 *
5276 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5277 * there was no previous command, or the previous command's response was too
5278 * big to save.
5279 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005280#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005281
5282/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005283 * This header byte on a command indicate version 0. Any header byte less
5284 * than this means that we are talking to an old EC which doesn't support
5285 * versioning. In that case, we assume version 0.
5286 *
5287 * Header bytes greater than this indicate a later version. For example,
5288 * EC_CMD_VERSION0 + 1 means we are using version 1.
5289 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005290 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005291 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005292#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005293
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005294/*****************************************************************************/
5295/*
5296 * PD commands
5297 *
5298 * These commands are for PD MCU communication.
5299 */
5300
5301/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005302#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005303#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005304
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005305enum pd_charge_state {
5306 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
5307 PD_CHARGE_NONE, /* No charging allowed */
5308 PD_CHARGE_5V, /* 5V charging only */
5309 PD_CHARGE_MAX /* Charge at max voltage */
5310};
5311
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005312/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005313#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005314
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005315struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005316 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005317 int8_t batt_soc; /* battery state of charge */
5318 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005319} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005320
5321/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005322#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5323#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
5324#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
5325#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5326#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5327#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5328#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08005329#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
5330 PD_STATUS_TCPC_ALERT_1 | \
5331 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005332struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005333 uint32_t curr_lim_ma; /* input current limit */
5334 uint16_t status; /* PD MCU status */
5335 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005336} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005337
5338/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005339#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005340
5341/* PD MCU host event status bits */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005342#define PD_EVENT_UPDATE_DEVICE BIT(0)
5343#define PD_EVENT_POWER_CHANGE BIT(1)
5344#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5345#define PD_EVENT_DATA_SWAP BIT(3)
5346#define PD_EVENT_TYPEC BIT(4)
5347
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005348struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005349 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005350} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005351
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005352/*
5353 * Set USB type-C port role and muxes
5354 *
5355 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5356 *
5357 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5358 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005359#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005360
5361enum usb_pd_control_role {
5362 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5363 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5364 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5365 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5366 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005367 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005368 USB_PD_CTRL_ROLE_COUNT
5369};
5370
5371enum usb_pd_control_mux {
5372 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5373 USB_PD_CTRL_MUX_NONE = 1,
5374 USB_PD_CTRL_MUX_USB = 2,
5375 USB_PD_CTRL_MUX_DP = 3,
5376 USB_PD_CTRL_MUX_DOCK = 4,
5377 USB_PD_CTRL_MUX_AUTO = 5,
5378 USB_PD_CTRL_MUX_COUNT
5379};
5380
Duncan Laurieeb316852015-12-01 18:51:18 -08005381enum usb_pd_control_swap {
5382 USB_PD_CTRL_SWAP_NONE = 0,
5383 USB_PD_CTRL_SWAP_DATA = 1,
5384 USB_PD_CTRL_SWAP_POWER = 2,
5385 USB_PD_CTRL_SWAP_VCONN = 3,
5386 USB_PD_CTRL_SWAP_COUNT
5387};
5388
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005389struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005390 uint8_t port;
5391 uint8_t role;
5392 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005393 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005394} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005395
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005396#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5397#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
5398#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005399
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005400#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5401#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5402#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5403#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5404#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5405#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005406#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */
Duncan Laurieeb316852015-12-01 18:51:18 -08005407
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005408struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005409 uint8_t enabled;
5410 uint8_t role;
5411 uint8_t polarity;
5412 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005413} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005414
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005415struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005416 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005417 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005418 uint8_t polarity;
5419 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005420} __ec_align1;
5421
Jett Rinkba2edaf2020-01-14 11:49:06 -07005422/* Possible port partner connections based on CC line states */
5423enum pd_cc_states {
5424 PD_CC_NONE = 0, /* No port partner attached */
5425
5426 /* From DFP perspective */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005427 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005428 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5429 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5430 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
5431
5432 /* From UFP perspective */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005433 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005434 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005435};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005436
Jett Rinkba2edaf2020-01-14 11:49:06 -07005437/* Active/Passive Cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005438#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005439/* Optical/Non-optical cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005440#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005441/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005442#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
5443/* Active Link Uni-Direction */
5444#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005446struct ec_response_usb_pd_control_v2 {
5447 uint8_t enabled;
5448 uint8_t role;
5449 uint8_t polarity;
5450 char state[32];
Jett Rinkba2edaf2020-01-14 11:49:06 -07005451 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5452 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005453 uint8_t reserved; /* Reserved for future use */
5454 uint8_t control_flags; /* USB_PD_CTRL_*flags */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005455 uint8_t cable_speed; /* TBT_SS_* cable speed */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005456 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005457} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005458
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005459#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005460
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005461/* Maximum number of PD ports on a device, num_ports will be <= this */
5462#define EC_USB_PD_MAX_PORTS 8
5463
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005464struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005465 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005466} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005467
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005468#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005469
5470#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005471struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005472 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005473} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005474
5475enum usb_chg_type {
5476 USB_CHG_TYPE_NONE,
5477 USB_CHG_TYPE_PD,
5478 USB_CHG_TYPE_C,
5479 USB_CHG_TYPE_PROPRIETARY,
5480 USB_CHG_TYPE_BC12_DCP,
5481 USB_CHG_TYPE_BC12_CDP,
5482 USB_CHG_TYPE_BC12_SDP,
5483 USB_CHG_TYPE_OTHER,
5484 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005485 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005486 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005487};
5488enum usb_power_roles {
5489 USB_PD_PORT_POWER_DISCONNECTED,
5490 USB_PD_PORT_POWER_SOURCE,
5491 USB_PD_PORT_POWER_SINK,
5492 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5493};
5494
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005495struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005496 uint16_t voltage_max;
5497 uint16_t voltage_now;
5498 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005499 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005500} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005502struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005503 uint8_t role;
5504 uint8_t type;
5505 uint8_t dualrole;
5506 uint8_t reserved1;
5507 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005508 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005509} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005510
Yidi Lin42f79592020-09-21 18:04:10 +08005511
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005512/*
5513 * This command will return the number of USB PD charge port + the number
5514 * of dedicated port present.
5515 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5516 */
5517#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005518struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005519 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005520} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005521
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005522/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005523#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005524
5525enum usb_pd_fw_update_cmds {
5526 USB_PD_FW_REBOOT,
5527 USB_PD_FW_FLASH_ERASE,
5528 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005529 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005530};
5531
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005532struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005533 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005534 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005535 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005536 uint32_t size; /* Size to write in bytes */
5537 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005538} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005539
5540/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005541#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005542/* RW hash is first 20 bytes of SHA-256 of RW section */
5543#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005544struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005545 uint16_t dev_id;
5546 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005547 uint8_t reserved; /*
5548 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005549 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005550 * Should have been reserved[2].
5551 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005552 uint32_t current_image; /* One of ec_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005553} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005554
5555/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005556#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005557
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005558struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005559 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005560} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005561
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005562/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005563#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005564struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005565 uint16_t vid; /* USB-IF VID */
5566 uint16_t pid; /* USB-IF PID */
5567 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005568} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005569
5570/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005571#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005572
5573/* Negative port parameters have special meaning */
5574enum usb_pd_override_ports {
5575 OVERRIDE_DONT_CHARGE = -2,
5576 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005577 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005578};
5579
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005580struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005581 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005582} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005583
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005584/*
5585 * Read (and delete) one entry of PD event log.
5586 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5587 * future non-PD logs that use the same internal EC event_log.
5588 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005589#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005590
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005591struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005592 uint32_t timestamp; /* relative timestamp in milliseconds */
5593 uint8_t type; /* event type : see PD_EVENT_xx below */
5594 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5595 uint16_t data; /* type-defined data payload */
5596 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005597} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005598
5599/* The timestamp is the microsecond counter shifted to get about a ms. */
5600#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5601
Duncan Laurieeb316852015-12-01 18:51:18 -08005602#define PD_LOG_SIZE_MASK 0x1f
5603#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005604#define PD_LOG_PORT_SHIFT 5
5605#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5606 ((size) & PD_LOG_SIZE_MASK))
5607#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5608#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5609
5610/* PD event log : entry types */
5611/* PD MCU events */
5612#define PD_EVENT_MCU_BASE 0x00
5613#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5614#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5615/* Reserved for custom board event */
5616#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5617/* PD generic accessory events */
5618#define PD_EVENT_ACC_BASE 0x20
5619#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5620#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5621/* PD power supply events */
5622#define PD_EVENT_PS_BASE 0x40
5623#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5624/* PD video dongles events */
5625#define PD_EVENT_VIDEO_BASE 0x60
5626#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5627#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5628/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005629#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005630
5631/*
5632 * PD_EVENT_MCU_CHARGE event definition :
5633 * the payload is "struct usb_chg_measures"
5634 * the data field contains the port state flags as defined below :
5635 */
5636/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005637#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005638/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005639#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005640/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005641#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005642/* Charger type */
5643#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005644#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005645/* Power delivery role */
5646#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5647
5648/*
5649 * PD_EVENT_PS_FAULT data field flags definition :
5650 */
5651#define PS_FAULT_OCP 1
5652#define PS_FAULT_FAST_OCP 2
5653#define PS_FAULT_OVP 3
5654#define PS_FAULT_DISCH 4
5655
5656/*
5657 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5658 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005659struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005660 uint8_t major;
5661 uint8_t minor;
5662 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005663} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005664
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005665struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005666 uint8_t family[2];
5667 uint8_t chipid[2];
5668 struct mcdp_version irom;
5669 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005670} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005671
5672/* struct mcdp_info field decoding */
5673#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5674#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5675
5676/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005677#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005678struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005679 uint16_t svid_idx; /* SVID index to get */
5680 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005681} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005682
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005683struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005684 uint16_t svid; /* SVID */
5685 uint16_t opos; /* Object Position */
5686 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005687} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005688
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005689#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005690
5691enum pd_mode_cmd {
5692 PD_EXIT_MODE = 0,
5693 PD_ENTER_MODE = 1,
5694 /* Not a command. Do NOT remove. */
5695 PD_MODE_CMD_COUNT,
5696};
5697
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005698struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005699 uint32_t cmd; /* enum pd_mode_cmd */
5700 uint16_t svid; /* SVID to set */
5701 uint8_t opos; /* Object Position */
5702 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005703} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005704
5705/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005706#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005707
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005708struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005709 uint8_t type; /* event type : see PD_EVENT_xx above */
5710 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005711} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005712
Yidi Lin42f79592020-09-21 18:04:10 +08005713
Gwendal Grignou880b4582016-06-20 08:49:25 -07005714/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005715#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005716
5717enum ec_pd_control_cmd {
5718 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5719 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5720 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005721 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5722 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005723};
5724
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005725struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005726 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005727 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005728} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005729
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005730/* Get info about USB-C SS muxes */
5731#define EC_CMD_USB_PD_MUX_INFO 0x011A
5732
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005733struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005734 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005735} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005736
5737/* Flags representing mux state */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005738#define USB_PD_MUX_NONE 0 /* Open switch */
5739#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5740#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5741#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5742#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5743#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
5744#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
5745#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005746#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
5747
5748/* USB-C Dock connected */
5749#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005750
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005751struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005752 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005753} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005754
5755#define EC_CMD_PD_CHIP_INFO 0x011B
5756
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005757struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005758 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005759 /*
5760 * Fetch the live chip info or hard-coded + cached chip info
5761 * 0: hardcoded value for VID/PID, cached value for FW version
5762 * 1: live chip value for VID/PID/FW Version
5763 */
5764 uint8_t live;
5765} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005766
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005767struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005768 uint16_t vendor_id;
5769 uint16_t product_id;
5770 uint16_t device_id;
5771 union {
5772 uint8_t fw_version_string[8];
5773 uint64_t fw_version_number;
5774 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005775} __ec_align2;
5776
5777struct ec_response_pd_chip_info_v1 {
5778 uint16_t vendor_id;
5779 uint16_t product_id;
5780 uint16_t device_id;
5781 union {
5782 uint8_t fw_version_string[8];
5783 uint64_t fw_version_number;
5784 };
5785 union {
5786 uint8_t min_req_fw_version_string[8];
5787 uint64_t min_req_fw_version_number;
5788 };
5789} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005790
5791/* Run RW signature verification and get status */
5792#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5793
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005794struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005795 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005796} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005797
5798/* For controlling RWSIG task */
5799#define EC_CMD_RWSIG_ACTION 0x011D
5800
5801enum rwsig_action {
5802 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5803 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5804};
5805
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005806struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005807 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005808} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005809
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005810/* Run verification on a slot */
5811#define EC_CMD_EFS_VERIFY 0x011E
5812
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005813struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005814 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005815} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005816
5817/*
5818 * Retrieve info from Cros Board Info store. Response is based on the data
5819 * type. Integers return a uint32. Strings return a string, using the response
5820 * size to determine how big it is.
5821 */
5822#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5823/*
5824 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5825 * hardware write-protect enabled.
5826 */
5827#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5828
Daisuke Nojirif984a052018-02-15 12:38:15 -08005829enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005830 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5831 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5832 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005833 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005834 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005835 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005836 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005837 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08005838 /* Second Source Factory Cache */
5839 CBI_TAG_SSFC = 8, /* uint32_t bit field */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005840 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005841};
5842
5843/*
5844 * Flags to control read operation
5845 *
5846 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5847 * write was successful without reboot.
5848 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005849#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005850
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005851struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005852 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005853 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005854} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005855
5856/*
5857 * Flags to control write behavior.
5858 *
5859 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5860 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005861 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005862 * will be initialized to zero first.
5863 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005864#define CBI_SET_NO_SYNC BIT(0)
5865#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005866
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005867struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08005868 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005869 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005870 uint32_t size; /* Data size */
5871 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005872} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005873
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005874/*
5875 * Information about resets of the AP by the EC and the EC's own uptime.
5876 */
5877#define EC_CMD_GET_UPTIME_INFO 0x0121
5878
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005879/* EC reset causes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005880#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
5881#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
5882#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
5883#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
5884#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
5885#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
5886#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
5887#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
5888#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
5889#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
5890#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
5891#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
5892#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
5893#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
5894 * previous boot
5895 */
5896#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
5897#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
5898#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
5899#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
5900#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005901#define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This
5902 * enables PD in RO for Chromebox.
5903 */
Yidi Lin42f79592020-09-21 18:04:10 +08005904#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
5905#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
5906#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005907
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005908/*
5909 * Reason codes used by the AP after a shutdown to figure out why it was reset
5910 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
5911 * compatibility:
5912 * - New entries must be inserted prior to the _COUNT field
5913 * - If an existing entry is no longer in service, it must be replaced with a
5914 * RESERVED entry instead.
5915 * - The semantic meaning of an entry should not change.
5916 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
5917 */
5918enum chipset_reset_reason {
5919 CHIPSET_RESET_BEGIN = 0,
5920 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
5921 /* Custom reason defined by a board.c or baseboard.c file */
5922 CHIPSET_RESET_BOARD_CUSTOM,
5923 /* Believe that the AP has hung */
5924 CHIPSET_RESET_HANG_REBOOT,
5925 /* Reset by EC console command */
5926 CHIPSET_RESET_CONSOLE_CMD,
5927 /* Reset by EC host command */
5928 CHIPSET_RESET_HOST_CMD,
5929 /* Keyboard module reset key combination */
5930 CHIPSET_RESET_KB_SYSRESET,
5931 /* Keyboard module warm reboot */
5932 CHIPSET_RESET_KB_WARM_REBOOT,
5933 /* Debug module warm reboot */
5934 CHIPSET_RESET_DBG_WARM_REBOOT,
5935 /* I cannot self-terminate. You must lower me into the steel. */
5936 CHIPSET_RESET_AP_REQ,
5937 /* Reset as side-effect of startup sequence */
5938 CHIPSET_RESET_INIT,
5939 /* EC detected an AP watchdog event. */
5940 CHIPSET_RESET_AP_WATCHDOG,
5941
5942 CHIPSET_RESET_COUNT,
5943};
5944
5945/*
5946 * AP hard shutdowns are logged on the same path as resets.
5947 */
5948enum chipset_shutdown_reason {
5949 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
5950 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
5951 /* Forcing a shutdown as part of EC initialization */
5952 CHIPSET_SHUTDOWN_INIT,
5953 /* Custom reason on a per-board basis. */
5954 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
5955 /* This is a reason to inhibit startup, not cause shut down. */
5956 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
5957 /* A power_wait_signal is being asserted */
5958 CHIPSET_SHUTDOWN_WAIT,
5959 /* Critical battery level. */
5960 CHIPSET_SHUTDOWN_BATTERY_CRIT,
5961 /* Because you told me to. */
5962 CHIPSET_SHUTDOWN_CONSOLE_CMD,
5963 /* Forcing a shutdown to effect entry to G3. */
5964 CHIPSET_SHUTDOWN_G3,
5965 /* Force shutdown due to over-temperature. */
5966 CHIPSET_SHUTDOWN_THERMAL,
5967 /* Force a chipset shutdown from the power button through EC */
5968 CHIPSET_SHUTDOWN_BUTTON,
5969
5970 CHIPSET_SHUTDOWN_COUNT,
5971};
5972
5973
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005974struct ec_response_uptime_info {
5975 /*
5976 * Number of milliseconds since the last EC boot. Sysjump resets
5977 * typically do not restart the EC's time_since_boot epoch.
5978 *
5979 * WARNING: The EC's sense of time is much less accurate than the AP's
5980 * sense of time, in both phase and frequency. This timebase is similar
5981 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5982 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005983 uint32_t time_since_ec_boot_ms;
5984
5985 /*
5986 * Number of times the AP was reset by the EC since the last EC boot.
5987 * Note that the AP may be held in reset by the EC during the initial
5988 * boot sequence, such that the very first AP boot may count as more
5989 * than one here.
5990 */
5991 uint32_t ap_resets_since_ec_boot;
5992
5993 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005994 * The set of flags which describe the EC's most recent reset.
5995 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005996 */
5997 uint32_t ec_reset_flags;
5998
5999 /* Empty log entries have both the cause and timestamp set to zero. */
6000 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006001 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006002 uint16_t reset_cause;
6003
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006004 /* Reserved for protocol growth. */
6005 uint16_t reserved;
6006
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006007 /*
6008 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006009 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6010 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006011 */
6012 uint32_t reset_time_ms;
6013 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006014} __ec_align4;
6015
6016/*
6017 * Add entropy to the device secret (stored in the rollback region).
6018 *
6019 * Depending on the chip, the operation may take a long time (e.g. to erase
6020 * flash), so the commands are asynchronous.
6021 */
6022#define EC_CMD_ADD_ENTROPY 0x0122
6023
6024enum add_entropy_action {
6025 /* Add entropy to the current secret. */
6026 ADD_ENTROPY_ASYNC = 0,
6027 /*
6028 * Add entropy, and also make sure that the previous secret is erased.
6029 * (this can be implemented by adding entropy multiple times until
6030 * all rolback blocks have been overwritten).
6031 */
6032 ADD_ENTROPY_RESET_ASYNC = 1,
6033 /* Read back result from the previous operation. */
6034 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006035};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006036
6037struct ec_params_rollback_add_entropy {
6038 uint8_t action;
6039} __ec_align1;
6040
6041/*
6042 * Perform a single read of a given ADC channel.
6043 */
6044#define EC_CMD_ADC_READ 0x0123
6045
6046struct ec_params_adc_read {
6047 uint8_t adc_channel;
6048} __ec_align1;
6049
6050struct ec_response_adc_read {
6051 int32_t adc_value;
6052} __ec_align4;
6053
6054/*
6055 * Read back rollback info
6056 */
6057#define EC_CMD_ROLLBACK_INFO 0x0124
6058
6059struct ec_response_rollback_info {
6060 int32_t id; /* Incrementing number to indicate which region to use. */
6061 int32_t rollback_min_version;
6062 int32_t rw_rollback_version;
6063} __ec_align4;
6064
Yidi Lin42f79592020-09-21 18:04:10 +08006065
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006066/* Issue AP reset */
6067#define EC_CMD_AP_RESET 0x0125
6068
6069/*****************************************************************************/
6070/* Locate peripheral chips
6071 *
6072 * Return values:
6073 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6074 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6075 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6076 */
6077#define EC_CMD_LOCATE_CHIP 0x0126
6078
6079enum ec_chip_type {
6080 EC_CHIP_TYPE_CBI_EEPROM = 0,
6081 EC_CHIP_TYPE_TCPC = 1,
6082 EC_CHIP_TYPE_COUNT,
6083 EC_CHIP_TYPE_MAX = 0xFF,
6084};
6085
6086enum ec_bus_type {
6087 EC_BUS_TYPE_I2C = 0,
6088 EC_BUS_TYPE_EMBEDDED = 1,
6089 EC_BUS_TYPE_COUNT,
6090 EC_BUS_TYPE_MAX = 0xFF,
6091};
6092
6093struct ec_i2c_info {
6094 uint16_t port; /* Physical port for device */
6095 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
6096};
6097
6098struct ec_params_locate_chip {
6099 uint8_t type; /* enum ec_chip_type */
6100 uint8_t index; /* Specifies one instance of chip type */
6101 /* Used for type specific parameters in future */
6102 union {
6103 uint16_t reserved;
6104 };
6105} __ec_align2;
6106
Yidi Lin42f79592020-09-21 18:04:10 +08006107
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006108struct ec_response_locate_chip {
6109 uint8_t bus_type; /* enum ec_bus_type */
6110 uint8_t reserved; /* Aligning the following union to 2 bytes */
6111 union {
6112 struct ec_i2c_info i2c_info;
6113 };
6114} __ec_align2;
6115
Jett Rinkba2edaf2020-01-14 11:49:06 -07006116/*
6117 * Reboot AP on G3
6118 *
6119 * This command is used for validation purpose, where the AP needs to be
6120 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006121 * wake events.
6122 * - With command version 0:
6123 * AP reboots immediately from G3
6124 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6125 * - With command version 1:
6126 * AP reboots after the user specified delay
6127 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006128 */
6129#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6130
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006131struct ec_params_reboot_ap_on_g3_v1 {
6132 /* configurable delay in seconds in G3 state */
6133 uint32_t reboot_ap_at_g3_delay;
6134} __ec_align4;
6135
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006136/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006137/* Get PD port capabilities
6138 *
6139 * Returns the following static *capabilities* of the given port:
6140 * 1) Power role: source, sink, or dual. It is not anticipated that
6141 * future CrOS devices would ever be only a source, so the options are
6142 * sink or dual.
6143 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6144 * believe any CrOS device would support Try.SNK, so this would be source
6145 * or none).
6146 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6147 * for CrOS devices.
6148 */
6149#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6150
6151enum ec_pd_power_role_caps {
6152 EC_PD_POWER_ROLE_SOURCE = 0,
6153 EC_PD_POWER_ROLE_SINK = 1,
6154 EC_PD_POWER_ROLE_DUAL = 2,
6155};
6156
6157enum ec_pd_try_power_role_caps {
6158 EC_PD_TRY_POWER_ROLE_NONE = 0,
6159 EC_PD_TRY_POWER_ROLE_SINK = 1,
6160 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6161};
6162
6163enum ec_pd_data_role_caps {
6164 EC_PD_DATA_ROLE_DFP = 0,
6165 EC_PD_DATA_ROLE_UFP = 1,
6166 EC_PD_DATA_ROLE_DUAL = 2,
6167};
6168
6169/* From: power_manager/power_supply_properties.proto */
6170enum ec_pd_port_location {
6171 /* The location of the port is unknown, or there's only one port. */
6172 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6173
6174 /*
6175 * Various positions on the device. The first word describes the side of
6176 * the device where the port is located while the second clarifies the
6177 * position. For example, LEFT_BACK means the farthest-back port on the
6178 * left side, while BACK_LEFT means the leftmost port on the back of the
6179 * device.
6180 */
6181 EC_PD_PORT_LOCATION_LEFT = 1,
6182 EC_PD_PORT_LOCATION_RIGHT = 2,
6183 EC_PD_PORT_LOCATION_BACK = 3,
6184 EC_PD_PORT_LOCATION_FRONT = 4,
6185 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6186 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
6187 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
6188 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6189 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6190 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
6191};
6192
6193struct ec_params_get_pd_port_caps {
6194 uint8_t port; /* Which port to interrogate */
6195} __ec_align1;
6196
6197struct ec_response_get_pd_port_caps {
6198 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6199 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6200 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6201 uint8_t pd_port_location; /* enum ec_pd_port_location */
6202} __ec_align1;
6203
6204/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006205/*
6206 * Button press simulation
6207 *
6208 * This command is used to simulate a button press.
6209 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6210 * Time duration for which button needs to be pressed is an optional parameter.
6211 *
6212 * NOTE: This is only available on unlocked devices for testing purposes only.
6213 */
6214#define EC_CMD_BUTTON 0x0129
6215
6216struct ec_params_button {
6217 /* Button mask aligned to enum keyboard_button_type */
6218 uint32_t btn_mask;
6219
6220 /* Duration in milliseconds button needs to be pressed */
6221 uint32_t press_ms;
6222} __ec_align1;
6223
6224enum keyboard_button_type {
6225 KEYBOARD_BUTTON_POWER = 0,
6226 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
6227 KEYBOARD_BUTTON_VOLUME_UP = 2,
6228 KEYBOARD_BUTTON_RECOVERY = 3,
6229 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6230 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6231 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6232 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6233 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6234 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6235 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6236 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
6237
6238 KEYBOARD_BUTTON_COUNT
6239};
Yidi Lin42f79592020-09-21 18:04:10 +08006240
Rajat Jainc0495722020-04-02 23:58:35 -07006241/*****************************************************************************/
6242/*
6243 * "Get the Keyboard Config". An EC implementing this command is expected to be
6244 * vivaldi capable, i.e. can send action codes for the top row keys.
6245 * Additionally, capability to send function codes for the same keys is
6246 * optional and acceptable.
6247 *
6248 * Note: If the top row can generate both function and action codes by
6249 * using a dedicated Fn key, it does not matter whether the key sends
6250 * "function" or "action" codes by default. In both cases, the response
6251 * for this command will look the same.
6252 */
6253#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6254
6255/* Possible values for the top row keys */
6256enum action_key {
6257 TK_ABSENT = 0,
6258 TK_BACK = 1,
6259 TK_FORWARD = 2,
6260 TK_REFRESH = 3,
6261 TK_FULLSCREEN = 4,
6262 TK_OVERVIEW = 5,
6263 TK_BRIGHTNESS_DOWN = 6,
6264 TK_BRIGHTNESS_UP = 7,
6265 TK_VOL_MUTE = 8,
6266 TK_VOL_DOWN = 9,
6267 TK_VOL_UP = 10,
6268 TK_SNAPSHOT = 11,
6269 TK_PRIVACY_SCRN_TOGGLE = 12,
6270 TK_KBD_BKLIGHT_DOWN = 13,
6271 TK_KBD_BKLIGHT_UP = 14,
6272 TK_PLAY_PAUSE = 15,
6273 TK_NEXT_TRACK = 16,
6274 TK_PREV_TRACK = 17,
6275};
6276
6277/*
6278 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6279 * If this needs to change, please create a new version of the command.
6280 */
6281#define MAX_TOP_ROW_KEYS 15
6282#define MIN_TOP_ROW_KEYS 10
6283
6284/*
6285 * Is the keyboard capable of sending function keys *in addition to*
6286 * action keys. This is possible for e.g. if the keyboard has a
6287 * dedicated Fn key.
6288 */
6289#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
6290/*
6291 * Whether the keyboard has a dedicated numeric keyboard.
6292 */
6293#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
6294/*
6295 * Whether the keyboard has a screenlock key.
6296 */
6297#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
6298
6299struct ec_response_keybd_config {
6300 /*
6301 * Number of top row keys, excluding Esc and Screenlock.
6302 * If this is 0, all Vivaldi keyboard code is disabled.
6303 * (i.e. does not expose any tables to the kernel).
6304 */
6305 uint8_t num_top_row_keys;
6306
6307 /*
6308 * The action keys in the top row, in order from left to right.
6309 * The values are filled from enum action_key. Esc and Screenlock
6310 * keys are not considered part of top row keys.
6311 */
6312 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6313
6314 /* Capability flags */
6315 uint8_t capabilities;
6316
6317} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006318
Yidi Lin42f79592020-09-21 18:04:10 +08006319/*
6320 * Configure smart discharge
6321 */
6322#define EC_CMD_SMART_DISCHARGE 0x012B
6323
6324#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
6325
6326/* Discharge rates when the system is in cutoff or hibernation. */
6327struct discharge_rate {
6328 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6329 uint16_t hibern; /* Discharge rate (uA) in hibernation */
6330};
6331
6332struct smart_discharge_zone {
6333 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6334 int cutoff;
6335 /* When the capacity (mAh) is below this, EC stays up. */
6336 int stayup;
6337};
6338
6339struct ec_params_smart_discharge {
6340 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
6341 /*
6342 * Desired hours for the battery to survive before reaching 0%. Set to
6343 * zero to disable smart discharging. That is, the system hibernates as
6344 * soon as the G3 idle timer expires.
6345 */
6346 uint16_t hours_to_zero;
6347 /* Set both to zero to keep the current rates. */
6348 struct discharge_rate drate;
6349};
6350
6351struct ec_response_smart_discharge {
6352 uint16_t hours_to_zero;
6353 struct discharge_rate drate;
6354 struct smart_discharge_zone dzone;
6355};
6356
6357/*****************************************************************************/
6358/* Voltage regulator controls */
6359
6360/*
6361 * Get basic info of voltage regulator for given index.
6362 *
6363 * Returns the regulator name and supported voltage list in mV.
6364 */
6365#define EC_CMD_REGULATOR_GET_INFO 0x012C
6366
6367/* Maximum length of regulator name */
6368#define EC_REGULATOR_NAME_MAX_LEN 16
6369
6370/* Maximum length of the supported voltage list. */
6371#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6372
6373struct ec_params_regulator_get_info {
6374 uint32_t index;
6375} __ec_align4;
6376
6377struct ec_response_regulator_get_info {
6378 char name[EC_REGULATOR_NAME_MAX_LEN];
6379 uint16_t num_voltages;
6380 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6381} __ec_align2;
6382
6383/*
6384 * Configure the regulator as enabled / disabled.
6385 */
6386#define EC_CMD_REGULATOR_ENABLE 0x012D
6387
6388struct ec_params_regulator_enable {
6389 uint32_t index;
6390 uint8_t enable;
6391} __ec_align4;
6392
6393/*
6394 * Query if the regulator is enabled.
6395 *
6396 * Returns 1 if the regulator is enabled, 0 if not.
6397 */
6398#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6399
6400struct ec_params_regulator_is_enabled {
6401 uint32_t index;
6402} __ec_align4;
6403
6404struct ec_response_regulator_is_enabled {
6405 uint8_t enabled;
6406} __ec_align1;
6407
6408/*
6409 * Set voltage for the voltage regulator within the range specified.
6410 *
6411 * The driver should select the voltage in range closest to min_mv.
6412 *
6413 * Also note that this might be called before the regulator is enabled, and the
6414 * setting should be in effect after the regulator is enabled.
6415 */
6416#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6417
6418struct ec_params_regulator_set_voltage {
6419 uint32_t index;
6420 uint32_t min_mv;
6421 uint32_t max_mv;
6422} __ec_align4;
6423
6424/*
6425 * Get the currently configured voltage for the voltage regulator.
6426 *
6427 * Note that this might be called before the regulator is enabled, and this
6428 * should return the configured output voltage if the regulator is enabled.
6429 */
6430#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6431
6432struct ec_params_regulator_get_voltage {
6433 uint32_t index;
6434} __ec_align4;
6435
6436struct ec_response_regulator_get_voltage {
6437 uint32_t voltage_mv;
6438} __ec_align4;
6439
6440/*
6441 * Gather all discovery information for the given port and partner type.
6442 *
6443 * Note that if discovery has not yet completed, only the currently completed
6444 * responses will be filled in. If the discovery data structures are changed
6445 * in the process of the command running, BUSY will be returned.
6446 *
6447 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6448 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6449 * maximum parameter size.
6450 */
6451#define EC_CMD_TYPEC_DISCOVERY 0x0131
6452
6453enum typec_partner_type {
6454 TYPEC_PARTNER_SOP = 0,
6455 TYPEC_PARTNER_SOP_PRIME = 1,
6456};
6457
6458struct ec_params_typec_discovery {
6459 uint8_t port;
6460 uint8_t partner_type; /* enum typec_partner_type */
6461} __ec_align1;
6462
6463struct svid_mode_info {
6464 uint16_t svid;
6465 uint16_t mode_count; /* Number of modes partner sent */
6466 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6467};
6468
6469struct ec_response_typec_discovery {
6470 uint8_t identity_count; /* Number of identity VDOs partner sent */
6471 uint8_t svid_count; /* Number of SVIDs partner sent */
6472 uint16_t reserved;
6473 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6474 struct svid_mode_info svids[0];
6475} __ec_align1;
6476
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006477/* USB Type-C commands for AP-controlled device policy. */
6478#define EC_CMD_TYPEC_CONTROL 0x0132
6479
6480enum typec_control_command {
6481 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6482 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006483 TYPEC_CONTROL_COMMAND_ENTER_MODE,
6484};
6485
6486/* Modes (USB or alternate) that a type-C port may enter. */
6487enum typec_mode {
6488 TYPEC_MODE_DP,
6489 TYPEC_MODE_TBT,
6490 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006491};
6492
6493struct ec_params_typec_control {
6494 uint8_t port;
6495 uint8_t command; /* enum typec_control_command */
6496 uint16_t reserved;
6497
6498 /*
6499 * This section will be interpreted based on |command|. Define a
6500 * placeholder structure to avoid having to increase the size and bump
6501 * the command version when adding new sub-commands.
6502 */
6503 union {
6504 uint32_t clear_events_mask;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006505 uint8_t mode_to_enter; /* enum typec_mode */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006506 uint8_t placeholder[128];
6507 };
6508} __ec_align1;
6509
6510/*
6511 * Gather all status information for a port.
6512 *
6513 * Note: this covers many of the return fields from the deprecated
6514 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6515 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6516 * EC_CMD_USB_PD_CONTROL command.
6517 *
6518 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006519 */
6520#define EC_CMD_TYPEC_STATUS 0x0133
6521
6522/*
6523 * Power role.
6524 *
6525 * Note this is also used for PD header creation, and values align to those in
6526 * the Power Delivery Specification Revision 3.0 (See
6527 * 6.2.1.1.4 Port Power Role).
6528 */
6529enum pd_power_role {
6530 PD_ROLE_SINK = 0,
6531 PD_ROLE_SOURCE = 1
6532};
6533
6534/*
6535 * Data role.
6536 *
6537 * Note this is also used for PD header creation, and the first two values
6538 * align to those in the Power Delivery Specification Revision 3.0 (See
6539 * 6.2.1.1.6 Port Data Role).
6540 */
6541enum pd_data_role {
6542 PD_ROLE_UFP = 0,
6543 PD_ROLE_DFP = 1,
6544 PD_ROLE_DISCONNECTED = 2,
6545};
6546
6547enum pd_vconn_role {
6548 PD_ROLE_VCONN_OFF = 0,
6549 PD_ROLE_VCONN_SRC = 1,
6550};
6551
6552/*
6553 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6554 * regardless of whether a debug accessory is connected.
6555 */
6556enum tcpc_cc_polarity {
6557 /*
6558 * _CCx: is used to indicate the polarity while not connected to
6559 * a Debug Accessory. Only one CC line will assert a resistor and
6560 * the other will be open.
6561 */
6562 POLARITY_CC1 = 0,
6563 POLARITY_CC2 = 1,
6564
6565 /*
6566 * _CCx_DTS is used to indicate the polarity while connected to a
6567 * SRC Debug Accessory. Assert resistors on both lines.
6568 */
6569 POLARITY_CC1_DTS = 2,
6570 POLARITY_CC2_DTS = 3,
6571
6572 /*
6573 * The current TCPC code relies on these specific POLARITY values.
6574 * Adding in a check to verify if the list grows for any reason
6575 * that this will give a hint that other places need to be
6576 * adjusted.
6577 */
6578 POLARITY_COUNT
6579};
6580
6581#define MODE_DP_PIN_A BIT(0)
6582#define MODE_DP_PIN_B BIT(1)
6583#define MODE_DP_PIN_C BIT(2)
6584#define MODE_DP_PIN_D BIT(3)
6585#define MODE_DP_PIN_E BIT(4)
6586#define MODE_DP_PIN_F BIT(5)
6587#define MODE_DP_PIN_ALL GENMASK(5, 0)
6588
6589#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6590#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
6591
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006592/*
6593 * Encode and decode for BCD revision response
6594 *
6595 * Note: the major revision set is written assuming that the value given is the
6596 * Specification Revision from the PD header, which currently only maps to PD
6597 * 1.0-3.0 with the major revision being one greater than the binary value.
6598 */
6599#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6600#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6601#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
6602
6603/*
6604 * Decode helpers for Source and Sink Capability PDOs
6605 *
6606 * Note: The Power Delivery Specification should be considered the ultimate
6607 * source of truth on the decoding of these PDOs
6608 */
6609#define PDO_TYPE_FIXED (0 << 30)
6610#define PDO_TYPE_BATTERY (1 << 30)
6611#define PDO_TYPE_VARIABLE (2 << 30)
6612#define PDO_TYPE_AUGMENTED (3 << 30)
6613#define PDO_TYPE_MASK (3 << 30)
6614
6615/*
6616 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6617 *
6618 * <31:30> : Fixed Supply
6619 * <29> : Dual-Role Power
6620 * <28> : SNK/SRC dependent
6621 * <27> : Unconstrained Power
6622 * <26> : USB Communications Capable
6623 * <25> : Dual-Role Data
6624 * <24:20> : SNK/SRC dependent
6625 * <19:10> : Voltage in 50mV Units
6626 * <9:0> : Maximum Current in 10mA units
6627 */
6628#define PDO_FIXED_DUAL_ROLE BIT(29)
6629#define PDO_FIXED_UNCONSTRAINED BIT(27)
6630#define PDO_FIXED_COMM_CAP BIT(26)
6631#define PDO_FIXED_DATA_SWAP BIT(25)
6632#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
6633#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6634#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
6635
6636/*
6637 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
6638 *
6639 * <31:30> : Battery
6640 * <29:20> : Maximum Voltage in 50mV units
6641 * <19:10> : Minimum Voltage in 50mV units
6642 * <9:0> : Maximum Allowable Power in 250mW units
6643 */
6644#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6645#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6646#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
6647
6648/*
6649 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
6650 *
6651 * <31:30> : Variable Supply (non-Battery)
6652 * <29:20> : Maximum Voltage in 50mV units
6653 * <19:10> : Minimum Voltage in 50mV units
6654 * <9:0> : Operational Current in 10mA units
6655 */
6656#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6657#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6658#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
6659
6660/*
6661 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
6662 *
6663 * Note this type is reserved in PD 2.0, and only one type of APDO is
6664 * supported as of the cited version.
6665 *
6666 * <31:30> : Augmented Power Data Object
6667 * <29:28> : Programmable Power Supply
6668 * <27> : PPS Power Limited
6669 * <26:25> : Reserved
6670 * <24:17> : Maximum Voltage in 100mV increments
6671 * <16> : Reserved
6672 * <15:8> : Minimum Voltage in 100mV increments
6673 * <7> : Reserved
6674 * <6:0> : Maximum Current in 50mA increments
6675 */
6676#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
6677#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
6678#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
6679
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006680struct ec_params_typec_status {
6681 uint8_t port;
6682} __ec_align1;
6683
6684struct ec_response_typec_status {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006685 uint8_t pd_enabled; /* PD communication enabled - bool */
6686 uint8_t dev_connected; /* Device connected - bool */
6687 uint8_t sop_connected; /* Device is SOP PD capable - bool */
6688 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006689
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006690 uint8_t power_role; /* enum pd_power_role */
6691 uint8_t data_role; /* enum pd_data_role */
6692 uint8_t vconn_role; /* enum pd_vconn_role */
6693 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006694
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006695 uint8_t polarity; /* enum tcpc_cc_polarity */
6696 uint8_t cc_state; /* enum pd_cc_states */
6697 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
6698 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006699
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006700 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006701
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006702 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006703
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006704 /*
6705 * BCD PD revisions for partners
6706 *
6707 * The format has the PD major reversion in the upper nibble, and PD
6708 * minor version in the next nibble. Following two nibbles are
6709 * currently 0.
6710 * ex. PD 3.2 would map to 0x3200
6711 *
6712 * PD major/minor will be 0 if no PD device is connected.
6713 */
6714 uint16_t sop_revision;
6715 uint16_t sop_prime_revision;
6716
6717 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
6718
6719 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006720} __ec_align1;
6721
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006722/**
6723 * Get the number of peripheral charge ports
6724 */
6725#define EC_CMD_PCHG_COUNT 0x0134
6726
6727#define EC_PCHG_MAX_PORTS 8
6728
6729struct ec_response_pchg_count {
6730 uint8_t port_count;
6731} __ec_align1;
6732
6733/**
6734 * Get the status of a peripheral charge port
6735 */
6736#define EC_CMD_PCHG 0x0135
6737
6738struct ec_params_pchg {
6739 uint8_t port;
6740} __ec_align1;
6741
6742struct ec_response_pchg {
6743 uint32_t error; /* enum pchg_error */
6744 uint8_t state; /* enum pchg_state state */
6745 uint8_t battery_percentage;
6746} __ec_align2;
6747
6748enum pchg_state {
6749 /* Charger is reset and not initialized. */
6750 PCHG_STATE_RESET = 0,
6751 /* Charger is initialized or disabled. */
6752 PCHG_STATE_INITIALIZED,
6753 /* Charger is enabled and ready to detect a device. */
6754 PCHG_STATE_ENABLED,
6755 /* Device is detected in proximity. */
6756 PCHG_STATE_DETECTED,
6757 /* Device is being charged. */
6758 PCHG_STATE_CHARGING,
6759};
6760
6761#define EC_PCHG_STATE_TEXT { \
6762 [PCHG_STATE_RESET] = "RESET", \
6763 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
6764 [PCHG_STATE_ENABLED] = "ENABLED", \
6765 [PCHG_STATE_DETECTED] = "DETECTED", \
6766 [PCHG_STATE_CHARGING] = "CHARGING", \
6767 }
6768
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006769/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006770/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08006771
6772/*****************************************************************************/
6773/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006774 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08006775 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006776#define EC_CMD_CR51_BASE 0x0300
6777#define EC_CMD_CR51_LAST 0x03FF
6778
6779/*****************************************************************************/
6780/* Fingerprint MCU commands: range 0x0400-0x040x */
6781
6782/* Fingerprint SPI sensor passthru command: prototyping ONLY */
6783#define EC_CMD_FP_PASSTHRU 0x0400
6784
6785#define EC_FP_FLAG_NOT_COMPLETE 0x1
6786
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006787struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006788 uint16_t len; /* Number of bytes to write then read */
6789 uint16_t flags; /* EC_FP_FLAG_xxx */
6790 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006791} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006792
6793/* Configure the Fingerprint MCU behavior */
6794#define EC_CMD_FP_MODE 0x0402
6795
6796/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006797#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006798/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006799#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006800/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006801#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006802/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006803#define FP_MODE_CAPTURE BIT(3)
6804/* Finger enrollment session on-going */
6805#define FP_MODE_ENROLL_SESSION BIT(4)
6806/* Enroll the current finger image */
6807#define FP_MODE_ENROLL_IMAGE BIT(5)
6808/* Try to match the current finger image */
6809#define FP_MODE_MATCH BIT(6)
6810/* Reset and re-initialize the sensor. */
6811#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08006812/* Sensor maintenance for dead pixels. */
6813#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006814/* special value: don't change anything just read back current mode */
6815#define FP_MODE_DONT_CHANGE BIT(31)
6816
6817#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
6818 FP_MODE_FINGER_DOWN | \
6819 FP_MODE_FINGER_UP | \
6820 FP_MODE_CAPTURE | \
6821 FP_MODE_ENROLL_SESSION | \
6822 FP_MODE_ENROLL_IMAGE | \
6823 FP_MODE_MATCH | \
6824 FP_MODE_RESET_SENSOR | \
Yidi Lin42f79592020-09-21 18:04:10 +08006825 FP_MODE_SENSOR_MAINTENANCE | \
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006826 FP_MODE_DONT_CHANGE)
6827
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006828/* Capture types defined in bits [30..28] */
6829#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006830#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
6831/*
6832 * This enum must remain ordered, if you add new values you must ensure that
6833 * FP_CAPTURE_TYPE_MAX is still the last one.
6834 */
6835enum fp_capture_type {
6836 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
6837 FP_CAPTURE_VENDOR_FORMAT = 0,
6838 /* Simple raw image capture (produces width x height x bpp bits) */
6839 FP_CAPTURE_SIMPLE_IMAGE = 1,
6840 /* Self test pattern (e.g. checkerboard) */
6841 FP_CAPTURE_PATTERN0 = 2,
6842 /* Self test pattern (e.g. inverted checkerboard) */
6843 FP_CAPTURE_PATTERN1 = 3,
6844 /* Capture for Quality test with fixed contrast */
6845 FP_CAPTURE_QUALITY_TEST = 4,
6846 /* Capture for pixel reset value test */
6847 FP_CAPTURE_RESET_TEST = 5,
6848 FP_CAPTURE_TYPE_MAX,
6849};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006850/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006851#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
6852 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006853
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006854struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006855 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006856} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006857
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006858struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006859 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006860} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006861
6862/* Retrieve Fingerprint sensor information */
6863#define EC_CMD_FP_INFO 0x0403
6864
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006865/* Number of dead pixels detected on the last maintenance */
6866#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006867/* Unknown number of dead pixels detected on the last maintenance */
6868#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006869/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006870#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006871/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006872#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006873/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006874#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006875/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006876#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006877
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006878struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006879 /* Sensor identification */
6880 uint32_t vendor_id;
6881 uint32_t product_id;
6882 uint32_t model_id;
6883 uint32_t version;
6884 /* Image frame characteristics */
6885 uint32_t frame_size;
6886 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
6887 uint16_t width;
6888 uint16_t height;
6889 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006890 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006891} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006892
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006893struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006894 /* Sensor identification */
6895 uint32_t vendor_id;
6896 uint32_t product_id;
6897 uint32_t model_id;
6898 uint32_t version;
6899 /* Image frame characteristics */
6900 uint32_t frame_size;
6901 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
6902 uint16_t width;
6903 uint16_t height;
6904 uint16_t bpp;
6905 uint16_t errors; /* see FP_ERROR_ flags above */
6906 /* Template/finger current information */
6907 uint32_t template_size; /* max template size in bytes */
6908 uint16_t template_max; /* maximum number of fingers/templates */
6909 uint16_t template_valid; /* number of valid fingers/templates */
6910 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006911 uint32_t template_version; /* version of the template format */
6912} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006913
6914/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006915#define EC_CMD_FP_FRAME 0x0404
6916
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006917/* constants defining the 'offset' field which also contains the frame index */
6918#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006919/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006920#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006921/* First frame buffer holding a template */
6922#define FP_FRAME_INDEX_TEMPLATE 1
6923#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006924#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
6925
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006926/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006927#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006928
6929/* Constants for encryption parameters */
6930#define FP_CONTEXT_NONCE_BYTES 12
6931#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
6932#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07006933#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006934#define FP_CONTEXT_TPM_BYTES 32
6935
Jett Rinkba2edaf2020-01-14 11:49:06 -07006936/* Constants for positive match parameters. */
6937#define FP_POSITIVE_MATCH_SALT_BYTES 16
6938
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006939struct ec_fp_template_encryption_metadata {
6940 /*
6941 * Version of the structure format (N=3).
6942 */
6943 uint16_t struct_version;
6944 /* Reserved bytes, set to 0. */
6945 uint16_t reserved;
6946 /*
6947 * The salt is *only* ever used for key derivation. The nonce is unique,
6948 * a different one is used for every message.
6949 */
6950 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07006951 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006952 uint8_t tag[FP_CONTEXT_TAG_BYTES];
6953};
6954
6955struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006956 /*
6957 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
6958 * in the high nibble, and the real offset within the frame in
6959 * FP_FRAME_OFFSET_MASK.
6960 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006961 uint32_t offset;
6962 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006963} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006964
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006965/* Load a template into the MCU */
6966#define EC_CMD_FP_TEMPLATE 0x0405
6967
6968/* Flag in the 'size' field indicating that the full template has been sent */
6969#define FP_TEMPLATE_COMMIT 0x80000000
6970
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006971struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006972 uint32_t offset;
6973 uint32_t size;
6974 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006975} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006976
6977/* Clear the current fingerprint user context and set a new one */
6978#define EC_CMD_FP_CONTEXT 0x0406
6979
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006980struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006981 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006982} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006983
Jett Rinkba2edaf2020-01-14 11:49:06 -07006984enum fp_context_action {
6985 FP_CONTEXT_ASYNC = 0,
6986 FP_CONTEXT_GET_RESULT = 1,
6987};
6988
6989/* Version 1 of the command is "asynchronous". */
6990struct ec_params_fp_context_v1 {
6991 uint8_t action; /**< enum fp_context_action */
6992 uint8_t reserved[3]; /**< padding for alignment */
6993 uint32_t userid[FP_CONTEXT_USERID_WORDS];
6994} __ec_align4;
6995
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006996#define EC_CMD_FP_STATS 0x0407
6997
6998#define FPSTATS_CAPTURE_INV BIT(0)
6999#define FPSTATS_MATCHING_INV BIT(1)
7000
7001struct ec_response_fp_stats {
7002 uint32_t capture_time_us;
7003 uint32_t matching_time_us;
7004 uint32_t overall_time_us;
7005 struct {
7006 uint32_t lo;
7007 uint32_t hi;
7008 } overall_t0;
7009 uint8_t timestamps_invalid;
7010 int8_t template_matched;
7011} __ec_align2;
7012
7013#define EC_CMD_FP_SEED 0x0408
7014struct ec_params_fp_seed {
7015 /*
7016 * Version of the structure format (N=3).
7017 */
7018 uint16_t struct_version;
7019 /* Reserved bytes, set to 0. */
7020 uint16_t reserved;
7021 /* Seed from the TPM. */
7022 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7023} __ec_align4;
7024
7025#define EC_CMD_FP_ENC_STATUS 0x0409
7026
7027/* FP TPM seed has been set or not */
7028#define FP_ENC_STATUS_SEED_SET BIT(0)
7029
7030struct ec_response_fp_encryption_status {
7031 /* Used bits in encryption engine status */
7032 uint32_t valid_flags;
7033 /* Encryption engine status */
7034 uint32_t status;
7035} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007036
Jett Rinkba2edaf2020-01-14 11:49:06 -07007037#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7038struct ec_params_fp_read_match_secret {
7039 uint16_t fgr;
7040} __ec_align4;
7041
7042/* The positive match secret has the length of the SHA256 digest. */
7043#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7044struct ec_response_fp_read_match_secret {
7045 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7046} __ec_align4;
7047
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007048/*****************************************************************************/
7049/* Touchpad MCU commands: range 0x0500-0x05FF */
7050
7051/* Perform touchpad self test */
7052#define EC_CMD_TP_SELF_TEST 0x0500
7053
7054/* Get number of frame types, and the size of each type */
7055#define EC_CMD_TP_FRAME_INFO 0x0501
7056
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007057struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007058 uint32_t n_frames;
7059 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007060} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007061
7062/* Create a snapshot of current frame readings */
7063#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7064
7065/* Read the frame */
7066#define EC_CMD_TP_FRAME_GET 0x0503
7067
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007068struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007069 uint32_t frame_index;
7070 uint32_t offset;
7071 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007072} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007073
7074/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007075/* EC-EC communication commands: range 0x0600-0x06FF */
7076
7077#define EC_COMM_TEXT_MAX 8
7078
7079/*
7080 * Get battery static information, i.e. information that never changes, or
7081 * very infrequently.
7082 */
7083#define EC_CMD_BATTERY_GET_STATIC 0x0600
7084
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007085/**
7086 * struct ec_params_battery_static_info - Battery static info parameters
7087 * @index: Battery index.
7088 */
7089struct ec_params_battery_static_info {
7090 uint8_t index;
7091} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007092
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007093/**
7094 * struct ec_response_battery_static_info - Battery static info response
7095 * @design_capacity: Battery Design Capacity (mAh)
7096 * @design_voltage: Battery Design Voltage (mV)
7097 * @manufacturer: Battery Manufacturer String
7098 * @model: Battery Model Number String
7099 * @serial: Battery Serial Number String
7100 * @type: Battery Type String
7101 * @cycle_count: Battery Cycle Count
7102 */
7103struct ec_response_battery_static_info {
7104 uint16_t design_capacity;
7105 uint16_t design_voltage;
7106 char manufacturer[EC_COMM_TEXT_MAX];
7107 char model[EC_COMM_TEXT_MAX];
7108 char serial[EC_COMM_TEXT_MAX];
7109 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007110 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007111 uint32_t cycle_count;
7112} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007113
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007114/**
7115 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7116 * Equivalent to struct ec_response_battery_static_info, but with longer
7117 * strings.
7118 * @design_capacity: battery design capacity (in mAh)
7119 * @design_voltage: battery design voltage (in mV)
7120 * @cycle_count: battery cycle count
7121 * @manufacturer_ext: battery manufacturer string
7122 * @model_ext: battery model string
7123 * @serial_ext: battery serial number string
7124 * @type_ext: battery type string
7125 */
7126struct ec_response_battery_static_info_v1 {
7127 uint16_t design_capacity;
7128 uint16_t design_voltage;
7129 uint32_t cycle_count;
7130 char manufacturer_ext[12];
7131 char model_ext[12];
7132 char serial_ext[12];
7133 char type_ext[12];
7134} __ec_align4;
7135
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007136/*
7137 * Get battery dynamic information, i.e. information that is likely to change
7138 * every time it is read.
7139 */
7140#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7141
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007142/**
7143 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7144 * @index: Battery index.
7145 */
7146struct ec_params_battery_dynamic_info {
7147 uint8_t index;
7148} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007150/**
7151 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7152 * @actual_voltage: Battery voltage (mV)
7153 * @actual_current: Battery current (mA); negative=discharging
7154 * @remaining_capacity: Remaining capacity (mAh)
7155 * @full_capacity: Capacity (mAh, might change occasionally)
7156 * @flags: Flags, see EC_BATT_FLAG_*
7157 * @desired_voltage: Charging voltage desired by battery (mV)
7158 * @desired_current: Charging current desired by battery (mA)
7159 */
7160struct ec_response_battery_dynamic_info {
7161 int16_t actual_voltage;
7162 int16_t actual_current;
7163 int16_t remaining_capacity;
7164 int16_t full_capacity;
7165 int16_t flags;
7166 int16_t desired_voltage;
7167 int16_t desired_current;
7168} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007169
7170/*
7171 * Control charger chip. Used to control charger chip on the slave.
7172 */
7173#define EC_CMD_CHARGER_CONTROL 0x0602
7174
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007175/**
7176 * struct ec_params_charger_control - Charger control parameters
7177 * @max_current: Charger current (mA). Positive to allow base to draw up to
7178 * max_current and (possibly) charge battery, negative to request current
7179 * from base (OTG).
7180 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7181 * >= 0.
7182 * @allow_charging: Allow base battery charging (only makes sense if
7183 * max_current > 0).
7184 */
7185struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007186 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007187 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007188 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007189} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007190
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007191/* Get ACK from the USB-C SS muxes */
7192#define EC_CMD_USB_PD_MUX_ACK 0x0603
7193
7194struct ec_params_usb_pd_mux_ack {
7195 uint8_t port; /* USB-C port number */
7196} __ec_align1;
7197
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007198/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007199/*
7200 * Reserve a range of host commands for board-specific, experimental, or
7201 * special purpose features. These can be (re)used without updating this file.
7202 *
7203 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7204 * their EC commands for easier development, testing, debugging, and support.
7205 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007206 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7207 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7208 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007209 * In your experimental code, you may want to do something like this:
7210 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007211 * #define EC_CMD_MAGIC_FOO 0x0000
7212 * #define EC_CMD_MAGIC_BAR 0x0001
7213 * #define EC_CMD_MAGIC_HEY 0x0002
7214 *
7215 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7216 * EC_VER_MASK(0);
7217 *
7218 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7219 * EC_VER_MASK(0);
7220 *
7221 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7222 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007223 */
7224#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7225#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7226
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007227/*
7228 * Given the private host command offset, calculate the true private host
7229 * command value.
7230 */
7231#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7232 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7233
Duncan Laurie93e24442014-01-06 12:30:52 -08007234/*****************************************************************************/
7235/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007236 * Passthru commands
7237 *
7238 * Some platforms have sub-processors chained to each other. For example.
7239 *
7240 * AP <--> EC <--> PD MCU
7241 *
7242 * The top 2 bits of the command number are used to indicate which device the
7243 * command is intended for. Device 0 is always the device receiving the
7244 * command; other device mapping is board-specific.
7245 *
7246 * When a device receives a command to be passed to a sub-processor, it passes
7247 * it on with the device number set back to 0. This allows the sub-processor
7248 * to remain blissfully unaware of whether the command originated on the next
7249 * device up the chain, or was passed through from the AP.
7250 *
7251 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7252 * AP sends command 0x4002 to the EC
7253 * EC sends command 0x0002 to the PD MCU
7254 * EC forwards PD MCU response back to the AP
7255 */
7256
7257/* Offset and max command number for sub-device n */
7258#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7259#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7260
7261/*****************************************************************************/
7262/*
Duncan Laurie93e24442014-01-06 12:30:52 -08007263 * Deprecated constants. These constants have been renamed for clarity. The
7264 * meaning and size has not changed. Programs that use the old names should
7265 * switch to the new names soon, as the old names may not be carried forward
7266 * forever.
7267 */
7268#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
7269#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
7270#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
7271
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007272#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007273
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007274#ifdef __cplusplus
7275}
7276#endif
7277
Duncan Laurieeb316852015-12-01 18:51:18 -08007278#endif /* __CROS_EC_EC_COMMANDS_H */