blob: a55c075b77f00984243f40846d62c6c576999762 [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
Caveh Jalali839ada12022-10-31 23:16:48 -07003
4
5
Stefan Reinauerd6682e82013-02-21 15:39:35 -08006/* Host communication command constants for Chrome EC */
7
Caveh Jalali839ada12022-10-31 23:16:48 -07008/*
9 * TODO(b/272518464): Work around coreboot GCC preprocessor bug.
10 * #line marks the *next* line, so it is off by one.
11 */
12#line 13
13
Duncan Laurieeb316852015-12-01 18:51:18 -080014#ifndef __CROS_EC_EC_COMMANDS_H
15#define __CROS_EC_EC_COMMANDS_H
Stefan Reinauerd6682e82013-02-21 15:39:35 -080016
Patrick Georgi0f6187a2017-07-28 15:57:23 +020017#if !defined(__ACPI__) && !defined(__KERNEL__)
Duncan Laurie67f26cc2017-06-29 23:17:22 -070018#include <stdint.h>
19#endif
20
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070021#ifdef CHROMIUM_EC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080022/*
23 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
24 * It is used to not include macros that may cause conflicts in foreign
25 * projects (refer to crbug.com/984623).
26 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070027
Duncan Laurie67f26cc2017-06-29 23:17:22 -070028/*
29 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
30 * generates more efficient code for accessing request/response structures on
31 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
32 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -070033#include "common.h"
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080034#include "compile_time_macros.h"
35
36#else
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080037/* If BUILD_ASSERT isn't already defined, make it a no-op */
38#ifndef BUILD_ASSERT
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080039#define BUILD_ASSERT(_cond)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080040#endif /* !BUILD_ASSERT */
Caveh Jalali024ffe32023-01-30 14:35:19 -080041#endif /* CHROMIUM_EC */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070042
43#ifdef __KERNEL__
44#include <linux/limits.h>
45#else
46/*
47 * Defines macros that may be needed but are for sure defined by the linux
48 * kernel. This section is removed when cros_ec_commands.h is generated (by
49 * util/make_linux_ec_commands_h.sh).
50 * cros_ec_commands.h looks more integrated to the kernel.
51 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080052
53#ifndef BIT
Caveh Jalali024ffe32023-01-30 14:35:19 -080054#define BIT(nr) (1UL << (nr))
Duncan Laurie67f26cc2017-06-29 23:17:22 -070055#endif
56
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080057#ifndef BIT_ULL
Caveh Jalali024ffe32023-01-30 14:35:19 -080058#define BIT_ULL(nr) (1ULL << (nr))
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080059#endif
60
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080061/*
62 * When building Zephyr, this file ends up being included before Zephyr's
63 * include/sys/util.h so causes a warning there. We don't want to add an #ifdef
64 * in that file since it won't be accepted upstream. So work around it here.
65 */
66#ifndef CONFIG_ZEPHYR
67#ifndef GENMASK
68#define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1))
69#endif
70
71#ifndef GENMASK_ULL
72#define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1))
73#endif
74#endif
75
Caveh Jalali024ffe32023-01-30 14:35:19 -080076#endif /* __KERNEL__ */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080077
Rob Barnes8bc5fa92021-06-28 09:32:28 -060078#ifdef __cplusplus
79extern "C" {
80#endif
81
Caveh Jalali6bd733b2023-01-30 17:06:31 -080082/**
83 * Constant for creation of flexible array members that work in both C and
84 * C++. Flexible array members were added in C99 and are not part of the C++
85 * standard. However, clang++ supports them for C++.
86 * When compiling with gcc, flexible array members are not allowed to appear
87 * in an otherwise empty struct, so we use the GCC zero-length array
88 * extension that works with both clang/gcc/g++.
89 */
90#if defined(__cplusplus) && defined(__clang__)
91#define FLEXIBLE_ARRAY_MEMBER_SIZE
92#else
93#define FLEXIBLE_ARRAY_MEMBER_SIZE 0
94#endif
95
Stefan Reinauerd6682e82013-02-21 15:39:35 -080096/*
Duncan Laurie93e24442014-01-06 12:30:52 -080097 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080098 *
Duncan Laurie93e24442014-01-06 12:30:52 -080099 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
100 * determined in other ways. Remove this once the kernel code no longer
101 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800102 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800103#define EC_PROTO_VERSION 0x00000002
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800104
105/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800106#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800107
108/* I/O addresses for ACPI commands */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800109#define EC_LPC_ADDR_ACPI_DATA 0x62
110#define EC_LPC_ADDR_ACPI_CMD 0x66
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800111
112/* I/O addresses for host command */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800113#define EC_LPC_ADDR_HOST_DATA 0x200
114#define EC_LPC_ADDR_HOST_CMD 0x204
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800115
116/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -0800117/* Protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800118#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800119/* For version 2 params; size is EC_PROTO2_MAX_PARAM_SIZE */
120#define EC_LPC_ADDR_HOST_PARAM 0x804
121
Duncan Laurie93e24442014-01-06 12:30:52 -0800122/* Protocol version 3 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800123#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
124#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800126/*
127 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
128 * and they tell the kernel that so we have to think of it as two parts.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800129 *
130 * Other BIOSes report only the I/O port region spanned by the Microchip
131 * MEC series EC; an attempt to address a larger region may fail.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800132 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800133#define EC_HOST_CMD_REGION0 0x800
134#define EC_HOST_CMD_REGION1 0x880
135#define EC_HOST_CMD_REGION_SIZE 0x80
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800136#define EC_HOST_CMD_MEC_REGION_SIZE 0x8
Bill Richardsone221aad2013-06-12 10:50:41 -0700137
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800138/* EC command register bit functions */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800139#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
140#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
141#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
142#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
143#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
144#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
145#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800146
Caveh Jalali024ffe32023-01-30 14:35:19 -0800147#define EC_LPC_ADDR_MEMMAP 0x900
148#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
149#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800150
151/* The offset address of each type of data in mapped memory. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800152#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
153#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
154#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
155#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
156#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
157#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
158#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800159#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800160#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
161#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700162/* Unused 0x28 - 0x2f */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800163#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700164/* Unused 0x31 - 0x33 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800165#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600166/* Battery values are all 32 bits, unless otherwise noted. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800167#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
168#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
169#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
170#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
171#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
172#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600173/* Unused 0x4f */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800174#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
175#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
176#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
177#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700178/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800179#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
180#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
181#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
182#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
183#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700184/* Unused 0x84 - 0x8f */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800185#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700186/* Unused 0x91 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800187#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
Duncan Laurieeb316852015-12-01 18:51:18 -0800188/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
189/* 0x94 - 0x99: 1st Accelerometer */
190/* 0x9a - 0x9f: 2nd Accelerometer */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800191
Caveh Jalali024ffe32023-01-30 14:35:19 -0800192#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800193#define EC_MEMMAP_GPU 0xa6 /* GPU-specific, 8 bits */
194
195/*
196 * Bit fields for EC_MEMMAP_GPU
197 * 0:2: D-Notify level (0:D1, ... 4:D5)
198 * 3: Over temperature
199 */
200#define EC_MEMMAP_GPU_D_NOTIFY_MASK GENMASK(2, 0)
201#define EC_MEMMAP_GPU_OVERT_BIT BIT(3)
202
203/* Power Participant related components */
204#define EC_MEMMAP_PWR_SRC 0xa7 /* Power source (8-bit) */
205/* Unused 0xa8 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700206
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700207/*
208 * ACPI is unable to access memory mapped data at or above this offset due to
209 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
210 * which might be needed by ACPI.
211 */
212#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700213
214/* Define the format of the accelerometer mapped memory status byte. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800215#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
216#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
217#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800218
219/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800220#define EC_TEMP_SENSOR_ENTRIES 16
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800221/*
222 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
223 *
224 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
225 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800226#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800227
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -0800228/* Max temp sensor entries for host commands */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800229#define EC_MAX_TEMP_SENSOR_ENTRIES \
230 (EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -0800231
Duncan Laurie93e24442014-01-06 12:30:52 -0800232/* Special values for mapped temperature sensors */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800233#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
234#define EC_TEMP_SENSOR_ERROR 0xfe
235#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
Duncan Laurie433432b2013-06-03 10:38:22 -0700236#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800237/*
238 * The offset of temperature value stored in mapped memory. This allows
239 * reporting a temperature range of 200K to 454K = -73C to 181C.
240 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800241#define EC_TEMP_SENSOR_OFFSET 200
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800242
Duncan Laurie93e24442014-01-06 12:30:52 -0800243/*
244 * Number of ALS readings at EC_MEMMAP_ALS
245 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800246#define EC_ALS_ENTRIES 2
Duncan Laurie93e24442014-01-06 12:30:52 -0800247
248/*
249 * The default value a temperature sensor will return when it is present but
250 * has not been read this boot. This is a reasonable number to avoid
251 * triggering alarms on the host.
252 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800253#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
Duncan Laurie93e24442014-01-06 12:30:52 -0800254
Caveh Jalali024ffe32023-01-30 14:35:19 -0800255#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
256#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800257
258/* Report 0 for fan stalled so userspace applications can take
259 * an appropriate action based on this value to control the fan.
260 */
Tim Van Pattencab60602023-02-24 12:27:04 -0700261#define EC_FAN_SPEED_STALLED 0x0
262/* This should be used only for ectool to support old ECs. */
263#define EC_FAN_SPEED_STALLED_DEPRECATED 0xfffe
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800264
265/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800266#define EC_BATT_FLAG_AC_PRESENT 0x01
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800267#define EC_BATT_FLAG_BATT_PRESENT 0x02
Caveh Jalali024ffe32023-01-30 14:35:19 -0800268#define EC_BATT_FLAG_DISCHARGING 0x04
269#define EC_BATT_FLAG_CHARGING 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800270#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600271/* Set if some of the static/dynamic data is invalid (or outdated). */
272#define EC_BATT_FLAG_INVALID_DATA 0x20
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800273#define EC_BATT_FLAG_CUT_OFF 0x40
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800274
275/* Switch flags at EC_MEMMAP_SWITCHES */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800276#define EC_SWITCH_LID_OPEN 0x01
277#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800278#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700279/* Was recovery requested via keyboard; now unused. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800280#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800281/* Recovery requested via dedicated signal (from servo board) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800282#define EC_SWITCH_DEDICATED_RECOVERY 0x10
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800283/* Was fake developer mode switch; now unused. Remove in next refactor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800284#define EC_SWITCH_IGNORE0 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800285
286/* Host command interface flags */
287/* Host command interface supports LPC args (LPC interface only) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800288#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800289/* Host command interface supports version 3 protocol */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800290#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800291
292/* Wireless switch flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800293#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
294#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
295#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
296#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
297#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800298
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700299/*****************************************************************************/
300/*
301 * ACPI commands
302 *
303 * These are valid ONLY on the ACPI command/data port.
304 */
305
306/*
307 * ACPI Read Embedded Controller
308 *
309 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
310 *
311 * Use the following sequence:
312 *
313 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
314 * - Wait for EC_LPC_CMDR_PENDING bit to clear
315 * - Write address to EC_LPC_ADDR_ACPI_DATA
316 * - Wait for EC_LPC_CMDR_DATA bit to set
317 * - Read value from EC_LPC_ADDR_ACPI_DATA
318 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700319#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700320
321/*
322 * ACPI Write Embedded Controller
323 *
324 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
325 *
326 * Use the following sequence:
327 *
328 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
329 * - Wait for EC_LPC_CMDR_PENDING bit to clear
330 * - Write address to EC_LPC_ADDR_ACPI_DATA
331 * - Wait for EC_LPC_CMDR_PENDING bit to clear
332 * - Write value to EC_LPC_ADDR_ACPI_DATA
333 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700334#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700335
336/*
337 * ACPI Burst Enable Embedded Controller
338 *
339 * This enables burst mode on the EC to allow the host to issue several
340 * commands back-to-back. While in this mode, writes to mapped multi-byte
341 * data are locked out to ensure data consistency.
342 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700343#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700344
345/*
346 * ACPI Burst Disable Embedded Controller
347 *
348 * This disables burst mode on the EC and stops preventing EC writes to mapped
349 * multi-byte data.
350 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700351#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700352
353/*
354 * ACPI Query Embedded Controller
355 *
356 * This clears the lowest-order bit in the currently pending host events, and
357 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
358 * event 0x80000000 = 32), or 0 if no event was pending.
359 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700360#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700361
362/* Valid addresses in ACPI memory space, for read/write commands */
363
364/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800365#define EC_ACPI_MEM_VERSION 0x00
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700366/*
367 * Test location; writing value here updates test compliment byte to (0xff -
368 * value).
369 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800370#define EC_ACPI_MEM_TEST 0x01
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700371/* Test compliment; writes here are ignored. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800372#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700373
374/* Keyboard backlight brightness percent (0 - 100) */
375#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
376/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800377#define EC_ACPI_MEM_FAN_DUTY 0x04
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700378
379/*
380 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
381 * independent thresholds attached to them. The current value of the ID
382 * register determines which sensor is affected by the THRESHOLD and COMMIT
383 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
384 * as the memory-mapped sensors. The COMMIT register applies those settings.
385 *
386 * The spec does not mandate any way to read back the threshold settings
387 * themselves, but when a threshold is crossed the AP needs a way to determine
388 * which sensor(s) are responsible. Each reading of the ID register clears and
389 * returns one sensor ID that has crossed one of its threshold (in either
390 * direction) since the last read. A value of 0xFF means "no new thresholds
391 * have tripped". Setting or enabling the thresholds for a sensor will clear
392 * the unread event count for that sensor.
393 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800394#define EC_ACPI_MEM_TEMP_ID 0x05
395#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
396#define EC_ACPI_MEM_TEMP_COMMIT 0x07
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700397/*
398 * Here are the bits for the COMMIT register:
399 * bit 0 selects the threshold index for the chosen sensor (0/1)
400 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
401 * Each write to the commit register affects one threshold.
402 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800403#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
404#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700405/*
406 * Example:
407 *
408 * Set the thresholds for sensor 2 to 50 C and 60 C:
409 * write 2 to [0x05] -- select temp sensor 2
410 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
411 * write 0x2 to [0x07] -- enable threshold 0 with this value
412 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
413 * write 0x3 to [0x07] -- enable threshold 1 with this value
414 *
415 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
416 * write 2 to [0x05] -- select temp sensor 2
417 * write 0x1 to [0x07] -- disable threshold 1
418 */
419
420/* DPTF battery charging current limit */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800421#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700422
423/* Charging limit is specified in 64 mA steps */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800424#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700425/* Value to disable DPTF battery charging limit */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800426#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700427
jiazi Yang51fc93f2016-07-28 05:15:01 -0400428/*
429 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800430 * Bits Definition
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800431 * 4 Off Body/On Body status: 0 = Off Body.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800432 * 3:1 Device DPTF Profile Number (DDPN)
433 * 0 = Reserved for backward compatibility (indicates no valid
434 * profile number. Host should fall back to using TBMD).
435 * 1..7 = DPTF Profile number to indicate to host which table needs
436 * to be loaded.
437 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400438 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700439#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
Caveh Jalali024ffe32023-01-30 14:35:19 -0800440#define EC_ACPI_MEM_TBMD_SHIFT 0
441#define EC_ACPI_MEM_TBMD_MASK 0x1
442#define EC_ACPI_MEM_DDPN_SHIFT 1
443#define EC_ACPI_MEM_DDPN_MASK 0x7
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800444#define EC_ACPI_MEM_STTB_SHIFT 4
445#define EC_ACPI_MEM_STTB_MASK 0x1
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700446
447/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600448 * Report device features. Uses the same format as the host command, except:
449 *
450 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
451 * of features", which is of limited interest when the system is already
452 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
453 * these are supported, it defaults to 0.
454 * This allows detecting the presence of this field since older versions of
455 * the EC codebase would simply return 0xff to that unknown address. Check
456 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
457 * are valid.
458 */
459#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
460#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
461#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
462#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
463#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
464#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
465#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
466#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
467
Caveh Jalali024ffe32023-01-30 14:35:19 -0800468#define EC_ACPI_MEM_BATTERY_INDEX 0x12
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600469
470/*
471 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
472 * is enabled (1) or disabled (0).
473 * bit 0 USB port ID 0
474 * ...
475 * bit 7 USB port ID 7
476 */
477#define EC_ACPI_MEM_USB_PORT_POWER 0x13
478
479/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600480 * USB Retimer firmware update.
481 * Read:
482 * Result of last operation AP requested
483 * Write:
484 * bits[3:0]: USB-C port number
485 * bits[7:4]: Operation requested by AP
486 *
487 * NDA (no device attached) case:
488 * To update retimer firmware, AP needs set up TBT Alt mode.
489 * AP requests operations in this sequence:
490 * 1. Get port information about which ports support retimer firmware update.
491 * In the query result, each bit represents one port.
492 * 2. Get current MUX mode, it's NDA.
493 * 3. Suspend specified PD port's task.
494 * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode ->
495 * update firmware -> disconnect MUX -> resume PD task.
496 *
497 * DA (device attached) cases:
498 * Retimer firmware update is not supported in DA cases.
499 * 1. Get port information about which ports support retimer firmware update
500 * 2. Get current MUX mode, it's DA.
501 * 3. AP continues. No more retimer firmware update activities.
502 *
503 */
504#define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14
505
506#define USB_RETIMER_FW_UPDATE_OP_SHIFT 4
Caveh Jalali024ffe32023-01-30 14:35:19 -0800507#define USB_RETIMER_FW_UPDATE_ERR 0xfe
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600508#define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff
Scott Chao18141d8c2021-07-30 10:40:57 +0800509/* Mask to clear unused MUX bits in retimer firmware update */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800510#define USB_RETIMER_FW_UPDATE_MUX_MASK \
511 (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED | \
512 USB_PD_MUX_SAFE_MODE | USB_PD_MUX_TBT_COMPAT_ENABLED | \
513 USB_PD_MUX_USB4_ENABLED)
Scott Chao18141d8c2021-07-30 10:40:57 +0800514
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600515/* Retimer firmware update operations */
516#define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
517#define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800518#define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
519#define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
520#define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
521#define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
522#define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600523#define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
524
Caveh Jalali024ffe32023-01-30 14:35:19 -0800525#define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x)&0x0f)
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600526#define EC_ACPI_MEM_USB_RETIMER_OP(x) \
Caveh Jalali024ffe32023-01-30 14:35:19 -0800527 (((x)&0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600528
529/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700530 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
531 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
532 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800533#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
534#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700535
536/* Current version of ACPI memory address space */
537#define EC_ACPI_MEM_VERSION_CURRENT 2
538
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800539/*
540 * This header file is used in coreboot both in C and ACPI code. The ACPI code
541 * is pre-processed to handle constants but the ASL compiler is unable to
542 * handle actual C code so keep it separate.
543 */
544#ifndef __ACPI__
545
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800546#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800547/*
548 * Define __packed if someone hasn't beat us to it. Linux kernel style
549 * checking prefers __packed over __attribute__((packed)).
550 */
551#ifndef __packed
552#define __packed __attribute__((packed))
553#endif
554
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700555#ifndef __aligned
556#define __aligned(x) __attribute__((aligned(x)))
557#endif
Caveh Jalali024ffe32023-01-30 14:35:19 -0800558#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700559
560/*
561 * Attributes for EC request and response packets. Just defining __packed
562 * results in inefficient assembly code on ARM, if the structure is actually
563 * 32-bit aligned, as it should be for all buffers.
564 *
565 * Be very careful when adding these to existing structures. They will round
566 * up the structure size to the specified boundary.
567 *
568 * Also be very careful to make that if a structure is included in some other
569 * parent structure that the alignment will still be true given the packing of
570 * the parent structure. This is particularly important if the sub-structure
571 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200572 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700573 *
574 * Also be very careful using __packed - particularly when nesting non-packed
575 * structures inside packed ones. In fact, DO NOT use __packed directly;
576 * always use one of these attributes.
577 *
578 * Once everything is annotated properly, the following search strings should
579 * not return ANY matches in this file other than right here:
580 *
581 * "__packed" - generates inefficient code; all sub-structs must also be packed
582 *
583 * "struct [^_]" - all structs should be annotated, except for structs that are
584 * members of other structs/unions (and their original declarations should be
585 * annotated).
586 */
587#ifdef CONFIG_HOSTCMD_ALIGNED
588
589/*
590 * Packed structures where offset and size are always aligned to 1, 2, or 4
591 * byte boundary.
592 */
593#define __ec_align1 __packed
594#define __ec_align2 __packed __aligned(2)
595#define __ec_align4 __packed __aligned(4)
596
597/*
598 * Packed structure which must be under-aligned, because its size is not a
599 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
600 * of all multi-byte fields in it, even though they are themselves aligned.
601 *
602 * In theory, we could duplicate the structure with __aligned(4) for accessing
603 * its members, but use the __packed version for sizeof().
604 */
605#define __ec_align_size1 __packed
606
607/*
608 * Packed structure which must be under-aligned, because its offset inside a
609 * parent structure is not a 4-byte multiple.
610 */
611#define __ec_align_offset1 __packed
612#define __ec_align_offset2 __packed __aligned(2)
613
614/*
615 * Structures which are complicated enough that I'm skipping them on the first
616 * pass. They are effectively unchanged from their previous definitions.
617 *
618 * TODO(rspangler): Figure out what to do with these. It's likely necessary
619 * to work out the size and offset of each member and add explicit padding to
620 * maintain those.
621 */
622#define __ec_todo_packed __packed
623#define __ec_todo_unpacked
624
Caveh Jalali024ffe32023-01-30 14:35:19 -0800625#else /* !CONFIG_HOSTCMD_ALIGNED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700626
627/*
628 * Packed structures make no assumption about alignment, so they do inefficient
629 * byte-wise reads.
630 */
631#define __ec_align1 __packed
632#define __ec_align2 __packed
633#define __ec_align4 __packed
634#define __ec_align_size1 __packed
635#define __ec_align_offset1 __packed
636#define __ec_align_offset2 __packed
637#define __ec_todo_packed __packed
638#define __ec_todo_unpacked
639
Caveh Jalali024ffe32023-01-30 14:35:19 -0800640#endif /* !CONFIG_HOSTCMD_ALIGNED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700641
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800642/* LPC command status byte masks */
643/* EC has written a byte in the data register and host hasn't read it yet */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800644#define EC_LPC_STATUS_TO_HOST 0x01
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800645/* Host has written a command/data byte and the EC hasn't read it yet */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800646#define EC_LPC_STATUS_FROM_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800647/* EC is processing a command */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800648#define EC_LPC_STATUS_PROCESSING 0x04
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800649/* Last write to EC was a command, not data */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800650#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700651/* EC is in burst mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800652#define EC_LPC_STATUS_BURST_MODE 0x10
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800653/* SCI event is pending (requesting SCI query) */
654#define EC_LPC_STATUS_SCI_PENDING 0x20
655/* SMI event is pending (requesting SMI query) */
656#define EC_LPC_STATUS_SMI_PENDING 0x40
657/* (reserved) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800658#define EC_LPC_STATUS_RESERVED 0x80
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800659
660/*
661 * EC is busy. This covers both the EC processing a command, and the host has
662 * written a new command but the EC hasn't picked it up yet.
663 */
664#define EC_LPC_STATUS_BUSY_MASK \
665 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
666
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800667/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700668 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700669 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800670enum ec_status {
671 EC_RES_SUCCESS = 0,
672 EC_RES_INVALID_COMMAND = 1,
673 EC_RES_ERROR = 2,
674 EC_RES_INVALID_PARAM = 3,
675 EC_RES_ACCESS_DENIED = 4,
676 EC_RES_INVALID_RESPONSE = 5,
677 EC_RES_INVALID_VERSION = 6,
678 EC_RES_INVALID_CHECKSUM = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -0800679 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
680 EC_RES_UNAVAILABLE = 9, /* No response available */
681 EC_RES_TIMEOUT = 10, /* We got a timeout */
682 EC_RES_OVERFLOW = 11, /* Table / data overflow */
683 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
684 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
685 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
686 EC_RES_BUS_ERROR = 15, /* Communications bus error */
687 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
688 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
689 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
690 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
691 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700692
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800693 EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700694} __packed;
695BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800696
697/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600698 * Host event codes. ACPI query EC command uses code 0 to mean "no event
699 * pending". We explicitly specify each value in the enum listing so they won't
700 * change if we delete/insert an item or rearrange the list (it needs to be
701 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800702 */
703enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600704 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800705 EC_HOST_EVENT_LID_CLOSED = 1,
706 EC_HOST_EVENT_LID_OPEN = 2,
707 EC_HOST_EVENT_POWER_BUTTON = 3,
708 EC_HOST_EVENT_AC_CONNECTED = 4,
709 EC_HOST_EVENT_AC_DISCONNECTED = 5,
710 EC_HOST_EVENT_BATTERY_LOW = 6,
711 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
712 EC_HOST_EVENT_BATTERY = 8,
713 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700714 /* Event generated by a device attached to the EC */
715 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800716 EC_HOST_EVENT_THERMAL = 11,
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800717 /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */
718 EC_HOST_EVENT_GPU = 12,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800719 EC_HOST_EVENT_KEY_PRESSED = 13,
720 /*
721 * EC has finished initializing the host interface. The host can check
722 * for this event following sending a EC_CMD_REBOOT_EC command to
723 * determine when the EC is ready to accept subsequent commands.
724 */
725 EC_HOST_EVENT_INTERFACE_READY = 14,
726 /* Keyboard recovery combo has been pressed */
727 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
728
729 /* Shutdown due to thermal overload */
730 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
731 /* Shutdown due to battery level too low */
732 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
733
Duncan Laurie93e24442014-01-06 12:30:52 -0800734 /* Suggest that the AP throttle itself */
735 EC_HOST_EVENT_THROTTLE_START = 18,
736 /* Suggest that the AP resume normal speed */
737 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700738
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800739 /* Hang detect logic detected a hang and host event timeout expired */
740 EC_HOST_EVENT_HANG_DETECT = 20,
741 /* Hang detect logic detected a hang and warm rebooted the AP */
742 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700743
744 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700745 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800746
Duncan Lauried8401182014-09-29 08:32:19 -0700747 /* Battery Status flags have changed */
748 EC_HOST_EVENT_BATTERY_STATUS = 23,
749
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700750 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800751 EC_HOST_EVENT_PANIC = 24,
752
Furquan Shaikh066cc852015-06-20 15:53:03 -0700753 /* Keyboard fastboot combo has been pressed */
754 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
755
Gwendal Grignou880b4582016-06-20 08:49:25 -0700756 /* EC RTC event occurred */
757 EC_HOST_EVENT_RTC = 26,
758
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700759 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700760 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700761
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700762 /* EC desires to change state of host-controlled USB mux */
763 EC_HOST_EVENT_USB_MUX = 28,
764
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800765 /*
766 * The device has changed "modes". This can be one of the following:
767 *
768 * - TABLET/LAPTOP mode
769 * - detachable base attach/detach event
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800770 * - on body/off body transition event
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800771 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400772 EC_HOST_EVENT_MODE_CHANGE = 29,
773
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700774 /* Keyboard recovery combo with hardware reinitialization */
775 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
776
Jett Rinkba2edaf2020-01-14 11:49:06 -0700777 /* WoV */
778 EC_HOST_EVENT_WOV = 31,
779
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700780 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800781 * The high bit of the event mask is not used as a host event code. If
782 * it reads back as set, then the entire event mask should be
783 * considered invalid by the host. This can happen when reading the
784 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
785 * not initialized on the EC, or improperly configured on the host.
786 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800787 EC_HOST_EVENT_INVALID = 32,
Tim Van Pattencab60602023-02-24 12:27:04 -0700788
789 /* Body detect (lap/desk) change event */
790 EC_HOST_EVENT_BODY_DETECT_CHANGE = 33,
791
792 /*
793 * Only 64 host events are supported. This enum uses 1-based counting so
794 * it can skip 0 (NONE), so the last legal host event number is 64.
795 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800796};
Tim Van Pattencab60602023-02-24 12:27:04 -0700797
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800798/* Host event mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800799#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800800
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800801/* clang-format off */
802#define HOST_EVENT_TEXT \
803 { \
804 [EC_HOST_EVENT_NONE] = "NONE", \
805 [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \
806 [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \
807 [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \
808 [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \
809 [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \
810 [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \
811 [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \
812 [EC_HOST_EVENT_BATTERY] = "BATTERY", \
813 [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \
814 [EC_HOST_EVENT_DEVICE] = "DEVICE", \
815 [EC_HOST_EVENT_THERMAL] = "THERMAL", \
816 [EC_HOST_EVENT_GPU] = "GPU", \
817 [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \
818 [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \
819 [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \
820 [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \
821 [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \
822 [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \
823 [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \
824 [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \
825 [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \
826 [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \
827 [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \
828 [EC_HOST_EVENT_PANIC] = "PANIC", \
829 [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \
830 [EC_HOST_EVENT_RTC] = "RTC", \
831 [EC_HOST_EVENT_MKBP] = "MKBP", \
832 [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \
833 [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \
834 [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \
835 "KEYBOARD_RECOVERY_HW_REINIT", \
836 [EC_HOST_EVENT_WOV] = "WOV", \
837 [EC_HOST_EVENT_INVALID] = "INVALID", \
Tim Van Pattencab60602023-02-24 12:27:04 -0700838 [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800839 }
840/* clang-format on */
841
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800842/**
843 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
844 * @flags: The host argument flags.
845 * @command_version: Command version.
846 * @data_size: The length of data.
847 * @checksum: Checksum; sum of command + flags + command_version + data_size +
848 * all params/response data bytes.
849 */
850struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800851 uint8_t flags;
852 uint8_t command_version;
853 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800854 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800855} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800856
857/* Flags for ec_lpc_host_args.flags */
858/*
859 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
860 * params.
861 *
862 * If EC gets a command and this flag is not set, this is an old-style command.
863 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
864 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700865 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800866 */
867#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
868/*
869 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
870 *
871 * If EC responds to a command and this flag is not set, this is an old-style
872 * response. Command version is 0 and response data from EC is at
873 * EC_LPC_ADDR_OLD_PARAM with unknown length.
874 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800875#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800876
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800877/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800878/*
879 * Byte codes returned by EC over SPI interface.
880 *
881 * These can be used by the AP to debug the EC interface, and to determine
882 * when the EC is not in a state where it will ever get around to responding
883 * to the AP.
884 *
885 * Example of sequence of bytes read from EC for a current good transfer:
886 * 1. - - AP asserts chip select (CS#)
887 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
888 * 3. - - EC starts handling CS# interrupt
889 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
890 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
891 * bytes looking for EC_SPI_FRAME_START
892 * 6. - - EC finishes processing and sets up response
893 * 7. EC_SPI_FRAME_START - AP reads frame byte
894 * 8. (response packet) - AP reads response packet
895 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
896 * 10 - - AP deasserts chip select
897 * 11 - - EC processes CS# interrupt and sets up DMA for
898 * next request
899 *
900 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
901 * the following byte values:
902 * EC_SPI_OLD_READY
903 * EC_SPI_RX_READY
904 * EC_SPI_RECEIVING
905 * EC_SPI_PROCESSING
906 *
907 * Then the EC found an error in the request, or was not ready for the request
908 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
909 * because the EC is unable to tell when the AP is done sending its request.
910 */
911
912/*
913 * Framing byte which precedes a response packet from the EC. After sending a
914 * request, the AP will clock in bytes until it sees the framing byte, then
915 * clock in the response packet.
916 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800917#define EC_SPI_FRAME_START 0xec
Duncan Laurie93e24442014-01-06 12:30:52 -0800918
919/*
920 * Padding bytes which are clocked out after the end of a response packet.
921 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800922#define EC_SPI_PAST_END 0xed
Duncan Laurie93e24442014-01-06 12:30:52 -0800923
924/*
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800925 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
Duncan Laurie93e24442014-01-06 12:30:52 -0800926 * that the AP will send a valid packet header (starting with
927 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800928 *
929 * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
930 * CS goes low. This macro has the Most Significant Bit set to zero,
931 * so SDO will not be driven high when CS goes low.
Duncan Laurie93e24442014-01-06 12:30:52 -0800932 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800933#define EC_SPI_RX_READY 0x78
Duncan Laurie93e24442014-01-06 12:30:52 -0800934
935/*
936 * EC has started receiving the request from the AP, but hasn't started
937 * processing it yet.
938 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800939#define EC_SPI_RECEIVING 0xf9
Duncan Laurie93e24442014-01-06 12:30:52 -0800940
941/* EC has received the entire request from the AP and is processing it. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800942#define EC_SPI_PROCESSING 0xfa
Duncan Laurie93e24442014-01-06 12:30:52 -0800943
944/*
945 * EC received bad data from the AP, such as a packet header with an invalid
946 * length. EC will ignore all data until chip select deasserts.
947 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800948#define EC_SPI_RX_BAD_DATA 0xfb
Duncan Laurie93e24442014-01-06 12:30:52 -0800949
950/*
951 * EC received data from the AP before it was ready. That is, the AP asserted
952 * chip select and started clocking data before the EC was ready to receive it.
953 * EC will ignore all data until chip select deasserts.
954 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800955#define EC_SPI_NOT_READY 0xfc
Duncan Laurie93e24442014-01-06 12:30:52 -0800956
957/*
958 * EC was ready to receive a request from the AP. EC has treated the byte sent
959 * by the AP as part of a request packet, or (for old-style ECs) is processing
960 * a fully received packet but is not ready to respond yet.
961 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800962#define EC_SPI_OLD_READY 0xfd
Duncan Laurie93e24442014-01-06 12:30:52 -0800963
964/*****************************************************************************/
965
966/*
967 * Protocol version 2 for I2C and SPI send a request this way:
968 *
969 * 0 EC_CMD_VERSION0 + (command version)
970 * 1 Command number
971 * 2 Length of params = N
972 * 3..N+2 Params, if any
973 * N+3 8-bit checksum of bytes 0..N+2
974 *
975 * The corresponding response is:
976 *
977 * 0 Result code (EC_RES_*)
978 * 1 Length of params = M
979 * 2..M+1 Params, if any
980 * M+2 8-bit checksum of bytes 0..M+1
981 */
982#define EC_PROTO2_REQUEST_HEADER_BYTES 3
983#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -0800984#define EC_PROTO2_REQUEST_OVERHEAD \
985 (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -0800986
987#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
988#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -0800989#define EC_PROTO2_RESPONSE_OVERHEAD \
990 (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -0800991
992/* Parameter length was limited by the LPC interface */
993#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
994
995/* Maximum request and response packet sizes for protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800996#define EC_PROTO2_MAX_REQUEST_SIZE \
997 (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
998#define EC_PROTO2_MAX_RESPONSE_SIZE \
999 (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
Duncan Laurie93e24442014-01-06 12:30:52 -08001000
1001/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001002
1003/*
1004 * Value written to legacy command port / prefix byte to indicate protocol
1005 * 3+ structs are being used. Usage is bus-dependent.
1006 */
1007#define EC_COMMAND_PROTOCOL_3 0xda
1008
1009#define EC_HOST_REQUEST_VERSION 3
1010
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001011/**
1012 * struct ec_host_request - Version 3 request from host.
1013 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
1014 * receives a header with a version it doesn't know how to
1015 * parse.
1016 * @checksum: Checksum of request and data; sum of all bytes including checksum
1017 * should total to 0.
1018 * @command: Command to send (EC_CMD_...)
1019 * @command_version: Command version.
1020 * @reserved: Unused byte in current protocol version; set to 0.
1021 * @data_len: Length of data which follows this header.
1022 */
1023struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001024 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001025 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001026 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001027 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001028 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001029 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001030} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001031
1032#define EC_HOST_RESPONSE_VERSION 3
1033
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001034/**
1035 * struct ec_host_response - Version 3 response from EC.
1036 * @struct_version: Struct version (=3).
1037 * @checksum: Checksum of response and data; sum of all bytes including
1038 * checksum should total to 0.
1039 * @result: EC's response to the command (separate from communication failure)
1040 * @data_len: Length of data which follows this header.
1041 * @reserved: Unused bytes in current protocol version; set to 0.
1042 */
1043struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001044 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001045 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001046 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001047 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001048 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001049} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001050
1051/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001052
1053/*
1054 * Host command protocol V4.
1055 *
1056 * Packets always start with a request or response header. They are followed
1057 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +01001058 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001059 * polynomial.
1060 *
1061 * Host algorithm when sending a request q:
1062 *
1063 * 101) tries_left=(some value, e.g. 3);
1064 * 102) q.seq_num++
1065 * 103) q.seq_dup=0
1066 * 104) Calculate q.header_crc.
1067 * 105) Send request q to EC.
1068 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
1069 *
1070 * 201) If r.struct_version != 4, go to 301.
1071 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
1072 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
1073 * 204) If r.seq_num != q.seq_num, go to 301.
1074 * 205) If r.seq_dup == q.seq_dup, return success.
1075 * 207) If r.seq_dup == 1, go to 301.
1076 * 208) Return error.
1077 *
1078 * 301) If --tries_left <= 0, return error.
1079 * 302) If q.seq_dup == 1, go to 105.
1080 * 303) q.seq_dup = 1
1081 * 304) Go to 104.
1082 *
1083 * EC algorithm when receiving a request q.
1084 * EC has response buffer r, error buffer e.
1085 *
1086 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
1087 * and go to 301
1088 * 102) If q.header_crc mismatches calculated CRC, set e.result =
1089 * EC_RES_INVALID_HEADER_CRC and go to 301
1090 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
1091 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
1092 * and go to 301.
1093 * 104) If q.seq_dup == 0, go to 201.
1094 * 105) If q.seq_num != r.seq_num, go to 201.
1095 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
1096 *
1097 * 201) Process request q into response r.
1098 * 202) r.seq_num = q.seq_num
1099 * 203) r.seq_dup = q.seq_dup
1100 * 204) Calculate r.header_crc
1101 * 205) If r.data_len > 0 and data is no longer available, set e.result =
1102 * EC_RES_DUP_UNAVAILABLE and go to 301.
1103 * 206) Send response r.
1104 *
1105 * 301) e.seq_num = q.seq_num
1106 * 302) e.seq_dup = q.seq_dup
1107 * 303) Calculate e.header_crc.
1108 * 304) Send error response e.
1109 */
1110
1111/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001112struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001113 /*
1114 * bits 0-3: struct_version: Structure version (=4)
1115 * bit 4: is_response: Is response (=0)
1116 * bits 5-6: seq_num: Sequence number
1117 * bit 7: seq_dup: Sequence duplicate flag
1118 */
1119 uint8_t fields0;
1120
1121 /*
1122 * bits 0-4: command_version: Command version
1123 * bits 5-6: Reserved (set 0, ignore on read)
1124 * bit 7: data_crc_present: Is data CRC present after data
1125 */
1126 uint8_t fields1;
1127
1128 /* Command code (EC_CMD_*) */
1129 uint16_t command;
1130
1131 /* Length of data which follows this header (not including data CRC) */
1132 uint16_t data_len;
1133
1134 /* Reserved (set 0, ignore on read) */
1135 uint8_t reserved;
1136
1137 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1138 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001139} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001140
1141/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001142struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001143 /*
1144 * bits 0-3: struct_version: Structure version (=4)
1145 * bit 4: is_response: Is response (=1)
1146 * bits 5-6: seq_num: Sequence number
1147 * bit 7: seq_dup: Sequence duplicate flag
1148 */
1149 uint8_t fields0;
1150
1151 /*
1152 * bits 0-6: Reserved (set 0, ignore on read)
1153 * bit 7: data_crc_present: Is data CRC present after data
1154 */
1155 uint8_t fields1;
1156
1157 /* Result code (EC_RES_*) */
1158 uint16_t result;
1159
1160 /* Length of data which follows this header (not including data CRC) */
1161 uint16_t data_len;
1162
1163 /* Reserved (set 0, ignore on read) */
1164 uint8_t reserved;
1165
1166 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1167 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001168} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001169
1170/* Fields in fields0 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001171#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1172#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1173#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1174#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1175#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001176
1177/* Fields in fields1 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001178#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1179#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001180
1181/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001182/*
1183 * Notes on commands:
1184 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001185 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001186 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001187 * specified, the command does not input or output data, respectively.
1188 * Parameter/response length is implicit in the structs. Some underlying
1189 * communication protocols (I2C, SPI) may add length or checksum headers, but
1190 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001191 *
1192 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1193 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001194 */
1195
1196/*****************************************************************************/
1197/* General / test commands */
1198
1199/*
1200 * Get protocol version, used to deal with non-backward compatible protocol
1201 * changes.
1202 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001203#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001204
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001205/**
1206 * struct ec_response_proto_version - Response to the proto version command.
1207 * @version: The protocol version.
1208 */
1209struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001210 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001211} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001212
1213/*
1214 * Hello. This is a simple command to test the EC is responsive to
1215 * commands.
1216 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001217#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001218
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001219/**
1220 * struct ec_params_hello - Parameters to the hello command.
1221 * @in_data: Pass anything here.
1222 */
1223struct ec_params_hello {
1224 uint32_t in_data;
1225} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001226
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001227/**
1228 * struct ec_response_hello - Response to the hello command.
1229 * @out_data: Output will be in_data + 0x01020304.
1230 */
1231struct ec_response_hello {
1232 uint32_t out_data;
1233} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001234
1235/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001236#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001237
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001238enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001239 EC_IMAGE_UNKNOWN = 0,
1240 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001241 EC_IMAGE_RW,
1242 EC_IMAGE_RW_A = EC_IMAGE_RW,
1243 EC_IMAGE_RO_B,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001244 EC_IMAGE_RW_B,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001245};
1246
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001247/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001248 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001249 * @version_string_ro: Null-terminated RO firmware version string.
1250 * @version_string_rw: Null-terminated RW firmware version string.
1251 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001252 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001253 */
1254struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001255 char version_string_ro[32];
1256 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001257 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001258 uint32_t current_image;
1259} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001260
Rob Barnes5ab14662021-09-17 10:24:45 -06001261/**
1262 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1263 *
1264 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1265 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1266 * and adds one additional field (cros_fwid_rw).
1267 *
1268 * @version_string_ro: Null-terminated RO firmware version string.
1269 * @version_string_rw: Null-terminated RW firmware version string.
1270 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1271 * @current_image: One of ec_image.
1272 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1273 */
1274struct ec_response_get_version_v1 {
1275 char version_string_ro[32];
1276 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001277 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
Rob Barnes5ab14662021-09-17 10:24:45 -06001278 uint32_t current_image;
Caveh Jalali024ffe32023-01-30 14:35:19 -08001279 char cros_fwid_rw[32]; /* Added in version 1 */
Rob Barnes5ab14662021-09-17 10:24:45 -06001280} __ec_align4;
1281
Caveh Jalali839ada12022-10-31 23:16:48 -07001282/* Read test - OBSOLETE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001283#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001284
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001285/*
1286 * Get build information
1287 *
1288 * Response is null-terminated string.
1289 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001290#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001291
1292/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001293#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001294
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001295/**
1296 * struct ec_response_get_chip_info - Response to the get chip info command.
1297 * @vendor: Null-terminated string for chip vendor.
1298 * @name: Null-terminated string for chip name.
1299 * @revision: Null-terminated string for chip mask version.
1300 */
1301struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001302 char vendor[32];
1303 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001304 char revision[32];
1305} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001306
1307/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001308#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001309
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001310/**
1311 * struct ec_response_board_version - Response to the board version command.
1312 * @board_version: A monotonously incrementing number.
1313 */
1314struct ec_response_board_version {
1315 uint16_t board_version;
1316} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001317
1318/*
1319 * Read memory-mapped data.
1320 *
1321 * This is an alternate interface to memory-mapped data for bus protocols
1322 * which don't support direct-mapped memory - I2C, SPI, etc.
1323 *
1324 * Response is params.size bytes of data.
1325 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001326#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001327
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001328/**
1329 * struct ec_params_read_memmap - Parameters for the read memory map command.
1330 * @offset: Offset in memmap (EC_MEMMAP_*).
1331 * @size: Size to read in bytes.
1332 */
1333struct ec_params_read_memmap {
1334 uint8_t offset;
1335 uint8_t size;
1336} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001337
1338/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001339#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001340
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001341/**
1342 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1343 * @cmd: Command to check.
1344 */
1345struct ec_params_get_cmd_versions {
1346 uint8_t cmd;
1347} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001348
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001349/**
1350 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1351 * versions (v1)
1352 * @cmd: Command to check.
1353 */
1354struct ec_params_get_cmd_versions_v1 {
1355 uint16_t cmd;
1356} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001357
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001358/**
1359 * struct ec_response_get_cmd_version - Response to the get command versions.
1360 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1361 * a desired version.
1362 */
1363struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001364 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001365} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001366
Duncan Laurie433432b2013-06-03 10:38:22 -07001367/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001368 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001369 * on lpc since it has its own out-of-band busy indicator.
1370 *
1371 * lpc must read the status from the command register. Attempting this on
1372 * lpc will overwrite the args/parameter space and corrupt its data.
1373 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001374#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001375
1376/* Avoid using ec_status which is for return values */
1377enum ec_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001378 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001379};
1380
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001381/**
1382 * struct ec_response_get_comms_status - Response to the get comms status
1383 * command.
1384 * @flags: Mask of enum ec_comms_status.
1385 */
1386struct ec_response_get_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001387 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001388} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001389
Duncan Laurie93e24442014-01-06 12:30:52 -08001390/* Fake a variety of responses, purely for testing purposes. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001391#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001392
1393/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001394struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001395 uint32_t ec_result;
1396 uint32_t ret_len;
1397 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001398} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001399
1400/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001401struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001402 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001403} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001404
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001405/* Get protocol information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001406#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001407
1408/* Flags for ec_response_get_protocol_info.flags */
1409/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001410#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001411
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001412/**
1413 * struct ec_response_get_protocol_info - Response to the get protocol info.
1414 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1415 * version n).
1416 * @max_request_packet_size: Maximum request packet size in bytes.
1417 * @max_response_packet_size: Maximum response packet size in bytes.
1418 * @flags: see EC_PROTOCOL_INFO_*
1419 */
1420struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001421 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001422 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001423 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001424 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001425 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001426} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001427
Duncan Laurie93e24442014-01-06 12:30:52 -08001428/*****************************************************************************/
1429/* Get/Set miscellaneous values */
1430
1431/* The upper byte of .flags tells what to do (nothing means "get") */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001432#define EC_GSV_SET 0x80000000
Duncan Laurie93e24442014-01-06 12:30:52 -08001433
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001434/*
1435 * The lower three bytes of .flags identifies the parameter, if that has
1436 * meaning for an individual command.
1437 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001438#define EC_GSV_PARAM_MASK 0x00ffffff
1439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001440struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001441 uint32_t flags;
1442 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001443} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001444
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001445struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001446 uint32_t flags;
1447 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001448} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001449
Duncan Laurieeb316852015-12-01 18:51:18 -08001450/* More than one command can use these structs to get/set parameters. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001451#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001452
Duncan Laurieeb316852015-12-01 18:51:18 -08001453/*****************************************************************************/
1454/* List the features supported by the firmware */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001455#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001456
1457/* Supported features */
1458enum ec_feature_code {
1459 /*
1460 * This image contains a limited set of features. Another image
1461 * in RW partition may support more features.
1462 */
1463 EC_FEATURE_LIMITED = 0,
1464 /*
1465 * Commands for probing/reading/writing/erasing the flash in the
1466 * EC are present.
1467 */
1468 EC_FEATURE_FLASH = 1,
1469 /*
1470 * Can control the fan speed directly.
1471 */
1472 EC_FEATURE_PWM_FAN = 2,
1473 /*
1474 * Can control the intensity of the keyboard backlight.
1475 */
1476 EC_FEATURE_PWM_KEYB = 3,
1477 /*
1478 * Support Google lightbar, introduced on Pixel.
1479 */
1480 EC_FEATURE_LIGHTBAR = 4,
1481 /* Control of LEDs */
1482 EC_FEATURE_LED = 5,
1483 /* Exposes an interface to control gyro and sensors.
1484 * The host goes through the EC to access these sensors.
1485 * In addition, the EC may provide composite sensors, like lid angle.
1486 */
1487 EC_FEATURE_MOTION_SENSE = 6,
1488 /* The keyboard is controlled by the EC */
1489 EC_FEATURE_KEYB = 7,
1490 /* The AP can use part of the EC flash as persistent storage. */
1491 EC_FEATURE_PSTORE = 8,
1492 /* The EC monitors BIOS port 80h, and can return POST codes. */
1493 EC_FEATURE_PORT80 = 9,
1494 /*
1495 * Thermal management: include TMP specific commands.
1496 * Higher level than direct fan control.
1497 */
1498 EC_FEATURE_THERMAL = 10,
1499 /* Can switch the screen backlight on/off */
1500 EC_FEATURE_BKLIGHT_SWITCH = 11,
1501 /* Can switch the wifi module on/off */
1502 EC_FEATURE_WIFI_SWITCH = 12,
1503 /* Monitor host events, through for example SMI or SCI */
1504 EC_FEATURE_HOST_EVENTS = 13,
1505 /* The EC exposes GPIO commands to control/monitor connected devices. */
1506 EC_FEATURE_GPIO = 14,
1507 /* The EC can send i2c messages to downstream devices. */
1508 EC_FEATURE_I2C = 15,
1509 /* Command to control charger are included */
1510 EC_FEATURE_CHARGER = 16,
1511 /* Simple battery support. */
1512 EC_FEATURE_BATTERY = 17,
1513 /*
1514 * Support Smart battery protocol
1515 * (Common Smart Battery System Interface Specification)
1516 */
1517 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001518 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001519 EC_FEATURE_HANG_DETECT = 19,
1520 /* Report power information, for pit only */
1521 EC_FEATURE_PMU = 20,
1522 /* Another Cros EC device is present downstream of this one */
1523 EC_FEATURE_SUB_MCU = 21,
1524 /* Support USB Power delivery (PD) commands */
1525 EC_FEATURE_USB_PD = 22,
1526 /* Control USB multiplexer, for audio through USB port for instance. */
1527 EC_FEATURE_USB_MUX = 23,
1528 /* Motion Sensor code has an internal software FIFO */
1529 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1530 /* Support temporary secure vstore */
1531 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001532 /* EC decides on USB-C SS mux state, muxes configured by host */
1533 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1534 /* EC has RTC feature that can be controlled by host commands */
1535 EC_FEATURE_RTC = 27,
1536 /* The MCU exposes a Fingerprint sensor */
1537 EC_FEATURE_FINGERPRINT = 28,
1538 /* The MCU exposes a Touchpad */
1539 EC_FEATURE_TOUCHPAD = 29,
1540 /* The MCU has RWSIG task enabled */
1541 EC_FEATURE_RWSIG = 30,
1542 /* EC has device events support */
1543 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001544 /* EC supports the unified wake masks for LPC/eSPI systems */
1545 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001546 /* EC supports 64-bit host events */
1547 EC_FEATURE_HOST_EVENT64 = 33,
1548 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1549 EC_FEATURE_EXEC_IN_RAM = 34,
1550 /* EC supports CEC commands */
1551 EC_FEATURE_CEC = 35,
1552 /* EC supports tight sensor timestamping. */
1553 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001554 /*
1555 * EC supports tablet mode detection aligned to Chrome and allows
1556 * setting of threshold by host command using
1557 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1558 */
1559 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001560 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001561 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001562 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1563 * be sent to RO to be precise.
1564 */
1565 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001566 /* The MCU is a System Companion Processor (SCP). */
1567 EC_FEATURE_SCP = 39,
1568 /* The MCU is an Integrated Sensor Hub */
1569 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001570 /* New TCPMv2 TYPEC_ prefaced commands supported */
1571 EC_FEATURE_TYPEC_CMD = 41,
1572 /*
1573 * The EC will wait for direction from the AP to enter Type-C alternate
1574 * modes or USB4.
1575 */
1576 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1577 /*
1578 * The EC will wait for an acknowledge from the AP after setting the
1579 * mux.
1580 */
1581 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001582 /*
1583 * The EC supports entering and residing in S4.
1584 */
1585 EC_FEATURE_S4_RESIDENCY = 44,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001586 /*
1587 * The EC supports the AP directing mux sets for the board.
1588 */
1589 EC_FEATURE_TYPEC_AP_MUX_SET = 45,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001590 /*
1591 * The EC supports the AP composing VDMs for us to send.
1592 */
1593 EC_FEATURE_TYPEC_AP_VDM_SEND = 46,
Duncan Laurieeb316852015-12-01 18:51:18 -08001594};
1595
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001596#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1597#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1598
1599struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001600 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001601} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001602
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001603/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001604/* Get the board's SKU ID from EC */
1605#define EC_CMD_GET_SKU_ID 0x000E
1606
Kevin Chiue2bb0592017-09-12 09:13:41 +08001607/* Set SKU ID from AP */
1608#define EC_CMD_SET_SKU_ID 0x000F
1609
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001610struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001611 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001612} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001613
1614/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001615/* Flash commands */
1616
1617/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001618#define EC_CMD_FLASH_INFO 0x0010
1619#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001620
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001621/**
1622 * struct ec_response_flash_info - Response to the flash info command.
1623 * @flash_size: Usable flash size in bytes.
1624 * @write_block_size: Write block size. Write offset and size must be a
1625 * multiple of this.
1626 * @erase_block_size: Erase block size. Erase offset and size must be a
1627 * multiple of this.
1628 * @protect_block_size: Protection block size. Protection offset and size
1629 * must be a multiple of this.
1630 *
1631 * Version 0 returns these fields.
1632 */
1633struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001634 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001635 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001636 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001637 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001638} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001639
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001640/*
1641 * Flags for version 1+ flash info command
1642 * EC flash erases bits to 0 instead of 1.
1643 */
1644#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001645
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001646/*
1647 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001648 * be necessary on a chip where write/erase can be corrupted by other board
1649 * activity, or where the chip needs to enable some sort of programming voltage,
1650 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001651 * chip functionality.
1652 */
1653#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001654
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001655/**
1656 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1657 * @flash_size: Usable flash size in bytes.
1658 * @write_block_size: Write block size. Write offset and size must be a
1659 * multiple of this.
1660 * @erase_block_size: Erase block size. Erase offset and size must be a
1661 * multiple of this.
1662 * @protect_block_size: Protection block size. Protection offset and size
1663 * must be a multiple of this.
1664 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1665 * size is exactly this and offset is a multiple of this.
1666 * For example, an EC may have a write buffer which can do
1667 * half-page operations if data is aligned, and a slower
1668 * word-at-a-time write mode.
1669 * @flags: Flags; see EC_FLASH_INFO_*
1670 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001671 * Version 1 returns the same initial fields as version 0, with additional
1672 * fields following.
1673 *
1674 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001675 * if they did we'd define the version 0 structure as a sub-structure of this
1676 * one.
1677 *
1678 * Version 2 supports flash banks of different sizes:
1679 * The caller specified the number of banks it has preallocated
1680 * (num_banks_desc)
1681 * The EC returns the number of banks describing the flash memory.
1682 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001683 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001684struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001685 /* Version 0 fields; see above for description */
1686 uint32_t flash_size;
1687 uint32_t write_block_size;
1688 uint32_t erase_block_size;
1689 uint32_t protect_block_size;
1690
1691 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001692 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001693 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001694} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001695
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001696struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001697 /* Number of banks to describe */
1698 uint16_t num_banks_desc;
1699 /* Reserved; set 0; ignore on read */
1700 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001701} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001702
1703struct ec_flash_bank {
1704 /* Number of sector is in this bank. */
1705 uint16_t count;
1706 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1707 uint8_t size_exp;
1708 /* Minimal write size for the sectors in this bank */
1709 uint8_t write_size_exp;
1710 /* Erase size for the sectors in this bank */
1711 uint8_t erase_size_exp;
1712 /* Size for write protection, usually identical to erase size. */
1713 uint8_t protect_size_exp;
1714 /* Reserved; set 0; ignore on read */
1715 uint8_t reserved[2];
1716};
1717
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001718struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001719 /* Total flash in the EC. */
1720 uint32_t flash_size;
1721 /* Flags; see EC_FLASH_INFO_* */
1722 uint32_t flags;
1723 /* Maximum size to use to send data to write to the EC. */
1724 uint32_t write_ideal_size;
1725 /* Number of banks present in the EC. */
1726 uint16_t num_banks_total;
1727 /* Number of banks described in banks array. */
1728 uint16_t num_banks_desc;
1729 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001730} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001731
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001732/*
1733 * Read flash
1734 *
1735 * Response is params.size bytes of data.
1736 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001737#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001738
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001739/**
1740 * struct ec_params_flash_read - Parameters for the flash read command.
1741 * @offset: Byte offset to read.
1742 * @size: Size to read in bytes.
1743 */
1744struct ec_params_flash_read {
1745 uint32_t offset;
1746 uint32_t size;
1747} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001748
1749/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001750#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001751#define EC_VER_FLASH_WRITE 1
1752
1753/* Version 0 of the flash command supported only 64 bytes of data */
1754#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001755
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001756/**
1757 * struct ec_params_flash_write - Parameters for the flash write command.
1758 * @offset: Byte offset to write.
1759 * @size: Size to write in bytes.
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001760 * @data: Data to write.
1761 * @data.words32: uint32_t data to write.
1762 * @data.bytes: uint8_t data to write.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001763 */
1764struct ec_params_flash_write {
1765 uint32_t offset;
1766 uint32_t size;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001767 /* Followed by data to write. This union allows accessing an
1768 * underlying buffer as uint32s or uint8s for convenience.
1769 */
1770 union {
1771 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1772 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1773 } data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001774} __ec_align4;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001775BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001776
1777/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001778#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001779
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001780/**
1781 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1782 * @offset: Byte offset to erase.
1783 * @size: Size to erase in bytes.
1784 */
1785struct ec_params_flash_erase {
1786 uint32_t offset;
1787 uint32_t size;
1788} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001789
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001790/*
1791 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001792 * subcommands can returns:
1793 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1794 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1795 * EC_RES_ERROR : other errors.
1796 * EC_RES_BUSY : an existing erase operation is in progress.
1797 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1798 *
1799 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1800 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1801 * the proper result.
1802 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1803 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1804 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1805 * permitted while erasing. (For instance, STM32F4).
1806 */
1807enum ec_flash_erase_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001808 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1809 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1810 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001811};
1812
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001813/**
1814 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1815 * @cmd: One of ec_flash_erase_cmd.
1816 * @reserved: Pad byte; currently always contains 0.
1817 * @flag: No flags defined yet; set to 0.
1818 * @params: Same as v0 parameters.
1819 */
1820struct ec_params_flash_erase_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001821 uint8_t cmd;
1822 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001823 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001824 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001825} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001826
1827/*
1828 * Get/set flash protection.
1829 *
1830 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1831 * firmware write protect GPIO, not all flags will take effect immediately;
1832 * some flags require a subsequent hard reset to take effect. Check the
1833 * returned flags bits to see what actually happened.
1834 *
1835 * If mask=0, simply returns the current flags state.
1836 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001837#define EC_CMD_FLASH_PROTECT 0x0015
Caveh Jalali024ffe32023-01-30 14:35:19 -08001838#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001839
1840/* Flags for flash protection */
1841/* RO flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001842#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001843/*
1844 * RO flash code protected now. If this bit is set, at-boot status cannot
1845 * be changed.
1846 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001847#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001848/* Entire flash code protected now, until reboot. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001849#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001850/* Flash write protect GPIO is asserted now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001851#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001852/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001853#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001854/*
1855 * Error - flash protection is in inconsistent state. At least one bank of
1856 * flash which should be protected is not protected. Usually fixed by
1857 * re-requesting the desired flags, or by a hard reset if that fails.
1858 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001859#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001860/* Entire flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001861#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001862/* RW flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001863#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001864/* RW flash code protected now. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001865#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001866/* Rollback information flash region protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001867#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001868/* Rollback information flash region protected now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001869#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001870/* Error - Unknown error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001871#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001872
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001873/**
1874 * struct ec_params_flash_protect - Parameters for the flash protect command.
1875 * @mask: Bits in flags to apply.
1876 * @flags: New flags to apply.
1877 */
1878struct ec_params_flash_protect {
1879 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001880 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001881} __ec_align4;
1882
1883/**
1884 * struct ec_response_flash_protect - Response to the flash protect command.
1885 * @flags: Current value of flash protect flags.
1886 * @valid_flags: Flags which are valid on this platform. This allows the
1887 * caller to distinguish between flags which aren't set vs. flags
1888 * which can't be set on this platform.
1889 * @writable_flags: Flags which can be changed given the current protection
1890 * state.
1891 */
1892struct ec_response_flash_protect {
1893 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001894 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001895 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001896} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001897
1898/*
1899 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1900 * write protect. These commands may be reused with version > 0.
1901 */
1902
1903/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001904#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001905#define EC_VER_FLASH_REGION_INFO 1
1906
1907enum ec_flash_region {
1908 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001909 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001910 /*
1911 * Region which holds active RW image. 'Active' is different from
1912 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1913 * scheduled to run, active/non-active applies only to RW images (for
1914 * the same reason 'update' applies only to RW images. It's a state of
1915 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1916 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1917 * doesn't enter 'running' state but it's still active on a flash.
1918 */
1919 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001920 /*
1921 * Region which should be write-protected in the factory (a superset of
1922 * EC_FLASH_REGION_RO)
1923 */
1924 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001925 /* Region which holds updatable (non-active) RW image */
1926 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001927 /* Number of regions */
1928 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001929};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001930/*
1931 * 'RW' is vague if there are multiple RW images; we mean the active one,
1932 * so the old constant is deprecated.
1933 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001934#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001935
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001936/**
1937 * struct ec_params_flash_region_info - Parameters for the flash region info
1938 * command.
1939 * @region: Flash region; see EC_FLASH_REGION_*
1940 */
1941struct ec_params_flash_region_info {
1942 uint32_t region;
1943} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001944
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001945struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001946 uint32_t offset;
1947 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001948} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001949
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001950/* Get SPI flash information */
1951#define EC_CMD_FLASH_SPI_INFO 0x0018
1952
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001953struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001954 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1955 uint8_t jedec[3];
1956
1957 /* Pad byte; currently always contains 0 */
1958 uint8_t reserved0;
1959
1960 /* Manufacturer / device ID from command 0x90 */
1961 uint8_t mfr_dev_id[2];
1962
1963 /* Status registers from command 0x05 and 0x35 */
1964 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001965} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001966
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001967/* Select flash during flash operations */
1968#define EC_CMD_FLASH_SELECT 0x0019
1969
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001970/**
1971 * struct ec_params_flash_select - Parameters for the flash select command.
1972 * @select: 1 to select flash, 0 to deselect flash
1973 */
1974struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001975 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001976} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001977
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001978/**
1979 * Request random numbers to be generated and returned.
1980 * Can be used to test the random number generator is truly random.
1981 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1982 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1983 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001984#define EC_CMD_RAND_NUM 0x001A
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001985#define EC_VER_RAND_NUM 0
1986
1987struct ec_params_rand_num {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001988 uint16_t num_rand_bytes; /**< num random bytes to generate */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001989} __ec_align4;
1990
1991struct ec_response_rand_num {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001992 /**
1993 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
1994 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
1995 */
1996 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
1997} __ec_align1;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001998BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1999
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002000/**
2001 * Get information about the key used to sign the RW firmware.
2002 * For more details on the fields, see "struct vb21_packed_key".
2003 */
2004#define EC_CMD_RWSIG_INFO 0x001B
2005#define EC_VER_RWSIG_INFO 0
2006
2007#define VBOOT2_KEY_ID_BYTES 20
2008
2009#ifdef CHROMIUM_EC
2010/* Don't force external projects to depend on the vboot headers. */
2011#include "vb21_struct.h"
2012BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
2013#endif
2014
2015struct ec_response_rwsig_info {
2016 /**
2017 * Signature algorithm used by the key
2018 * (enum vb2_signature_algorithm).
2019 */
2020 uint16_t sig_alg;
2021
2022 /**
2023 * Hash digest algorithm used with the key
2024 * (enum vb2_hash_algorithm).
2025 */
2026 uint16_t hash_alg;
2027
2028 /** Key version. */
2029 uint32_t key_version;
2030
2031 /** Key ID (struct vb2_id). */
2032 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2033
2034 uint8_t key_is_valid;
2035
2036 /** Alignment padding. */
2037 uint8_t reserved[3];
2038} __ec_align4;
2039
2040BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2041
2042/**
2043 * Get information about the system, such as reset flags, locked state, etc.
2044 */
2045#define EC_CMD_SYSINFO 0x001C
2046#define EC_VER_SYSINFO 0
2047
2048enum sysinfo_flags {
2049 SYSTEM_IS_LOCKED = BIT(0),
2050 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2051 SYSTEM_JUMP_ENABLED = BIT(2),
2052 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08002053 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2054 /*
2055 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2056 * set and cleared when the system shuts down (not when the host event
2057 * flag is cleared).
2058 */
2059 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002060};
2061
2062struct ec_response_sysinfo {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002063 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002064 uint32_t current_image; /**< enum ec_image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002065 uint32_t flags; /**< enum sysinfo_flags */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002066} __ec_align4;
2067
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002068/*****************************************************************************/
2069/* PWM commands */
2070
2071/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002072#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002073
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002074struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002075 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002076} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002077
2078/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002079#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002081/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002082struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002083 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002084} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002085
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002086/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002087struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002088 uint32_t rpm;
2089 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002090} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002091
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002092/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002093/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002094#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002095
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002096struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002097 uint8_t percent;
2098 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002099} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002100
2101/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002102/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002103#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002104
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002105struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002106 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002107} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002108
2109/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002110#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002112/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002113struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002114 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002115} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002116
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002117/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002118struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002119 uint32_t percent;
2120 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002121} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002122
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002123#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002124/* 16 bit duty cycle, 0xffff = 100% */
2125#define EC_PWM_MAX_DUTY 0xffff
2126
2127enum ec_pwm_type {
2128 /* All types, indexed by board-specific enum pwm_channel */
2129 EC_PWM_TYPE_GENERIC = 0,
2130 /* Keyboard backlight */
2131 EC_PWM_TYPE_KB_LIGHT,
2132 /* Display backlight */
2133 EC_PWM_TYPE_DISPLAY_LIGHT,
2134 EC_PWM_TYPE_COUNT,
2135};
2136
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002137struct ec_params_pwm_set_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002138 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2139 uint8_t pwm_type; /* ec_pwm_type */
2140 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002141} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002142
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002143#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002144
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002145struct ec_params_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002146 uint8_t pwm_type; /* ec_pwm_type */
2147 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002148} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002150struct ec_response_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002151 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002152} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002153
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002154/*****************************************************************************/
2155/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002156 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002157 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2158 * into a subcommand. We'll make separate structs for subcommands with
2159 * different input args, so that we know how much to expect.
2160 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002161#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002162
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002163struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002164 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002165} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002166
Duncan Laurie433432b2013-06-03 10:38:22 -07002167#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002168
2169/*
2170 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002171 * host command, but the alignment is the same regardless. Keep it that way.
2172 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002173struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002174 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002175 int32_t google_ramp_up;
2176 int32_t google_ramp_down;
2177 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002178 int32_t s0_tick_delay[2]; /* AC=0/1 */
2179 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie93e24442014-01-06 12:30:52 -08002180 int32_t s0s3_ramp_down;
2181 int32_t s3_sleep_for;
2182 int32_t s3_ramp_up;
2183 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002184
2185 /* Oscillation */
2186 uint8_t new_s0;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002187 uint8_t osc_min[2]; /* AC=0/1 */
2188 uint8_t osc_max[2]; /* AC=0/1 */
2189 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002190
2191 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002192 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2193 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2194 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002195
2196 /* Battery level thresholds */
2197 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2198
2199 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002200 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2201 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie433432b2013-06-03 10:38:22 -07002202
2203 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002204 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002205} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002206
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002207struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002208 /* Timing */
2209 int32_t google_ramp_up;
2210 int32_t google_ramp_down;
2211 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002212 int32_t s0_tick_delay[2]; /* AC=0/1 */
2213 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002214 int32_t s0s3_ramp_down;
2215 int32_t s3_sleep_for;
2216 int32_t s3_ramp_up;
2217 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002218 int32_t s5_ramp_up;
2219 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002220 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002221 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002222 int32_t tap_display_time;
2223
2224 /* Tap-for-battery params */
2225 uint8_t tap_pct_red;
2226 uint8_t tap_pct_green;
2227 uint8_t tap_seg_min_on;
2228 uint8_t tap_seg_max_on;
2229 uint8_t tap_seg_osc;
2230 uint8_t tap_idx[3];
2231
2232 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002233 uint8_t osc_min[2]; /* AC=0/1 */
2234 uint8_t osc_max[2]; /* AC=0/1 */
2235 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002236
2237 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002238 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2239 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2240 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002241
2242 /* Battery level thresholds */
2243 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2244
2245 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002246 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2247 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002248
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002249 /* s5: single color pulse on inhibited power-up */
2250 uint8_t s5_idx;
2251
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002252 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002253 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002254} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002255
Duncan Laurieeb316852015-12-01 18:51:18 -08002256/* Lightbar command params v2
2257 * crbug.com/467716
2258 *
2259 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2260 * logical groups to make it more manageable ( < 120 bytes).
2261 *
2262 * NOTE: Each of these groups must be less than 120 bytes.
2263 */
2264
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002265struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002266 /* Timing */
2267 int32_t google_ramp_up;
2268 int32_t google_ramp_down;
2269 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002270 int32_t s0_tick_delay[2]; /* AC=0/1 */
2271 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002272 int32_t s0s3_ramp_down;
2273 int32_t s3_sleep_for;
2274 int32_t s3_ramp_up;
2275 int32_t s3_ramp_down;
2276 int32_t s5_ramp_up;
2277 int32_t s5_ramp_down;
2278 int32_t tap_tick_delay;
2279 int32_t tap_gate_delay;
2280 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002281} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002282
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002283struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002284 /* Tap-for-battery params */
2285 uint8_t tap_pct_red;
2286 uint8_t tap_pct_green;
2287 uint8_t tap_seg_min_on;
2288 uint8_t tap_seg_max_on;
2289 uint8_t tap_seg_osc;
2290 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002291} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002292
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002293struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002294 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002295 uint8_t osc_min[2]; /* AC=0/1 */
2296 uint8_t osc_max[2]; /* AC=0/1 */
2297 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002298} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002299
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002300struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002301 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002302 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2303 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2304 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002305} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002306
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002307struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002308 /* Battery level thresholds */
2309 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002310} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002311
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002312struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002313 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002314 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2315 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurieeb316852015-12-01 18:51:18 -08002316
2317 /* s5: single color pulse on inhibited power-up */
2318 uint8_t s5_idx;
2319
2320 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002321 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002322} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002323
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002324/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002325#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002326struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002327 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002328 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002329} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002330
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002331struct ec_params_lightbar {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002332 uint8_t cmd; /* Command (see enum lightbar_command) */
Duncan Laurie433432b2013-06-03 10:38:22 -07002333 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002334 /*
2335 * The following commands have no args:
2336 *
2337 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2338 * version, get_brightness, get_demo, suspend, resume,
2339 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2340 * get_params_v2_bright, get_params_v2_thlds,
2341 * get_params_v2_colors
2342 *
2343 * Don't use an empty struct, because C++ hates that.
2344 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002345
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002346 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002347 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002348 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002349
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002350 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002351 uint8_t ctrl, reg, value;
2352 } reg;
2353
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002354 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002355 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002356 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002357
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002358 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002359 uint8_t led;
2360 } get_rgb;
2361
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002362 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002363 uint8_t enable;
2364 } manual_suspend_ctrl;
2365
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002366 struct lightbar_params_v0 set_params_v0;
2367 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002368
2369 struct lightbar_params_v2_timing set_v2par_timing;
2370 struct lightbar_params_v2_tap set_v2par_tap;
2371 struct lightbar_params_v2_oscillation set_v2par_osc;
2372 struct lightbar_params_v2_brightness set_v2par_bright;
2373 struct lightbar_params_v2_thresholds set_v2par_thlds;
2374 struct lightbar_params_v2_colors set_v2par_colors;
2375
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002376 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002377 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002378} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002379
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002380struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002381 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002382 struct __ec_todo_unpacked {
2383 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002384 uint8_t reg;
2385 uint8_t ic0;
2386 uint8_t ic1;
2387 } vals[23];
2388 } dump;
2389
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002390 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002391 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002392 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002393
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002394 struct lightbar_params_v0 get_params_v0;
2395 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002396
Duncan Laurieeb316852015-12-01 18:51:18 -08002397 struct lightbar_params_v2_timing get_params_v2_timing;
2398 struct lightbar_params_v2_tap get_params_v2_tap;
2399 struct lightbar_params_v2_oscillation get_params_v2_osc;
2400 struct lightbar_params_v2_brightness get_params_v2_bright;
2401 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2402 struct lightbar_params_v2_colors get_params_v2_colors;
2403
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002404 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002405 uint32_t num;
2406 uint32_t flags;
2407 } version;
2408
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002409 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002410 uint8_t red, green, blue;
2411 } get_rgb;
2412
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002413 /*
2414 * The following commands have no response:
2415 *
2416 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2417 * set_params_v0, set_params_v1, set_program,
2418 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2419 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2420 * set_v2par_thlds, set_v2par_colors
2421 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002422 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002423} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002424
2425/* Lightbar commands */
2426enum lightbar_command {
2427 LIGHTBAR_CMD_DUMP = 0,
2428 LIGHTBAR_CMD_OFF = 1,
2429 LIGHTBAR_CMD_ON = 2,
2430 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002431 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002432 LIGHTBAR_CMD_SEQ = 5,
2433 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002434 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002435 LIGHTBAR_CMD_GET_SEQ = 8,
2436 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002437 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2438 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002439 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002440 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2441 LIGHTBAR_CMD_GET_RGB = 14,
2442 LIGHTBAR_CMD_GET_DEMO = 15,
2443 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2444 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002445 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002446 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2447 LIGHTBAR_CMD_SUSPEND = 20,
2448 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002449 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2450 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2451 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2452 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2453 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2454 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2455 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2456 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2457 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2458 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2459 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2460 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002461 LIGHTBAR_NUM_CMDS,
Duncan Laurie433432b2013-06-03 10:38:22 -07002462};
2463
2464/*****************************************************************************/
2465/* LED control commands */
2466
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002467#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002468
Bill Richardsone221aad2013-06-12 10:50:41 -07002469enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002470 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002471 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002472 /*
2473 * LED to indicate system power state (on or in suspend).
2474 * May be on power button or on C-panel.
2475 */
2476 EC_LED_ID_POWER_LED,
2477 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002478 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002479 /* LED to indicate left side */
2480 EC_LED_ID_LEFT_LED,
2481 /* LED to indicate right side */
2482 EC_LED_ID_RIGHT_LED,
2483 /* LED to indicate recovery mode with HW_REINIT */
2484 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2485 /* LED to indicate sysrq debug mode. */
2486 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002487
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002488 EC_LED_ID_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002489};
Duncan Laurie433432b2013-06-03 10:38:22 -07002490
Bill Richardsone221aad2013-06-12 10:50:41 -07002491/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002492#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002493#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002494
2495enum ec_led_colors {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002496 EC_LED_COLOR_INVALID = -1,
Bill Richardsone221aad2013-06-12 10:50:41 -07002497 EC_LED_COLOR_RED = 0,
2498 EC_LED_COLOR_GREEN,
2499 EC_LED_COLOR_BLUE,
2500 EC_LED_COLOR_YELLOW,
2501 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002502 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002503
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002504 EC_LED_COLOR_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002505};
2506
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002507struct ec_params_led_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002508 uint8_t led_id; /* Which LED to control */
2509 uint8_t flags; /* Control flags */
Bill Richardsone221aad2013-06-12 10:50:41 -07002510
2511 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002512} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002513
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002514struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002515 /*
2516 * Available brightness value range.
2517 *
2518 * Range 0 means color channel not present.
2519 * Range 1 means on/off control.
2520 * Other values means the LED is control by PWM.
2521 */
2522 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002523} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002524
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002525/*****************************************************************************/
2526/* Verified boot commands */
2527
2528/*
2529 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2530 * reused for other purposes with version > 0.
2531 */
2532
2533/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002534#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002535
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002536struct ec_params_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002537 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2538 uint8_t hash_type; /* enum ec_vboot_hash_type */
2539 uint8_t nonce_size; /* Nonce size; may be 0 */
2540 uint8_t reserved0; /* Reserved; set 0 */
2541 uint32_t offset; /* Offset in flash to hash */
2542 uint32_t size; /* Number of bytes to hash */
2543 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002544} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002545
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002546struct ec_response_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002547 uint8_t status; /* enum ec_vboot_hash_status */
2548 uint8_t hash_type; /* enum ec_vboot_hash_type */
2549 uint8_t digest_size; /* Size of hash digest in bytes */
2550 uint8_t reserved0; /* Ignore; will be 0 */
2551 uint32_t offset; /* Offset in flash which was hashed */
2552 uint32_t size; /* Number of bytes hashed */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002553 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002554} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002555
2556enum ec_vboot_hash_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002557 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2558 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2559 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2560 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002561};
2562
2563enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002564 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002565};
2566
2567enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002568 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2569 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2570 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002571};
2572
Duncan Laurie433432b2013-06-03 10:38:22 -07002573/*
2574 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2575 * If one of these is specified, the EC will automatically update offset and
2576 * size to the correct values for the specified image (RO or RW).
2577 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002578#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2579#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2580#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002581
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002582/*
2583 * 'RW' is vague if there are multiple RW images; we mean the active one,
2584 * so the old constant is deprecated.
2585 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002586#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002587
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002588/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002589/*
2590 * Motion sense commands. We'll make separate structs for sub-commands with
2591 * different input args, so that we know how much to expect.
2592 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002593#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002594
2595/* Motion sense commands */
2596enum motionsense_command {
2597 /*
2598 * Dump command returns all motion sensor data including motion sense
2599 * module flags and individual sensor flags.
2600 */
2601 MOTIONSENSE_CMD_DUMP = 0,
2602
2603 /*
2604 * Info command returns data describing the details of a given sensor,
2605 * including enum motionsensor_type, enum motionsensor_location, and
2606 * enum motionsensor_chip.
2607 */
2608 MOTIONSENSE_CMD_INFO = 1,
2609
2610 /*
2611 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002612 * in milliseconds.
2613 * It is per sensor, the EC run sample task at the minimum of all
2614 * sensors EC_RATE.
2615 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2616 * to collect all the sensor samples.
2617 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2618 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002619 */
2620 MOTIONSENSE_CMD_EC_RATE = 2,
2621
2622 /*
2623 * Sensor ODR command is a setter/getter command for the output data
2624 * rate of a specific motion sensor in millihertz.
2625 */
2626 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2627
2628 /*
2629 * Sensor range command is a setter/getter command for the range of
2630 * a specified motion sensor in +/-G's or +/- deg/s.
2631 */
2632 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2633
2634 /*
2635 * Setter/getter command for the keyboard wake angle. When the lid
2636 * angle is greater than this value, keyboard wake is disabled in S3,
2637 * and when the lid angle goes less than this value, keyboard wake is
2638 * enabled. Note, the lid angle measurement is an approximate,
2639 * un-calibrated value, hence the wake angle isn't exact.
2640 */
2641 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2642
Duncan Laurieeb316852015-12-01 18:51:18 -08002643 /*
2644 * Returns a single sensor data.
2645 */
2646 MOTIONSENSE_CMD_DATA = 6,
2647
2648 /*
2649 * Return sensor fifo info.
2650 */
2651 MOTIONSENSE_CMD_FIFO_INFO = 7,
2652
2653 /*
2654 * Insert a flush element in the fifo and return sensor fifo info.
2655 * The host can use that element to synchronize its operation.
2656 */
2657 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2658
2659 /*
2660 * Return a portion of the fifo.
2661 */
2662 MOTIONSENSE_CMD_FIFO_READ = 9,
2663
2664 /*
2665 * Perform low level calibration.
2666 * On sensors that support it, ask to do offset calibration.
2667 */
2668 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2669
2670 /*
2671 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002672 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002673 * The offsets can be calculated by the host, or via
2674 * PERFORM_CALIB command.
2675 */
2676 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2677
2678 /*
2679 * List available activities for a MOTION sensor.
2680 * Indicates if they are enabled or disabled.
2681 */
2682 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2683
2684 /*
2685 * Activity management
2686 * Enable/Disable activity recognition.
2687 */
2688 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2689
2690 /*
2691 * Lid Angle
2692 */
2693 MOTIONSENSE_CMD_LID_ANGLE = 14,
2694
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002695 /*
2696 * Allow the FIFO to trigger interrupt via MKBP events.
2697 * By default the FIFO does not send interrupt to process the FIFO
2698 * until the AP is ready or it is coming from a wakeup sensor.
2699 */
2700 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2701
2702 /*
2703 * Spoof the readings of the sensors. The spoofed readings can be set
2704 * to arbitrary values, or will lock to the last read actual values.
2705 */
2706 MOTIONSENSE_CMD_SPOOF = 16,
2707
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002708 /* Set lid angle for tablet mode detection. */
2709 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2710
2711 /*
2712 * Sensor Scale command is a setter/getter command for the calibration
2713 * scale.
2714 */
2715 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2716
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002717 /*
2718 * Read the current online calibration values (if available).
2719 */
2720 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2721
Yidi Lin42f79592020-09-21 18:04:10 +08002722 /*
2723 * Activity management
2724 * Retrieve current status of given activity.
2725 */
2726 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2727
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002728 /* Number of motionsense sub-commands. */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002729 MOTIONSENSE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002730};
2731
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002732/* List of motion sensor types. */
2733enum motionsensor_type {
2734 MOTIONSENSE_TYPE_ACCEL = 0,
2735 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002736 MOTIONSENSE_TYPE_MAG = 2,
2737 MOTIONSENSE_TYPE_PROX = 3,
2738 MOTIONSENSE_TYPE_LIGHT = 4,
2739 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002740 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002741 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002742 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002743 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002744};
2745
2746/* List of motion sensor locations. */
2747enum motionsensor_location {
2748 MOTIONSENSE_LOC_BASE = 0,
2749 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002750 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002751 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002752};
2753
2754/* List of motion sensor chips. */
2755enum motionsensor_chip {
2756 MOTIONSENSE_CHIP_KXCJ9 = 0,
2757 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002758 MOTIONSENSE_CHIP_BMI160 = 2,
2759 MOTIONSENSE_CHIP_SI1141 = 3,
2760 MOTIONSENSE_CHIP_SI1142 = 4,
2761 MOTIONSENSE_CHIP_SI1143 = 5,
2762 MOTIONSENSE_CHIP_KX022 = 6,
2763 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002764 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002765 MOTIONSENSE_CHIP_BMP280 = 9,
2766 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002767 MOTIONSENSE_CHIP_BH1730 = 11,
2768 MOTIONSENSE_CHIP_GPIO = 12,
2769 MOTIONSENSE_CHIP_LIS2DH = 13,
2770 MOTIONSENSE_CHIP_LSM6DSM = 14,
2771 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002772 MOTIONSENSE_CHIP_LIS2MDL = 16,
2773 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2774 MOTIONSENSE_CHIP_LSM6DSO = 18,
2775 MOTIONSENSE_CHIP_LNG2DM = 19,
2776 MOTIONSENSE_CHIP_TCS3400 = 20,
2777 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2778 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002779 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002780 MOTIONSENSE_CHIP_BMI260 = 24,
2781 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002782 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002783 MOTIONSENSE_CHIP_BMA422 = 27,
2784 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002785 MOTIONSENSE_CHIP_BMI220 = 29,
2786 MOTIONSENSE_CHIP_CM32183 = 30,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002787 MOTIONSENSE_CHIP_MAX,
2788};
2789
2790/* List of orientation positions */
2791enum motionsensor_orientation {
2792 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2793 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2794 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2795 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2796 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002797};
2798
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002799struct ec_response_activity_data {
2800 uint8_t activity; /* motionsensor_activity */
2801 uint8_t state;
2802} __ec_todo_packed;
2803
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002804struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002805 /* Flags for each sensor. */
2806 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002807 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002808 uint8_t sensor_num;
2809 /* Each sensor is up to 3-axis. */
2810 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002811 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002812 /* for sensors using unsigned data */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002813 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002814 struct __ec_todo_packed {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002815 uint16_t reserved;
2816 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002817 };
2818 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002819 struct ec_response_activity_data activity_data;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002820 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002821 };
2822 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002823} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002824
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002825/* Response to AP reporting calibration data for a given sensor. */
2826struct ec_response_online_calibration_data {
2827 /** The calibration values. */
2828 int16_t data[3];
2829};
2830
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002831/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002832struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002833 /* Size of the fifo */
2834 uint16_t size;
2835 /* Amount of space used in the fifo */
2836 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002837 /* Timestamp recorded in us.
2838 * aka accurate timestamp when host event was triggered.
2839 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002840 uint32_t timestamp;
2841 /* Total amount of vector lost */
2842 uint16_t total_lost;
2843 /* Lost events since the last fifo_info, per sensors */
2844 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002845} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002846
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002847struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002848 uint32_t number_data;
2849 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002850} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002851
2852/* List supported activity recognition */
2853enum motionsensor_activity {
2854 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2855 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2856 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002857 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002858 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002859};
2860
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002861struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002862 uint8_t sensor_num;
2863 uint8_t activity; /* one of enum motionsensor_activity */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002864 uint8_t enable; /* 1: enable, 0: disable */
Duncan Laurieeb316852015-12-01 18:51:18 -08002865 uint8_t reserved;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002866 uint16_t parameters[4]; /* activity dependent parameters */
2867} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002868
2869/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002870#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002871
2872/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002873#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002874
2875/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002876 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002877 * data contains time stamp
2878 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002879#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2880#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2881#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2882#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2883#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002884
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002885#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2886
Duncan Laurieeb316852015-12-01 18:51:18 -08002887/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002888 * Send this value for the data element to only perform a read. If you
2889 * send any other value, the EC will interpret it as data to set and will
2890 * return the actual value set.
2891 */
2892#define EC_MOTION_SENSE_NO_VALUE -1
2893
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002894#define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
Duncan Laurieeb316852015-12-01 18:51:18 -08002895
2896/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2897/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002898#define MOTION_SENSE_SET_OFFSET BIT(0)
2899
2900/* Default Scale value, factor 1. */
2901#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002902
2903#define LID_ANGLE_UNRELIABLE 500
2904
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002905enum motionsense_spoof_mode {
2906 /* Disable spoof mode. */
2907 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2908
2909 /* Enable spoof mode, but use provided component values. */
2910 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2911
2912 /* Enable spoof mode, but use the current sensor values. */
2913 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2914
2915 /* Query the current spoof mode status for the sensor. */
2916 MOTIONSENSE_SPOOF_MODE_QUERY,
2917};
2918
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002919struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002920 uint8_t cmd;
2921 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002922 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002923 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002924 /*
2925 * Maximal number of sensor the host is expecting.
2926 * 0 means the host is only interested in the number
2927 * of sensors controlled by the EC.
2928 */
2929 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002930 } dump;
2931
2932 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002933 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002934 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002935 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002936 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002937 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08002938 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002939 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002940 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002941
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002942 /*
2943 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2944 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002945 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002946 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002947 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002948
2949 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002950 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2951 * Allow entering/exiting the calibration mode.
2952 */
2953 struct __ec_todo_unpacked {
2954 uint8_t sensor_num;
2955 uint8_t enable;
2956 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002957
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002958 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002959 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2960 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002961 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002962 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002963 uint8_t sensor_num;
2964
2965 /* Rounding flag, true for round-up, false for down. */
2966 uint8_t roundup;
2967
2968 uint16_t reserved;
2969
2970 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2971 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002972 } ec_rate, sensor_odr, sensor_range;
2973
2974 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002975 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002976 uint8_t sensor_num;
2977
2978 /*
2979 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2980 * the calibration information in the EC.
2981 * If unset, just retrieve calibration information.
2982 */
2983 uint16_t flags;
2984
2985 /*
2986 * Temperature at calibration, in units of 0.01 C
2987 * 0x8000: invalid / unknown.
2988 * 0x0: 0C
2989 * 0x7fff: +327.67C
2990 */
2991 int16_t temp;
2992
2993 /*
2994 * Offset for calibration.
2995 * Unit:
2996 * Accelerometer: 1/1024 g
2997 * Gyro: 1/1024 deg/s
2998 * Compass: 1/16 uT
2999 */
3000 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003001 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08003002
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003003 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3004 struct __ec_todo_packed {
3005 uint8_t sensor_num;
3006
3007 /*
3008 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3009 * the calibration information in the EC.
3010 * If unset, just retrieve calibration information.
3011 */
3012 uint16_t flags;
3013
3014 /*
3015 * Temperature at calibration, in units of 0.01 C
3016 * 0x8000: invalid / unknown.
3017 * 0x0: 0C
3018 * 0x7fff: +327.67C
3019 */
3020 int16_t temp;
3021
3022 /*
3023 * Scale for calibration:
3024 * By default scale is 1, it is encoded on 16bits:
3025 * 1 = BIT(15)
3026 * ~2 = 0xFFFF
3027 * ~0 = 0.
3028 */
3029 uint16_t scale[3];
3030 } sensor_scale;
3031
Duncan Laurieeb316852015-12-01 18:51:18 -08003032 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003033 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08003034
3035 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003036 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003037 /*
3038 * Number of expected vector to return.
3039 * EC may return less or 0 if none available.
3040 */
3041 uint32_t max_data_vector;
3042 } fifo_read;
3043
Yidi Lin42f79592020-09-21 18:04:10 +08003044 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08003045 struct ec_motion_sense_activity set_activity;
3046
3047 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003048 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003049
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003050 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3051 struct __ec_todo_unpacked {
3052 /*
3053 * 1: enable, 0 disable fifo,
3054 * EC_MOTION_SENSE_NO_VALUE return value.
3055 */
3056 int8_t enable;
3057 } fifo_int_enable;
3058
3059 /* Used for MOTIONSENSE_CMD_SPOOF */
3060 struct __ec_todo_packed {
3061 uint8_t sensor_id;
3062
3063 /* See enum motionsense_spoof_mode. */
3064 uint8_t spoof_enable;
3065
3066 /* Ignored, used for alignment. */
3067 uint8_t reserved;
3068
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003069 union {
3070 /* Individual component values to spoof. */
3071 int16_t components[3];
3072
3073 /* Used when spoofing an activity */
3074 struct {
3075 /* enum motionsensor_activity */
3076 uint8_t activity_num;
3077
3078 /* spoof activity state */
3079 uint8_t activity_state;
3080 };
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003081 } __ec_todo_packed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003082 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003083
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003084 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3085 struct __ec_todo_unpacked {
3086 /*
3087 * Lid angle threshold for switching between tablet and
3088 * clamshell mode.
3089 */
3090 int16_t lid_angle;
3091
3092 /*
3093 * Hysteresis degree to prevent fluctuations between
3094 * clamshell and tablet mode if lid angle keeps
3095 * changing around the threshold. Lid motion driver will
3096 * use lid_angle + hys_degree to trigger tablet mode and
3097 * lid_angle - hys_degree to trigger clamshell mode.
3098 */
3099 int16_t hys_degree;
3100 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003101
3102 /*
3103 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3104 * Allow reading a single sensor's online calibration value.
3105 */
3106 struct __ec_todo_unpacked {
3107 uint8_t sensor_num;
3108 } online_calib_read;
3109
Yidi Lin42f79592020-09-21 18:04:10 +08003110 /*
3111 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3112 */
3113 struct __ec_todo_unpacked {
3114 uint8_t sensor_num;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003115 uint8_t activity; /* enum motionsensor_activity */
Yidi Lin42f79592020-09-21 18:04:10 +08003116 } get_activity;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003117 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003118} __ec_todo_packed;
3119
Jett Rinkba2edaf2020-01-14 11:49:06 -07003120enum motion_sense_cmd_info_flags {
3121 /* The sensor supports online calibration */
3122 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3123};
3124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003125struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003126 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003127 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003128 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003129 /* Flags representing the motion sensor module. */
3130 uint8_t module_flags;
3131
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003132 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003133 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003134
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003135 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003136 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003137 * for holding all the data.
3138 */
3139 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003140 } dump;
3141
3142 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003143 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003144 /* Should be element of enum motionsensor_type. */
3145 uint8_t type;
3146
3147 /* Should be element of enum motionsensor_location. */
3148 uint8_t location;
3149
3150 /* Should be element of enum motionsensor_chip. */
3151 uint8_t chip;
3152 } info;
3153
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003154 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3155 struct __ec_todo_unpacked {
3156 /* Should be element of enum motionsensor_type. */
3157 uint8_t type;
3158
3159 /* Should be element of enum motionsensor_location. */
3160 uint8_t location;
3161
3162 /* Should be element of enum motionsensor_chip. */
3163 uint8_t chip;
3164
3165 /* Minimum sensor sampling frequency */
3166 uint32_t min_frequency;
3167
3168 /* Maximum sensor sampling frequency */
3169 uint32_t max_frequency;
3170
3171 /* Max number of sensor events that could be in fifo */
3172 uint32_t fifo_max_event_count;
3173 } info_3;
3174
Jett Rinkba2edaf2020-01-14 11:49:06 -07003175 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3176 struct __ec_align4 {
3177 /* Should be element of enum motionsensor_type. */
3178 uint8_t type;
3179
3180 /* Should be element of enum motionsensor_location. */
3181 uint8_t location;
3182
3183 /* Should be element of enum motionsensor_chip. */
3184 uint8_t chip;
3185
3186 /* Minimum sensor sampling frequency */
3187 uint32_t min_frequency;
3188
3189 /* Maximum sensor sampling frequency */
3190 uint32_t max_frequency;
3191
3192 /* Max number of sensor events that could be in fifo */
3193 uint32_t fifo_max_event_count;
3194
3195 /*
3196 * Should be elements of
3197 * enum motion_sense_cmd_info_flags
3198 */
3199 uint32_t flags;
3200 } info_4;
3201
Duncan Laurieeb316852015-12-01 18:51:18 -08003202 /* Used for MOTIONSENSE_CMD_DATA */
3203 struct ec_response_motion_sensor_data data;
3204
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003205 /*
3206 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003207 * MOTIONSENSE_CMD_SENSOR_RANGE,
3208 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3209 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3210 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003211 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003212 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003213 /* Current value of the parameter queried. */
3214 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003215 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Caveh Jalali024ffe32023-01-30 14:35:19 -08003216 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003218 /*
3219 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3220 * PERFORM_CALIB.
3221 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003222 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003223 int16_t temp;
3224 int16_t offset[3];
3225 } sensor_offset, perform_calib;
3226
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003227 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003228 struct __ec_todo_unpacked {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003229 int16_t temp;
3230 uint16_t scale[3];
3231 } sensor_scale;
3232
Duncan Laurieeb316852015-12-01 18:51:18 -08003233 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3234
3235 struct ec_response_motion_sense_fifo_data fifo_read;
3236
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003237 struct ec_response_online_calibration_data online_calib_read;
3238
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003239 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003240 uint16_t reserved;
3241 uint32_t enabled;
3242 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003243 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003244
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003245 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003246
Duncan Laurieeb316852015-12-01 18:51:18 -08003247 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003248 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003249 /*
3250 * Angle between 0 and 360 degree if available,
3251 * LID_ANGLE_UNRELIABLE otherwise.
3252 */
3253 uint16_t value;
3254 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003255
3256 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3257 struct __ec_todo_unpacked {
3258 /*
3259 * Lid angle threshold for switching between tablet and
3260 * clamshell mode.
3261 */
3262 uint16_t lid_angle;
3263
3264 /* Hysteresis degree. */
3265 uint16_t hys_degree;
3266 } tablet_mode_threshold;
3267
Yidi Lin42f79592020-09-21 18:04:10 +08003268 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3269 struct __ec_todo_unpacked {
3270 uint8_t state;
3271 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003272 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003273} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003274
3275/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003276/* Force lid open command */
3277
3278/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003279#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003280
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003281struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003282 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003283} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003284
3285/*****************************************************************************/
3286/* Configure the behavior of the power button */
3287#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3288
3289enum ec_config_power_button_flags {
3290 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003291 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003292};
3293
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003294struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003295 /* See enum ec_config_power_button_flags */
3296 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003297} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003298
3299/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003300/* USB charging control commands */
3301
3302/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003303#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003304
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003305enum usb_charge_mode {
3306 /* Disable USB port. */
3307 USB_CHARGE_MODE_DISABLED,
3308 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3309 USB_CHARGE_MODE_SDP2,
3310 /* Set USB port to Charging Downstream Port, BC 1.2. */
3311 USB_CHARGE_MODE_CDP,
3312 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3313 USB_CHARGE_MODE_DCP_SHORT,
3314 /* Enable USB port (for dumb ports). */
3315 USB_CHARGE_MODE_ENABLED,
3316 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3317 USB_CHARGE_MODE_DEFAULT,
3318
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003319 USB_CHARGE_MODE_COUNT,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003320};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003321
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003322enum usb_suspend_charge {
3323 /* Enable charging in suspend */
3324 USB_ALLOW_SUSPEND_CHARGE,
3325 /* Disable charging in suspend */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003326 USB_DISALLOW_SUSPEND_CHARGE,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003327};
3328
3329struct ec_params_usb_charge_set_mode {
3330 uint8_t usb_port_id;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003331 uint8_t mode : 7; /* enum usb_charge_mode */
3332 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003333} __ec_align1;
3334
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003335/*****************************************************************************/
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003336/* Tablet mode commands */
3337
3338/* Set tablet mode */
3339#define EC_CMD_SET_TABLET_MODE 0x0031
3340
3341enum tablet_mode_override {
3342 TABLET_MODE_DEFAULT,
3343 TABLET_MODE_FORCE_TABLET,
3344 TABLET_MODE_FORCE_CLAMSHELL,
3345};
3346
3347struct ec_params_set_tablet_mode {
3348 uint8_t tablet_mode; /* enum tablet_mode_override */
3349} __ec_align1;
3350
3351/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003352/* Persistent storage for host */
3353
3354/* Maximum bytes that can be read/written in a single command */
3355#define EC_PSTORE_SIZE_MAX 64
3356
3357/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003358#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003360struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003361 /* Persistent storage size, in bytes */
3362 uint32_t pstore_size;
3363 /* Access size; read/write offset and size must be a multiple of this */
3364 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003365} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003366
3367/*
3368 * Read persistent storage
3369 *
3370 * Response is params.size bytes of data.
3371 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003372#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003373
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003374struct ec_params_pstore_read {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003375 uint32_t offset; /* Byte offset to read */
3376 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003377} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003378
3379/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003380#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003381
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003382struct ec_params_pstore_write {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003383 uint32_t offset; /* Byte offset to write */
3384 uint32_t size; /* Size to write in bytes */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003385 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003386} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003387
3388/*****************************************************************************/
3389/* Real-time clock */
3390
3391/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003392struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003393 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003394} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003395
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003396struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003397 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003398} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003399
3400/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003401#define EC_CMD_RTC_GET_VALUE 0x0044
3402#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003403
3404/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003405#define EC_CMD_RTC_SET_VALUE 0x0046
3406#define EC_CMD_RTC_SET_ALARM 0x0047
3407
3408/* Pass as time param to SET_ALARM to clear the current alarm */
3409#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003410
3411/*****************************************************************************/
3412/* Port80 log access */
3413
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003414/* Maximum entries that can be read/written in a single command */
3415#define EC_PORT80_SIZE_MAX 32
3416
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003417/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003418#define EC_CMD_PORT80_LAST_BOOT 0x0048
3419#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003420
3421enum ec_port80_subcmd {
3422 EC_PORT80_GET_INFO = 0,
3423 EC_PORT80_READ_BUFFER,
3424};
3425
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003426struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003427 uint16_t subcmd;
3428 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003429 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003430 uint32_t offset;
3431 uint32_t num_entries;
3432 } read_buffer;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003433 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003434} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003435
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003436struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003437 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003438 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003439 uint32_t writes;
3440 uint32_t history_size;
3441 uint32_t last_boot;
3442 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003443 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003444 uint16_t codes[EC_PORT80_SIZE_MAX];
3445 } data;
3446 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003447} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003448
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003449struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003450 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003451} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003452
3453/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003454/* Temporary secure storage for host verified boot use */
3455
3456/* Number of bytes in a vstore slot */
3457#define EC_VSTORE_SLOT_SIZE 64
3458
3459/* Maximum number of vstore slots */
3460#define EC_VSTORE_SLOT_MAX 32
3461
3462/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003463#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003464struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003465 /* Indicates which slots are locked */
3466 uint32_t slot_locked;
3467 /* Total number of slots available */
3468 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003469} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003470
3471/*
3472 * Read temporary secure storage
3473 *
3474 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3475 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003476#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003477
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003478struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003479 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003480} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003481
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003482struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003483 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003484} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003485
3486/*
3487 * Write temporary secure storage and lock it.
3488 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003489#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003490
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003491struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003492 uint8_t slot; /* Slot to write to */
3493 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003494} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003495
3496/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003497/* Thermal engine commands. Note that there are two implementations. We'll
3498 * reuse the command number, but the data and behavior is incompatible.
3499 * Version 0 is what originally shipped on Link.
3500 * Version 1 separates the CPU thermal limits from the fan control.
3501 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003502
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003503#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3504#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003505
Duncan Laurie93e24442014-01-06 12:30:52 -08003506/* The version 0 structs are opaque. You have to know what they are for
3507 * the get/set commands to make any sense.
3508 */
3509
3510/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003511struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003512 uint8_t sensor_type;
3513 uint8_t threshold_id;
3514 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003515} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003516
Duncan Laurie93e24442014-01-06 12:30:52 -08003517/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003518struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003519 uint8_t sensor_type;
3520 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003521} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003522
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003523struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003524 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003525} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003526
Duncan Laurie93e24442014-01-06 12:30:52 -08003527/* The version 1 structs are visible. */
3528enum ec_temp_thresholds {
3529 EC_TEMP_THRESH_WARN = 0,
3530 EC_TEMP_THRESH_HIGH,
3531 EC_TEMP_THRESH_HALT,
3532
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003533 EC_TEMP_THRESH_COUNT,
Duncan Laurie93e24442014-01-06 12:30:52 -08003534};
3535
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003536/*
3537 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003538 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003539 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003540 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3541 * hysteresis.
3542 * For example,
3543 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3544 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3545 * EC will throttle ap when temperature >= 301 K, and release throttling when
3546 * temperature <= 299 K.
3547 *
3548 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3549 * For example,
3550 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3551 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3552 * EC will throttle ap when temperature >= 301 K, and release throttling when
3553 * temperature <= 294 K.
3554 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003555 * Note that this structure is a sub-structure of
3556 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003557 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003558struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003559 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003560 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003561 uint32_t temp_fan_off; /* no active cooling needed */
3562 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003563} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003564
3565/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003566struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003567 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003568} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003569/* This returns a struct ec_thermal_config */
3570
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003571/*
3572 * Version 1 - set config for one sensor.
3573 * Use read-modify-write for best results!
3574 */
3575struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003576 uint32_t sensor_num;
3577 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003578} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003579/* This returns no data */
3580
3581/****************************************************************************/
3582
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003583/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003584#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003585
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003586/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003587struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003588 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003589} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003590
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003591/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003592#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3593#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003594
3595/*
3596 * The original TMP006 calibration only needed four params, but now we need
3597 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3598 * the params opaque. The v1 "get" response will include the algorithm number
3599 * and how many params it requires. That way we can change the EC code without
3600 * needing to update this file. We can also use a different algorithm on each
3601 * sensor.
3602 */
3603
3604/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003605struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003606 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003607} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003608
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003609/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003610struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003611 float s0;
3612 float b0;
3613 float b1;
3614 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003615} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003616
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003617struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003618 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003619 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003620 float s0;
3621 float b0;
3622 float b1;
3623 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003624} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003625
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003626/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003627struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003628 uint8_t algorithm;
3629 uint8_t num_params;
3630 uint8_t reserved[2];
3631 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003632} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003633
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003634struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003635 uint8_t index;
3636 uint8_t algorithm;
3637 uint8_t num_params;
3638 uint8_t reserved;
3639 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003640} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003641
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003642/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003643#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003644
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003645struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003646 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003647} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003648
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003649struct ec_response_tmp006_get_raw {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003650 int32_t t; /* In 1/100 K */
3651 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003652} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003653
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003654/*****************************************************************************/
3655/* MKBP - Matrix KeyBoard Protocol */
3656
3657/*
3658 * Read key state
3659 *
3660 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3661 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003662 *
3663 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3664 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3665 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003666 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003667#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003668
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003669/*
3670 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3671 */
3672#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003673
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003674struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003675 uint32_t rows;
3676 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003677 /* Formerly "switches", which was 0. */
3678 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003679} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003680
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003681struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003682 uint8_t info_type;
3683 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003684} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003685
3686enum ec_mkbp_info_type {
3687 /*
3688 * Info about the keyboard matrix: number of rows and columns.
3689 *
3690 * Returns struct ec_response_mkbp_info.
3691 */
3692 EC_MKBP_INFO_KBD = 0,
3693
3694 /*
3695 * For buttons and switches, info about which specifically are
3696 * supported. event_type must be set to one of the values in enum
3697 * ec_mkbp_event.
3698 *
3699 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3700 * bitmask indicating which buttons or switches are present. See the
3701 * bit inidices below.
3702 */
3703 EC_MKBP_INFO_SUPPORTED = 1,
3704
3705 /*
3706 * Instantaneous state of buttons and switches.
3707 *
3708 * event_type must be set to one of the values in enum ec_mkbp_event.
3709 *
3710 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3711 * indicating the current state of the keyboard matrix.
3712 *
3713 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3714 * event state.
3715 *
3716 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3717 * state of supported buttons.
3718 *
3719 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3720 * state of supported switches.
3721 */
3722 EC_MKBP_INFO_CURRENT = 2,
3723};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003724
3725/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003726#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003727
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003728struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003729 uint8_t col;
3730 uint8_t row;
3731 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003732} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003733
Duncan Laurie433432b2013-06-03 10:38:22 -07003734/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003735#define EC_CMD_MKBP_SET_CONFIG 0x0064
3736#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003737
3738/* flags */
3739enum mkbp_config_flags {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003740 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
Duncan Laurie433432b2013-06-03 10:38:22 -07003741};
3742
3743enum mkbp_config_valid {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003744 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3745 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3746 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3747 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3748 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3749 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3750 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003751};
3752
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003753/*
3754 * Configuration for our key scanning algorithm.
3755 *
3756 * Note that this is used as a sub-structure of
3757 * ec_{params/response}_mkbp_get_config.
3758 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003759struct ec_mkbp_config {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003760 uint32_t valid_mask; /* valid fields */
3761 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3762 uint8_t valid_flags; /* which flags are valid */
3763 uint16_t scan_period_us; /* period between start of scans */
Duncan Laurie433432b2013-06-03 10:38:22 -07003764 /* revert to interrupt mode after no activity for this long */
3765 uint32_t poll_timeout_us;
3766 /*
3767 * minimum post-scan relax time. Once we finish a scan we check
3768 * the time until we are due to start the next one. If this time is
3769 * shorter this field, we use this instead.
3770 */
3771 uint16_t min_post_scan_delay_us;
3772 /* delay between setting up output and waiting for it to settle */
3773 uint16_t output_settle_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003774 uint16_t debounce_down_us; /* time for debounce on key down */
3775 uint16_t debounce_up_us; /* time for debounce on key up */
Duncan Laurie433432b2013-06-03 10:38:22 -07003776 /* maximum depth to allow for fifo (0 = no keyscan output) */
3777 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003778} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003779
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003780struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003781 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003782} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003783
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003784struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003785 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003786} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003787
3788/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003789#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003790
3791enum ec_keyscan_seq_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003792 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3793 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3794 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3795 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3796 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003797};
3798
3799enum ec_collect_flags {
3800 /*
3801 * Indicates this scan was processed by the EC. Due to timing, some
3802 * scans may be skipped.
3803 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003804 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003805};
3806
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003807struct ec_collect_item {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003808 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003809} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003810
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003811struct ec_params_keyscan_seq_ctrl {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003812 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
Duncan Laurie433432b2013-06-03 10:38:22 -07003813 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003814 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003815 uint8_t active; /* still active */
3816 uint8_t num_items; /* number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003817 /* Current item being presented */
3818 uint8_t cur_item;
3819 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003820 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003821 /*
3822 * Absolute time for this scan, measured from the
3823 * start of the sequence.
3824 */
3825 uint32_t time_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003826 uint8_t scan[0]; /* keyscan data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003827 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003828 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003829 uint8_t start_item; /* First item to return */
3830 uint8_t num_items; /* Number of items to return */
Duncan Laurie433432b2013-06-03 10:38:22 -07003831 } collect;
3832 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003833} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003834
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003835struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003836 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003837 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003838 uint8_t num_items; /* Number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003839 /* Data for each item */
3840 struct ec_collect_item item[0];
3841 } collect;
3842 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003843} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003844
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003845/*
3846 * Get the next pending MKBP event.
3847 *
3848 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3849 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003850#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003852#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3853
3854/*
3855 * We use the most significant bit of the event type to indicate to the host
3856 * that the EC has more MKBP events available to provide.
3857 */
3858#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3859
3860/* The mask to apply to get the raw event type */
3861#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3862
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003863enum ec_mkbp_event {
3864 /* Keyboard matrix changed. The event data is the new matrix state. */
3865 EC_MKBP_EVENT_KEY_MATRIX = 0,
3866
3867 /* New host event. The event data is 4 bytes of host event flags. */
3868 EC_MKBP_EVENT_HOST_EVENT = 1,
3869
Duncan Laurieeb316852015-12-01 18:51:18 -08003870 /* New Sensor FIFO data. The event data is fifo_info structure. */
3871 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3872
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003873 /* The state of the non-matrixed buttons have changed. */
3874 EC_MKBP_EVENT_BUTTON = 3,
3875
3876 /* The state of the switches have changed. */
3877 EC_MKBP_EVENT_SWITCH = 4,
3878
3879 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3880 EC_MKBP_EVENT_FINGERPRINT = 5,
3881
3882 /*
3883 * Sysrq event: send emulated sysrq. The event data is sysrq,
3884 * corresponding to the key to be pressed.
3885 */
3886 EC_MKBP_EVENT_SYSRQ = 6,
3887
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003888 /*
3889 * New 64-bit host event.
3890 * The event data is 8 bytes of host event flags.
3891 */
3892 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3893
3894 /* Notify the AP that something happened on CEC */
3895 EC_MKBP_EVENT_CEC_EVENT = 8,
3896
3897 /* Send an incoming CEC message to the AP */
3898 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003900 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3901 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3902
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003903 /* New online calibration values are available. */
3904 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3905
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003906 /* Peripheral device charger event */
3907 EC_MKBP_EVENT_PCHG = 12,
3908
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003909 /* Number of MKBP events */
3910 EC_MKBP_EVENT_COUNT,
3911};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003912BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003913
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003914/* clang-format off */
3915#define EC_MKBP_EVENT_TEXT \
3916 { \
3917 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
3918 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
3919 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
3920 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
3921 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
3922 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
3923 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
3924 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
3925 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
3926 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
3927 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
3928 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
3929 [EC_MKBP_EVENT_PCHG] = "PCHG", \
3930 }
3931/* clang-format on */
3932
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003933union __ec_align_offset1 ec_response_get_next_data {
3934 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003935
3936 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003937 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003938 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003939
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003940 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003941 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003942 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003943 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003944 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003945
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003946 uint32_t buttons;
3947
3948 uint32_t switches;
3949
3950 uint32_t fp_events;
3951
3952 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003953
3954 /* CEC events from enum mkbp_cec_event */
3955 uint32_t cec_events;
3956};
3957
3958union __ec_align_offset1 ec_response_get_next_data_v1 {
3959 uint8_t key_matrix[16];
3960
3961 /* Unaligned */
3962 uint32_t host_event;
3963 uint64_t host_event64;
3964
3965 struct __ec_todo_unpacked {
3966 /* For aligning the fifo_info */
3967 uint8_t reserved[3];
3968 struct ec_response_motion_sense_fifo_info info;
3969 } sensor_fifo;
3970
3971 uint32_t buttons;
3972
3973 uint32_t switches;
3974
3975 uint32_t fp_events;
3976
3977 uint32_t sysrq;
3978
3979 /* CEC events from enum mkbp_cec_event */
3980 uint32_t cec_events;
3981
3982 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003983};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003984BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003985
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003986struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003987 uint8_t event_type;
3988 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003989 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003990} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003991
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003992struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003993 uint8_t event_type;
3994 /* Followed by event data if any */
3995 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003996} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003997
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003998/* Bit indices for buttons and switches.*/
3999/* Buttons */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004000#define EC_MKBP_POWER_BUTTON 0
4001#define EC_MKBP_VOL_UP 1
4002#define EC_MKBP_VOL_DOWN 2
4003#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004004
4005/* Switches */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004006#define EC_MKBP_LID_OPEN 0
4007#define EC_MKBP_TABLET_MODE 1
4008#define EC_MKBP_BASE_ATTACHED 2
4009#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004010
Gwendal Grignou880b4582016-06-20 08:49:25 -07004011/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004012#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07004013
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004014struct ec_response_keyboard_factory_test {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004015 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004016} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004017
4018/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004019#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF)
4020#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004021#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
Caveh Jalali024ffe32023-01-30 14:35:19 -08004022#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
4023 (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004024#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4025#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
Caveh Jalali024ffe32023-01-30 14:35:19 -08004026#define EC_MKBP_FP_MATCH_IDX(fpe) \
4027 (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
4028#define EC_MKBP_FP_ENROLL BIT(27)
4029#define EC_MKBP_FP_MATCH BIT(28)
4030#define EC_MKBP_FP_FINGER_DOWN BIT(29)
4031#define EC_MKBP_FP_FINGER_UP BIT(30)
4032#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004033/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004034#define EC_MKBP_FP_ERR_ENROLL_OK 0
4035#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4036#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4037#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4038#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004039/* Can be used to detect if image was usable for enrollment or not. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004040#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004041/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004042#define EC_MKBP_FP_ERR_MATCH_NO 0
4043#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4044#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
4045#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4046#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4047#define EC_MKBP_FP_ERR_MATCH_YES 1
4048#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004049#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4050
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004051#define EC_CMD_MKBP_WAKE_MASK 0x0069
4052enum ec_mkbp_event_mask_action {
4053 /* Retrieve the value of a wake mask. */
4054 GET_WAKE_MASK = 0,
4055
4056 /* Set the value of a wake mask. */
4057 SET_WAKE_MASK,
4058};
4059
4060enum ec_mkbp_mask_type {
4061 /*
4062 * These are host events sent via MKBP.
4063 *
4064 * Some examples are:
4065 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4066 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4067 *
4068 * The only things that should be in this mask are:
4069 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4070 */
4071 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4072
4073 /*
4074 * These are MKBP events. Some examples are:
4075 *
4076 * EC_MKBP_EVENT_KEY_MATRIX
4077 * EC_MKBP_EVENT_SWITCH
4078 *
4079 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4080 */
4081 EC_MKBP_EVENT_WAKE_MASK,
4082};
4083
4084struct ec_params_mkbp_event_wake_mask {
4085 /* One of enum ec_mkbp_event_mask_action */
4086 uint8_t action;
4087
4088 /*
4089 * Which MKBP mask are you interested in acting upon? This is one of
4090 * ec_mkbp_mask_type.
4091 */
4092 uint8_t mask_type;
4093
4094 /* If setting a new wake mask, this contains the mask to set. */
4095 uint32_t new_wake_mask;
4096};
4097
4098struct ec_response_mkbp_event_wake_mask {
4099 uint32_t wake_mask;
4100};
4101
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004102/*****************************************************************************/
4103/* Temperature sensor commands */
4104
4105/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004106#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004107
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004108struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004109 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004110} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004111
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004112struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004113 char sensor_name[32];
4114 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004115} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004116
4117/*****************************************************************************/
4118
4119/*
4120 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4121 * commands accidentally sent to the wrong interface. See the ACPI section
4122 * below.
4123 */
4124
4125/*****************************************************************************/
4126/* Host event commands */
4127
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004128/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004129/*
4130 * Host event mask params and response structures, shared by all of the host
4131 * event commands below.
4132 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004133struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004134 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004135} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004136
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004137struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004138 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004139} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004140
4141/* These all use ec_response_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004142#define EC_CMD_HOST_EVENT_GET_B 0x0087
4143#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4144#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004145#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004146
4147/* These all use ec_params_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004148#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4149#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4150#define EC_CMD_HOST_EVENT_CLEAR 0x008C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004151#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
Caveh Jalali024ffe32023-01-30 14:35:19 -08004152#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004153
Jenny TC1dfc2c32017-12-14 14:24:39 +05304154/*
4155 * Unified host event programming interface - Should be used by newer versions
4156 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004157 *
4158 * EC returns:
4159 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4160 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304161 */
4162
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004163struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304164 /* Action requested by host - one of enum ec_host_event_action. */
4165 uint8_t action;
4166
4167 /*
4168 * Mask type that the host requested the action on - one of
4169 * enum ec_host_event_mask_type.
4170 */
4171 uint8_t mask_type;
4172
4173 /* Set to 0, ignore on read */
4174 uint16_t reserved;
4175
4176 /* Value to be used in case of set operations. */
4177 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004178} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304179
4180/*
4181 * Response structure returned by EC_CMD_HOST_EVENT.
4182 * Update the value on a GET request. Set to 0 on GET/CLEAR
4183 */
4184
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004185struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304186 /* Mask value in case of get operation */
4187 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004188} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304189
4190enum ec_host_event_action {
4191 /*
4192 * params.value is ignored. Value of mask_type populated
4193 * in response.value
4194 */
4195 EC_HOST_EVENT_GET,
4196
4197 /* Bits in params.value are set */
4198 EC_HOST_EVENT_SET,
4199
4200 /* Bits in params.value are cleared */
4201 EC_HOST_EVENT_CLEAR,
4202};
4203
4204enum ec_host_event_mask_type {
4205
4206 /* Main host event copy */
4207 EC_HOST_EVENT_MAIN,
4208
4209 /* Copy B of host events */
4210 EC_HOST_EVENT_B,
4211
4212 /* SCI Mask */
4213 EC_HOST_EVENT_SCI_MASK,
4214
4215 /* SMI Mask */
4216 EC_HOST_EVENT_SMI_MASK,
4217
4218 /* Mask of events that should be always reported in hostevents */
4219 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4220
4221 /* Active wake mask */
4222 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4223
4224 /* Lazy wake mask for S0ix */
4225 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4226
4227 /* Lazy wake mask for S3 */
4228 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4229
4230 /* Lazy wake mask for S5 */
4231 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4232};
4233
Caveh Jalali024ffe32023-01-30 14:35:19 -08004234#define EC_CMD_HOST_EVENT 0x00A4
Jenny TC1dfc2c32017-12-14 14:24:39 +05304235
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004236/*****************************************************************************/
4237/* Switch commands */
4238
4239/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004240#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004241
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004242struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004243 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004244} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004245
4246/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004247#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004248#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004249
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004250/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004251struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004252 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004253} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004254
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004255/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004256struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004257 /* Flags to enable now */
4258 uint8_t now_flags;
4259
4260 /* Which flags to copy from now_flags */
4261 uint8_t now_mask;
4262
4263 /*
4264 * Flags to leave enabled in S3, if they're on at the S0->S3
4265 * transition. (Other flags will be disabled by the S0->S3
4266 * transition.)
4267 */
4268 uint8_t suspend_flags;
4269
4270 /* Which flags to copy from suspend_flags */
4271 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004272} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004273
4274/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004275struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004276 /* Flags to enable now */
4277 uint8_t now_flags;
4278
4279 /* Flags to leave enabled in S3 */
4280 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004281} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004282
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004283/*****************************************************************************/
4284/* GPIO commands. Only available on EC if write protect has been disabled. */
4285
4286/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004287#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004288
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004289struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004290 char name[32];
4291 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004292} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004293
4294/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004295#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004296
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004297/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004298struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004299 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004300} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004301
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004302struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004303 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004304} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004305
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004306/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004307struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004308 uint8_t subcmd;
4309 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004310 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004311 char name[32];
4312 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004313 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004314 uint8_t index;
4315 } get_info;
4316 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004317} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004318
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004319struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004320 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004321 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004322 uint8_t val;
4323 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004324 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004325 uint8_t val;
4326 char name[32];
4327 uint32_t flags;
4328 } get_info;
4329 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004330} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004331
4332enum gpio_get_subcmd {
4333 EC_GPIO_GET_BY_NAME = 0,
4334 EC_GPIO_GET_COUNT = 1,
4335 EC_GPIO_GET_INFO = 2,
4336};
4337
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004338/*****************************************************************************/
4339/* I2C commands. Only available when flash write protect is unlocked. */
4340
Duncan Laurie93e24442014-01-06 12:30:52 -08004341/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004342 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4343 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4344 *
4345 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004346 */
4347
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004348/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004349#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004350
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004351struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004352 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004353 uint8_t read_size; /* Either 8 or 16. */
4354 uint8_t port;
4355 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004356} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004357
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004358struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004359 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004360} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004361
4362/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004363#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004364
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004365struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004366 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004367 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004368 uint8_t write_size; /* Either 8 or 16. */
4369 uint8_t port;
4370 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004371} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004372
4373/*****************************************************************************/
4374/* Charge state commands. Only available when flash write protect unlocked. */
4375
Duncan Laurie93e24442014-01-06 12:30:52 -08004376/* Force charge state machine to stop charging the battery or force it to
4377 * discharge the battery.
4378 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004379#define EC_CMD_CHARGE_CONTROL 0x0096
Scott Chao18141d8c2021-07-30 10:40:57 +08004380#define EC_VER_CHARGE_CONTROL 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004381
Duncan Laurie93e24442014-01-06 12:30:52 -08004382enum ec_charge_control_mode {
4383 CHARGE_CONTROL_NORMAL = 0,
4384 CHARGE_CONTROL_IDLE,
4385 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004386 /* Add no more entry below. */
4387 CHARGE_CONTROL_COUNT,
4388};
4389
Caveh Jalali024ffe32023-01-30 14:35:19 -08004390#define EC_CHARGE_MODE_TEXT \
4391 { \
4392 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4393 [CHARGE_CONTROL_IDLE] = "IDLE", \
4394 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
Scott Chao18141d8c2021-07-30 10:40:57 +08004395 }
4396
4397enum ec_charge_control_cmd {
4398 EC_CHARGE_CONTROL_CMD_SET = 0,
4399 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004400};
4401
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004402struct ec_params_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004403 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004404
4405 /* Below are the fields added in V2. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004406 uint8_t cmd; /* enum ec_charge_control_cmd. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004407 uint8_t reserved;
4408 /*
4409 * Lower and upper thresholds for battery sustainer. This struct isn't
4410 * named to avoid tainting foreign projects' name spaces.
4411 *
4412 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4413 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4414 * lower=-1, upper=-1.
4415 */
4416 struct {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004417 int8_t lower; /* Display SoC in percentage. */
4418 int8_t upper; /* Display SoC in percentage. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004419 } sustain_soc;
4420} __ec_align4;
4421
4422/* Added in v2 */
4423struct ec_response_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004424 uint32_t mode; /* enum charge_control_mode */
4425 struct { /* Battery sustainer thresholds */
Scott Chao18141d8c2021-07-30 10:40:57 +08004426 int8_t lower;
4427 int8_t upper;
4428 } sustain_soc;
4429 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004430} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004431
4432/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004433
4434/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004435#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004436
4437/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004438 * Read data from the saved snapshot. If the subcmd parameter is
4439 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4440 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4441 * end of the previous snapshot.
4442 *
4443 * The params are only looked at in version >= 1 of this command. Prior
4444 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004445 *
4446 * Response is null-terminated string. Empty string, if there is no more
4447 * remaining output.
4448 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004449#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004450
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004451enum ec_console_read_subcmd {
4452 CONSOLE_READ_NEXT = 0,
4453 CONSOLE_READ_RECENT,
4454};
Duncan Laurieeb316852015-12-01 18:51:18 -08004455
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004456struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004457 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004458} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004459
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004460/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004461
4462/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004463 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004464 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004465 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4466 * EC_RES_SUCCESS if the command was successful.
4467 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004468 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004469#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004470
Caveh Jalali024ffe32023-01-30 14:35:19 -08004471#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004472
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004473struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004474 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004475} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004476
Duncan Laurie433432b2013-06-03 10:38:22 -07004477/*****************************************************************************/
4478/* USB port mux control. */
4479
4480/*
4481 * Switch USB mux or return to automatic switching.
4482 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004483#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004484
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004485struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004486 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004487} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004488
4489/*****************************************************************************/
4490/* LDOs / FETs control. */
4491
4492enum ec_ldo_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004493 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4494 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
Duncan Laurie433432b2013-06-03 10:38:22 -07004495};
4496
4497/*
4498 * Switch on/off a LDO.
4499 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004500#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004502struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004503 uint8_t index;
4504 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004505} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004506
4507/*
4508 * Get LDO state.
4509 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004510#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004511
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004512struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004513 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004514} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004516struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004517 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004518} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004519
4520/*****************************************************************************/
4521/* Power info. */
4522
4523/*
4524 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004525 *
4526 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004527 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004528#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004529
Jett Rinkba2edaf2020-01-14 11:49:06 -07004530/*
4531 * v1 of EC_CMD_POWER_INFO
4532 */
4533enum system_power_source {
4534 /*
4535 * Haven't established which power source is used yet,
4536 * or no presence signals are available
4537 */
4538 POWER_SOURCE_UNKNOWN = 0,
4539 /* System is running on battery alone */
4540 POWER_SOURCE_BATTERY = 1,
4541 /* System is running on A/C alone */
4542 POWER_SOURCE_AC = 2,
4543 /* System is running on A/C and battery */
4544 POWER_SOURCE_AC_BATTERY = 3,
4545};
4546
4547struct ec_response_power_info_v1 {
4548 /* enum system_power_source */
4549 uint8_t system_power_source;
4550 /* Battery state-of-charge, 0-100, 0 if not present */
4551 uint8_t battery_soc;
4552 /* AC Adapter 100% rating, Watts */
4553 uint8_t ac_adapter_100pct;
4554 /* AC Adapter 10ms rating, Watts */
4555 uint8_t ac_adapter_10ms;
4556 /* Battery 1C rating, derated */
4557 uint8_t battery_1cd;
4558 /* Rest of Platform average, Watts */
4559 uint8_t rop_avg;
4560 /* Rest of Platform peak, Watts */
4561 uint8_t rop_peak;
4562 /* Nominal charger efficiency, % */
4563 uint8_t nominal_charger_eff;
4564 /* Rest of Platform VR Average Efficiency, % */
4565 uint8_t rop_avg_eff;
4566 /* Rest of Platform VR Peak Efficiency, % */
4567 uint8_t rop_peak_eff;
4568 /* SoC VR Efficiency at Average level, % */
4569 uint8_t soc_avg_eff;
4570 /* SoC VR Efficiency at Peak level, % */
4571 uint8_t soc_peak_eff;
4572 /* Intel-specific items */
4573 struct {
4574 /* Battery's level of DBPT support: 0, 2 */
4575 uint8_t batt_dbpt_support_level;
4576 /*
4577 * Maximum peak power from battery (10ms), Watts
4578 * If DBPT is not supported, this is 0
4579 */
4580 uint8_t batt_dbpt_max_peak_power;
4581 /*
4582 * Sustained peak power from battery, Watts
4583 * If DBPT is not supported, this is 0
4584 */
4585 uint8_t batt_dbpt_sus_peak_power;
4586 } intel;
4587} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004588
4589/*****************************************************************************/
4590/* I2C passthru command */
4591
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004592#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004593
Duncan Laurie433432b2013-06-03 10:38:22 -07004594/* Read data; if not present, message is a write */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004595#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004596
4597/* Mask for address */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004598#define EC_I2C_ADDR_MASK 0x3ff
Duncan Laurie433432b2013-06-03 10:38:22 -07004599
Caveh Jalali024ffe32023-01-30 14:35:19 -08004600#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4601#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004602
4603/* Any error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004604#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
Duncan Laurie433432b2013-06-03 10:38:22 -07004605
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004606struct ec_params_i2c_passthru_msg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004607 uint16_t addr_flags; /* I2C peripheral address and flags */
4608 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004609} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004610
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004611struct ec_params_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004612 uint8_t port; /* I2C port number */
4613 uint8_t num_msgs; /* Number of messages */
Duncan Laurie433432b2013-06-03 10:38:22 -07004614 struct ec_params_i2c_passthru_msg msg[];
4615 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004616} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004617
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004618struct ec_response_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004619 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4620 uint8_t num_msgs; /* Number of messages processed */
4621 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004622} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004623
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004624/*****************************************************************************/
4625/* Power button hang detect */
4626
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004627#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004628
4629/* Reasons to start hang detection timer */
4630/* Power button pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004631#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004632
4633/* Lid closed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004634#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004635
Caveh Jalali024ffe32023-01-30 14:35:19 -08004636/* Lid opened */
4637#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004638
4639/* Start of AP S3->S0 transition (booting or resuming from suspend) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004640#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004641
4642/* Reasons to cancel hang detection */
4643
4644/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004645#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004646
4647/* Any host command from AP received */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004648#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004649
4650/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004651#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004652
4653/*
4654 * If this flag is set, all the other fields are ignored, and the hang detect
4655 * timer is started. This provides the AP a way to start the hang timer
4656 * without reconfiguring any of the other hang detect settings. Note that
4657 * you must previously have configured the timeouts.
4658 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004659#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004660
4661/*
4662 * If this flag is set, all the other fields are ignored (including
4663 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4664 * without reconfiguring any of the other hang detect settings.
4665 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004666#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004667
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004668struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004669 /* Flags; see EC_HANG_* */
4670 uint32_t flags;
4671
4672 /* Timeout in msec before generating host event, if enabled */
4673 uint16_t host_event_timeout_msec;
4674
4675 /* Timeout in msec before generating warm reboot, if enabled */
4676 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004677} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004678
4679/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004680/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004681
4682/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004683 * This is the single catch-all host command to exchange data regarding the
4684 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004685 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004686#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004687
4688/* Subcommands for this host command */
4689enum charge_state_command {
4690 CHARGE_STATE_CMD_GET_STATE,
4691 CHARGE_STATE_CMD_GET_PARAM,
4692 CHARGE_STATE_CMD_SET_PARAM,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004693 CHARGE_STATE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004694};
4695
4696/*
4697 * Known param numbers are defined here. Ranges are reserved for board-specific
4698 * params, which are handled by the particular implementations.
4699 */
4700enum charge_state_params {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004701 /* charger voltage limit */
4702 CS_PARAM_CHG_VOLTAGE,
4703
4704 /* charger current limit */
4705 CS_PARAM_CHG_CURRENT,
4706
4707 /* charger input current limit */
4708 CS_PARAM_CHG_INPUT_CURRENT,
4709
4710 /* charger-specific status */
4711 CS_PARAM_CHG_STATUS,
4712
4713 /* charger-specific options */
4714 CS_PARAM_CHG_OPTION,
4715
4716 /*
4717 * Check if power is limited due to low battery and / or a
4718 * weak external charger. READ ONLY.
4719 */
4720 CS_PARAM_LIMIT_POWER,
4721
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004722 /* How many so far? */
4723 CS_NUM_BASE_PARAMS,
4724
4725 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4726 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4727 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4728
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004729 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4730 CS_PARAM_DEBUG_MIN = 0x20000,
4731 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4732 CS_PARAM_DEBUG_MANUAL_MODE,
4733 CS_PARAM_DEBUG_SEEMS_DEAD,
4734 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4735 CS_PARAM_DEBUG_BATT_REMOVED,
4736 CS_PARAM_DEBUG_MANUAL_CURRENT,
4737 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4738 CS_PARAM_DEBUG_MAX = 0x2ffff,
4739
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004740 /* Other custom param ranges go here... */
4741};
4742
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004743struct ec_params_charge_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004744 uint8_t cmd; /* enum charge_state_command */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004745 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004746 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004747
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004748 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004749 uint32_t param; /* enum charge_state_param */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004750 } get_param;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004751
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004752 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004753 uint32_t param; /* param to set */
4754 uint32_t value; /* value to set */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004755 } set_param;
4756 } __ec_todo_packed;
Caveh Jalali024ffe32023-01-30 14:35:19 -08004757 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004758} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004759
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004760struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004761 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004762 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004763 int ac;
4764 int chg_voltage;
4765 int chg_current;
4766 int chg_input_current;
4767 int batt_state_of_charge;
4768 } get_state;
4769
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004770 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004771 uint32_t value;
4772 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004773
4774 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004775 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004776} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004777
Duncan Laurie433432b2013-06-03 10:38:22 -07004778/*
4779 * Set maximum battery charging current.
4780 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004781#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Tim Van Pattencab60602023-02-24 12:27:04 -07004782#define EC_VER_CHARGE_CURRENT_LIMIT 1
Duncan Laurie433432b2013-06-03 10:38:22 -07004783
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004784struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004785 uint32_t limit; /* in mA */
Caveh Jalali839ada12022-10-31 23:16:48 -07004786} __ec_align4;
Tim Van Pattencab60602023-02-24 12:27:04 -07004787
Caveh Jalali839ada12022-10-31 23:16:48 -07004788struct ec_params_current_limit_v1 {
4789 uint32_t limit; /* in mA */
Tim Van Pattencab60602023-02-24 12:27:04 -07004790 /*
4791 * Battery state of charge is the minimum charge percentage at which
4792 * the battery charge current limit will apply.
4793 * When not set, the limit will apply regardless of state of charge.
4794 */
4795 uint8_t battery_soc; /* battery state of charge, 0-100 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004796} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004797
4798/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004799 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004800 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004801#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004802
Duncan Laurieeb316852015-12-01 18:51:18 -08004803/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004804struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004805 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4806 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004807} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004808
Duncan Laurieeb316852015-12-01 18:51:18 -08004809#define EC_POWER_LIMIT_NONE 0xffff
4810
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004811/*
4812 * Set maximum voltage & current of a dedicated charge port
4813 */
4814#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004816struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004817 uint16_t current_lim; /* in mA */
4818 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004819} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004820
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08004821/*
4822 * Get and set charging splashscreen variables
4823 */
4824#define EC_CMD_CHARGESPLASH 0x00A5
4825
4826enum ec_chargesplash_cmd {
4827 /* Get the current state variables */
4828 EC_CHARGESPLASH_GET_STATE = 0,
4829
4830 /* Indicate initialization of the display loop */
4831 EC_CHARGESPLASH_DISPLAY_READY,
4832
4833 /* Manually put the EC into the requested state */
4834 EC_CHARGESPLASH_REQUEST,
4835
4836 /* Reset all state variables */
4837 EC_CHARGESPLASH_RESET,
4838
4839 /* Manually trigger a lockout */
4840 EC_CHARGESPLASH_LOCKOUT,
4841};
4842
4843struct __ec_align1 ec_params_chargesplash {
4844 /* enum ec_chargesplash_cmd */
4845 uint8_t cmd;
4846};
4847
4848struct __ec_align1 ec_response_chargesplash {
4849 uint8_t requested;
4850 uint8_t display_initialized;
4851 uint8_t locked_out;
4852};
4853
Duncan Laurieeb316852015-12-01 18:51:18 -08004854/*****************************************************************************/
4855/* Hibernate/Deep Sleep Commands */
4856
4857/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004858#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004859
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004860struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004861 /*
4862 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4863 * current settings without changing them.
4864 */
4865 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004866} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004867
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004868struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004869 /*
4870 * The current time in seconds in which the system has been in the G3
4871 * state. This value is reset if the EC transitions out of G3.
4872 */
4873 uint32_t time_g3;
4874
4875 /*
4876 * The current time remaining in seconds until the EC should hibernate.
4877 * This value is also reset if the EC transitions out of G3.
4878 */
4879 uint32_t time_remaining;
4880
4881 /*
4882 * The current time in seconds that the EC should wait in G3 before
4883 * hibernating.
4884 */
4885 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004886} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004887
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004888/* Inform the EC when entering a sleep state */
4889#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4890
4891enum host_sleep_event {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004892 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4893 HOST_SLEEP_EVENT_S3_RESUME = 2,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004894 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Caveh Jalali024ffe32023-01-30 14:35:19 -08004895 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004896 /* S3 suspend with additional enabled wake sources */
4897 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004898};
4899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004900struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004901 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004902} __ec_align1;
4903
4904/*
4905 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4906 * transition failures
4907 */
4908#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4909
4910/* Disable timeout detection for this sleep transition */
4911#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4912
4913struct ec_params_host_sleep_event_v1 {
4914 /* The type of sleep being entered or exited. */
4915 uint8_t sleep_event;
4916
4917 /* Padding */
4918 uint8_t reserved;
4919 union {
4920 /* Parameters that apply for suspend messages. */
4921 struct {
4922 /*
4923 * The timeout in milliseconds between when this message
4924 * is received and when the EC will declare sleep
4925 * transition failure if the sleep signal is not
4926 * asserted.
4927 */
4928 uint16_t sleep_timeout_ms;
4929 } suspend_params;
4930
4931 /* No parameters for non-suspend messages. */
4932 };
4933} __ec_align2;
4934
4935/* A timeout occurred when this bit is set */
4936#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4937
4938/*
4939 * The mask defining which bits correspond to the number of sleep transitions,
4940 * as well as the maximum number of suspend line transitions that will be
4941 * reported back to the host.
4942 */
4943#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4944
4945struct ec_response_host_sleep_event_v1 {
4946 union {
4947 /* Response fields that apply for resume messages. */
4948 struct {
4949 /*
4950 * The number of sleep power signal transitions that
4951 * occurred since the suspend message. The high bit
4952 * indicates a timeout occurred.
4953 */
4954 uint32_t sleep_transitions;
4955 } resume_response;
4956
4957 /* No response fields for non-resume messages. */
4958 };
4959} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004960
4961/*****************************************************************************/
4962/* Device events */
4963#define EC_CMD_DEVICE_EVENT 0x00AA
4964
4965enum ec_device_event {
4966 EC_DEVICE_EVENT_TRACKPAD,
4967 EC_DEVICE_EVENT_DSP,
4968 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004969 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004970};
4971
4972enum ec_device_event_param {
4973 /* Get and clear pending device events */
4974 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4975 /* Get device event mask */
4976 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4977 /* Set device event mask */
4978 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4979};
4980
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004981#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004982
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004983struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004984 uint32_t event_mask;
4985 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004986} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004987
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004988struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004989 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004990} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004991
Duncan Laurie433432b2013-06-03 10:38:22 -07004992/*****************************************************************************/
Caveh Jalali839ada12022-10-31 23:16:48 -07004993/* Get s0ix counter */
4994#define EC_CMD_GET_S0IX_COUNTER 0x00AB
4995
4996/* Flag use to reset the counter */
4997#define EC_S0IX_COUNTER_RESET 0x1
4998
4999struct ec_params_s0ix_cnt {
5000 /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */
5001 uint32_t flags;
5002} __ec_align4;
5003
5004struct ec_response_s0ix_cnt {
5005 /* Value of the s0ix_counter */
5006 uint32_t s0ix_counter;
5007} __ec_align4;
5008
5009/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07005010/* Smart battery pass-through */
5011
Caveh Jalali839ada12022-10-31 23:16:48 -07005012/* Get / Set 16-bit smart battery registers - OBSOLETE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005013#define EC_CMD_SB_READ_WORD 0x00B0
5014#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07005015
5016/* Get / Set string smart battery parameters
Caveh Jalali839ada12022-10-31 23:16:48 -07005017 * formatted as SMBUS "block". - OBSOLETE
Duncan Laurie433432b2013-06-03 10:38:22 -07005018 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005019#define EC_CMD_SB_READ_BLOCK 0x00B2
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005020#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07005021
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005022/*****************************************************************************/
5023/* Battery vendor parameters
5024 *
5025 * Get or set vendor-specific parameters in the battery. Implementations may
5026 * differ between boards or batteries. On a set operation, the response
5027 * contains the actual value set, which may be rounded or clipped from the
5028 * requested value.
5029 */
5030
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005031#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005032
5033enum ec_battery_vendor_param_mode {
5034 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5035 BATTERY_VENDOR_PARAM_MODE_SET,
5036};
5037
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005038struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005039 uint32_t param;
5040 uint32_t value;
5041 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005042} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005043
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005044struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005045 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005046} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005047
5048/*****************************************************************************/
5049/*
Caveh Jalali839ada12022-10-31 23:16:48 -07005050 * Smart Battery Firmware Update Command - OBSOLETE
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005051 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005052#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005053
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005054/*
5055 * Entering Verified Boot Mode Command
5056 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5057 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07005058 *
5059 * EC no longer needs to know what mode vboot has entered,
5060 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005061 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005062#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005063
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005064struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005065 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005066} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005067
Caveh Jalali024ffe32023-01-30 14:35:19 -08005068#define VBOOT_MODE_NORMAL 0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005069#define VBOOT_MODE_DEVELOPER 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08005070#define VBOOT_MODE_RECOVERY 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005071
Duncan Laurie433432b2013-06-03 10:38:22 -07005072/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07005073/*
5074 * I2C passthru protection command: Protects I2C tunnels against access on
5075 * certain addresses (board-specific).
5076 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005077#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07005078
5079enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005080 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5081 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5082 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005083};
5084
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005085struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005086 uint8_t subcmd;
Caveh Jalali024ffe32023-01-30 14:35:19 -08005087 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005088} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005089
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005090struct ec_response_i2c_passthru_protect {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005091 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005092} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005093
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005094/*****************************************************************************/
5095/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005096 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005097 *
5098 * These commands are for sending and receiving message via HDMI CEC
5099 */
5100
5101#define MAX_CEC_MSG_LEN 16
5102
5103/* CEC message from the AP to be written on the CEC bus */
5104#define EC_CMD_CEC_WRITE_MSG 0x00B8
5105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005106/**
5107 * struct ec_params_cec_write - Message to write to the CEC bus
5108 * @msg: message content to write to the CEC bus
5109 */
5110struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005111 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005112} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005113
5114/* Set various CEC parameters */
5115#define EC_CMD_CEC_SET 0x00BA
5116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005117/**
5118 * struct ec_params_cec_set - CEC parameters set
5119 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5120 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5121 * or 1 to enable CEC functionality, in case cmd is
5122 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5123 * address between 0 and 15 or 0xff to unregister
5124 */
5125struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005126 uint8_t cmd; /* enum cec_command */
5127 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005128} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005129
5130/* Read various CEC parameters */
5131#define EC_CMD_CEC_GET 0x00BB
5132
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005133/**
5134 * struct ec_params_cec_get - CEC parameters get
5135 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5136 */
5137struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005138 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005139} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005140
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005141/**
5142 * struct ec_response_cec_get - CEC parameters get response
5143 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5144 * disabled or 1 if CEC functionality is enabled,
5145 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5146 * configured logical address between 0 and 15 or 0xff if unregistered
5147 */
5148struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005149 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005150} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005151
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005152/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005153enum cec_command {
5154 /* CEC reading, writing and events enable */
5155 CEC_CMD_ENABLE,
5156 /* CEC logical address */
5157 CEC_CMD_LOGICAL_ADDRESS,
5158};
5159
5160/* Events from CEC to AP */
5161enum mkbp_cec_event {
5162 /* Outgoing message was acknowledged by a follower */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005163 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005164 /* Outgoing message was not acknowledged */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005165 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005166};
5167
Gwendal Grignou880b4582016-06-20 08:49:25 -07005168/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005169
Jett Rinkba2edaf2020-01-14 11:49:06 -07005170/* Commands for audio codec. */
5171#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005172
Jett Rinkba2edaf2020-01-14 11:49:06 -07005173enum ec_codec_subcmd {
5174 EC_CODEC_GET_CAPABILITIES = 0x0,
5175 EC_CODEC_GET_SHM_ADDR = 0x1,
5176 EC_CODEC_SET_SHM_ADDR = 0x2,
5177 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005178};
5179
Jett Rinkba2edaf2020-01-14 11:49:06 -07005180enum ec_codec_cap {
5181 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5182 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5183 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005184};
5185
Jett Rinkba2edaf2020-01-14 11:49:06 -07005186enum ec_codec_shm_id {
5187 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5188 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5189 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005190};
5191
Jett Rinkba2edaf2020-01-14 11:49:06 -07005192enum ec_codec_shm_type {
5193 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5194 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005195};
5196
Jett Rinkba2edaf2020-01-14 11:49:06 -07005197struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5198 uint8_t shm_id;
5199 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005200};
5201
Jett Rinkba2edaf2020-01-14 11:49:06 -07005202struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5203 uint64_t phys_addr;
5204 uint32_t len;
5205 uint8_t shm_id;
5206 uint8_t reserved[3];
5207};
5208
5209struct __ec_align4 ec_param_ec_codec {
5210 uint8_t cmd; /* enum ec_codec_subcmd */
5211 uint8_t reserved[3];
5212
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005213 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005214 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5215 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005216 };
5217};
5218
Jett Rinkba2edaf2020-01-14 11:49:06 -07005219struct __ec_align4 ec_response_ec_codec_get_capabilities {
5220 uint32_t capabilities;
5221};
5222
5223struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5224 uint64_t phys_addr;
5225 uint32_t len;
5226 uint8_t type;
5227 uint8_t reserved[3];
5228};
5229
5230/*****************************************************************************/
5231
5232/* Commands for DMIC on audio codec. */
5233#define EC_CMD_EC_CODEC_DMIC 0x00BD
5234
5235enum ec_codec_dmic_subcmd {
5236 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5237 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5238 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5239 EC_CODEC_DMIC_SUBCMD_COUNT,
5240};
5241
5242enum ec_codec_dmic_channel {
5243 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5244 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5245 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5246 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5247 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5248 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5249 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5250 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5251 EC_CODEC_DMIC_CHANNEL_COUNT,
5252};
5253
5254struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5255 uint8_t channel; /* enum ec_codec_dmic_channel */
5256 uint8_t gain;
5257 uint8_t reserved[2];
5258};
5259
5260struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5261 uint8_t channel; /* enum ec_codec_dmic_channel */
5262 uint8_t reserved[3];
5263};
5264
5265struct __ec_align4 ec_param_ec_codec_dmic {
5266 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5267 uint8_t reserved[3];
5268
5269 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005270 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5271 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005272 };
5273};
5274
5275struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5276 uint8_t max_gain;
5277};
5278
5279struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5280 uint8_t gain;
5281};
5282
5283/*****************************************************************************/
5284
5285/* Commands for I2S RX on audio codec. */
5286
5287#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5288
5289enum ec_codec_i2s_rx_subcmd {
5290 EC_CODEC_I2S_RX_ENABLE = 0x0,
5291 EC_CODEC_I2S_RX_DISABLE = 0x1,
5292 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5293 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5294 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005295 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005296 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5297};
5298
5299enum ec_codec_i2s_rx_sample_depth {
5300 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5301 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5302 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5303};
5304
5305enum ec_codec_i2s_rx_daifmt {
5306 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5307 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5308 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5309 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5310};
5311
5312struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5313 uint8_t depth;
5314 uint8_t reserved[3];
5315};
5316
5317struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5318 uint8_t left;
5319 uint8_t right;
5320 uint8_t reserved[2];
5321};
5322
5323struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5324 uint8_t daifmt;
5325 uint8_t reserved[3];
5326};
5327
5328struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5329 uint32_t bclk;
5330};
5331
5332struct __ec_align4 ec_param_ec_codec_i2s_rx {
5333 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5334 uint8_t reserved[3];
5335
5336 union {
5337 struct ec_param_ec_codec_i2s_rx_set_sample_depth
Caveh Jalali024ffe32023-01-30 14:35:19 -08005338 set_sample_depth_param;
5339 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5340 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005341 };
5342};
5343
5344/*****************************************************************************/
5345/* Commands for WoV on audio codec. */
5346
5347#define EC_CMD_EC_CODEC_WOV 0x00BF
5348
5349enum ec_codec_wov_subcmd {
5350 EC_CODEC_WOV_SET_LANG = 0x0,
5351 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5352 EC_CODEC_WOV_GET_LANG = 0x2,
5353 EC_CODEC_WOV_ENABLE = 0x3,
5354 EC_CODEC_WOV_DISABLE = 0x4,
5355 EC_CODEC_WOV_READ_AUDIO = 0x5,
5356 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5357 EC_CODEC_WOV_SUBCMD_COUNT,
5358};
5359
5360/*
5361 * @hash is SHA256 of the whole language model.
5362 * @total_len indicates the length of whole language model.
5363 * @offset is the cursor from the beginning of the model.
5364 * @buf is the packet buffer.
5365 * @len denotes how many bytes in the buf.
5366 */
5367struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5368 uint8_t hash[32];
5369 uint32_t total_len;
5370 uint32_t offset;
5371 uint8_t buf[128];
5372 uint32_t len;
5373};
5374
5375struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5376 uint8_t hash[32];
5377 uint32_t total_len;
5378};
5379
5380struct __ec_align4 ec_param_ec_codec_wov {
5381 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5382 uint8_t reserved[3];
5383
5384 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005385 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5386 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005387 };
5388};
5389
5390struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5391 uint8_t hash[32];
5392};
5393
5394struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5395 uint8_t buf[128];
5396 uint32_t len;
5397};
5398
5399struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5400 uint32_t offset;
5401 uint32_t len;
5402};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005403
5404/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005405/* Commands for PoE PSE controller */
5406
5407#define EC_CMD_PSE 0x00C0
5408
5409enum ec_pse_subcmd {
5410 EC_PSE_STATUS = 0x0,
5411 EC_PSE_ENABLE = 0x1,
5412 EC_PSE_DISABLE = 0x2,
5413 EC_PSE_SUBCMD_COUNT,
5414};
5415
5416struct __ec_align1 ec_params_pse {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005417 uint8_t cmd; /* enum ec_pse_subcmd */
5418 uint8_t port; /* PSE port */
Yidi Lin42f79592020-09-21 18:04:10 +08005419};
5420
5421enum ec_pse_status {
5422 EC_PSE_STATUS_DISABLED = 0x0,
5423 EC_PSE_STATUS_ENABLED = 0x1,
5424 EC_PSE_STATUS_POWERED = 0x2,
5425};
5426
5427struct __ec_align1 ec_response_pse_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005428 uint8_t status; /* enum ec_pse_status */
Yidi Lin42f79592020-09-21 18:04:10 +08005429};
5430
5431/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005432/* System commands */
5433
5434/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005435 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5436 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005437 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005438#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005439
5440/* Command */
5441enum ec_reboot_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005442 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5443 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5444 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005445 /* (command 3 was jump to RW-B) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005446 EC_REBOOT_COLD = 4, /* Cold-reboot */
5447 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5448 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005449 /*
5450 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5451 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5452 */
5453 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005454 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5455 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005456};
5457
5458/* Flags for ec_params_reboot_ec.reboot_flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005459#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5460#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5461#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5462#define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005463
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005464struct ec_params_reboot_ec {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005465 uint8_t cmd; /* enum ec_reboot_cmd */
5466 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005467} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005468
Duncan Laurie433432b2013-06-03 10:38:22 -07005469/*
5470 * Get information on last EC panic.
5471 *
5472 * Returns variable-length platform-dependent panic information. See panic.h
5473 * for details.
5474 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005475#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005476
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005477/*****************************************************************************/
5478/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005479 * Special commands
5480 *
5481 * These do not follow the normal rules for commands. See each command for
5482 * details.
5483 */
5484
5485/*
5486 * Reboot NOW
5487 *
5488 * This command will work even when the EC LPC interface is busy, because the
5489 * reboot command is processed at interrupt level. Note that when the EC
5490 * reboots, the host will reboot too, so there is no response to this command.
5491 *
5492 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5493 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005494#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005495
5496/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005497 * Resend last response (not supported on LPC).
5498 *
5499 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5500 * there was no previous command, or the previous command's response was too
5501 * big to save.
5502 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005503#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005504
5505/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005506 * This header byte on a command indicate version 0. Any header byte less
5507 * than this means that we are talking to an old EC which doesn't support
5508 * versioning. In that case, we assume version 0.
5509 *
5510 * Header bytes greater than this indicate a later version. For example,
5511 * EC_CMD_VERSION0 + 1 means we are using version 1.
5512 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005513 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005514 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005515#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005516
Caveh Jalali839ada12022-10-31 23:16:48 -07005517/*
5518 * Memory Dump Commands
5519 *
5520 * Since the HOSTCMD response size is limited, depending on the
5521 * protocol, retrieving a memory dump is split into 3 commands.
5522 *
5523 * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries,
5524 * and the total dump size.
5525 * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given
5526 * memory dump entry index.
5527 * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given
5528 * address. The address and size must be within the bounds of the given
5529 * memory dump entry index. Each response is limited to the max response size
5530 * of the host protocol, so this may need to be called repeatedly to retrieve
5531 * the entire memory dump entry.
5532 *
5533 * Memory entries may overlap and may be out of order.
5534 * The host should check for overlaps to optimize transfer rate.
5535 */
5536#define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD
5537struct ec_response_memory_dump_get_metadata {
5538 uint16_t memory_dump_entry_count;
5539 uint32_t memory_dump_total_size;
5540} __ec_align4;
5541
5542#define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE
5543struct ec_params_memory_dump_get_entry_info {
5544 uint16_t memory_dump_entry_index;
5545} __ec_align4;
5546
5547struct ec_response_memory_dump_get_entry_info {
5548 uint32_t address;
5549 uint32_t size;
5550} __ec_align4;
5551
5552#define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF
5553
5554struct ec_params_memory_dump_read_memory {
5555 uint16_t memory_dump_entry_index;
5556 uint32_t address;
5557 uint32_t size;
5558} __ec_align4;
5559
5560/*
5561 * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into
5562 * host_cmd_handler_args.response and host_cmd_handler_args.response_size.
5563 */
5564
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005565/*****************************************************************************/
5566/*
5567 * PD commands
5568 *
5569 * These commands are for PD MCU communication.
5570 */
5571
5572/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005573#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005574#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005575
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005576enum pd_charge_state {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005577 /* Don't change charge state */
5578 PD_CHARGE_NO_CHANGE = 0,
5579
5580 /* No charging allowed */
5581 PD_CHARGE_NONE,
5582
5583 /* 5V charging only */
5584 PD_CHARGE_5V,
5585
5586 /* Charge at max voltage */
5587 PD_CHARGE_MAX,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005588};
5589
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005590/* Status of EC being sent to PD */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005591#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005592
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005593struct ec_params_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005594 /* EC status */
5595 uint8_t status;
5596
5597 /* battery state of charge */
5598 int8_t batt_soc;
5599
5600 /* charging state (from enum pd_charge_state) */
5601 uint8_t charge_state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005602} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005603
5604/* Status of PD being sent back to EC */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005605#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5606#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005607#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005608#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5609#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5610#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5611#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
5612#define PD_STATUS_EC_INT_ACTIVE \
5613 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005614struct ec_response_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005615 /* input current limit */
5616 uint32_t curr_lim_ma;
5617
5618 /* PD MCU status */
5619 uint16_t status;
5620
5621 /* active charging port */
5622 int8_t active_charge_port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005623} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005624
5625/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005626#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005627
5628/* PD MCU host event status bits */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005629#define PD_EVENT_UPDATE_DEVICE BIT(0)
5630#define PD_EVENT_POWER_CHANGE BIT(1)
5631#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5632#define PD_EVENT_DATA_SWAP BIT(3)
5633#define PD_EVENT_TYPEC BIT(4)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005634
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005635struct ec_response_host_event_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005636 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005637} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005638
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005639/*
5640 * Set USB type-C port role and muxes
5641 *
5642 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5643 *
5644 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5645 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005646#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005647
5648enum usb_pd_control_role {
5649 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5650 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5651 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5652 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5653 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005654 USB_PD_CTRL_ROLE_FREEZE = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005655 USB_PD_CTRL_ROLE_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005656};
5657
5658enum usb_pd_control_mux {
5659 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5660 USB_PD_CTRL_MUX_NONE = 1,
5661 USB_PD_CTRL_MUX_USB = 2,
5662 USB_PD_CTRL_MUX_DP = 3,
5663 USB_PD_CTRL_MUX_DOCK = 4,
5664 USB_PD_CTRL_MUX_AUTO = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005665 USB_PD_CTRL_MUX_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005666};
5667
Duncan Laurieeb316852015-12-01 18:51:18 -08005668enum usb_pd_control_swap {
5669 USB_PD_CTRL_SWAP_NONE = 0,
5670 USB_PD_CTRL_SWAP_DATA = 1,
5671 USB_PD_CTRL_SWAP_POWER = 2,
5672 USB_PD_CTRL_SWAP_VCONN = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005673 USB_PD_CTRL_SWAP_COUNT,
Duncan Laurieeb316852015-12-01 18:51:18 -08005674};
5675
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005676struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005677 uint8_t port;
5678 uint8_t role;
5679 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005680 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005681} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005682
Caveh Jalali024ffe32023-01-30 14:35:19 -08005683#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5684#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005685#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005686
Caveh Jalali024ffe32023-01-30 14:35:19 -08005687#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5688#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5689#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5690#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5691#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5692#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005693/* Partner unconstrained power */
5694#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
Duncan Laurieeb316852015-12-01 18:51:18 -08005695
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005696struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005697 uint8_t enabled;
5698 uint8_t role;
5699 uint8_t polarity;
5700 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005701} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005702
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005703struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005704 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005705 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005706 uint8_t polarity;
5707 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005708} __ec_align1;
5709
Jett Rinkba2edaf2020-01-14 11:49:06 -07005710/* Possible port partner connections based on CC line states */
5711enum pd_cc_states {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005712 PD_CC_NONE = 0, /* No port partner attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005713
5714 /* From DFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005715 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
5716 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5717 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5718 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005719
5720 /* From UFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005721 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
5722 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005723};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005724
Jett Rinkba2edaf2020-01-14 11:49:06 -07005725/* Active/Passive Cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005726#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005727/* Optical/Non-optical cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005728#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005729/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005730#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005731/* Active Link Uni-Direction */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005732#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Caveh Jalali839ada12022-10-31 23:16:48 -07005733/* Retimer/Redriver cable */
5734#define USB_PD_CTRL_RETIMER_CABLE BIT(4)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005735
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005736struct ec_response_usb_pd_control_v2 {
5737 uint8_t enabled;
5738 uint8_t role;
5739 uint8_t polarity;
5740 char state[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08005741 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5742 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
5743 uint8_t reserved; /* Reserved for future use */
5744 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5745 uint8_t cable_speed; /* TBT_SS_* cable speed */
5746 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005747} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005748
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005749#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005750
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005751/* Maximum number of PD ports on a device, num_ports will be <= this */
5752#define EC_USB_PD_MAX_PORTS 8
5753
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005754struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005755 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005756} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005757
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005758#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005759
5760#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005761struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005762 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005763} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005764
5765enum usb_chg_type {
5766 USB_CHG_TYPE_NONE,
5767 USB_CHG_TYPE_PD,
5768 USB_CHG_TYPE_C,
5769 USB_CHG_TYPE_PROPRIETARY,
5770 USB_CHG_TYPE_BC12_DCP,
5771 USB_CHG_TYPE_BC12_CDP,
5772 USB_CHG_TYPE_BC12_SDP,
5773 USB_CHG_TYPE_OTHER,
5774 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005775 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005776 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005777};
5778enum usb_power_roles {
5779 USB_PD_PORT_POWER_DISCONNECTED,
5780 USB_PD_PORT_POWER_SOURCE,
5781 USB_PD_PORT_POWER_SINK,
5782 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5783};
5784
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005785struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005786 uint16_t voltage_max;
5787 uint16_t voltage_now;
5788 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005789 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005790} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005791
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005792struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005793 uint8_t role;
5794 uint8_t type;
5795 uint8_t dualrole;
5796 uint8_t reserved1;
5797 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005798 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005799} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005800
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005801/*
5802 * This command will return the number of USB PD charge port + the number
5803 * of dedicated port present.
5804 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5805 */
5806#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005807struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005808 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005809} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005810
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08005811/*
5812 * This command enable/disable dynamic PDO selection.
5813 */
5814#define EC_CMD_USB_PD_DPS_CONTROL 0x0106
5815
5816struct ec_params_usb_pd_dps_control {
5817 uint8_t enable;
5818} __ec_align1;
5819
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005820/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005821#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005822
5823enum usb_pd_fw_update_cmds {
5824 USB_PD_FW_REBOOT,
5825 USB_PD_FW_FLASH_ERASE,
5826 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005827 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005828};
5829
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005830struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005831 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005832 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005833 uint8_t port;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005834
5835 /* Size to write in bytes */
5836 uint32_t size;
5837
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005838 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005839} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005840
5841/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005842#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005843/* RW hash is first 20 bytes of SHA-256 of RW section */
5844#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005845struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005846 uint16_t dev_id;
5847 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005848
5849 /*
5850 * Reserved for alignment of current_image
5851 * TODO(rspangler) but it's not aligned!
5852 * Should have been reserved[2].
5853 */
5854 uint8_t reserved;
5855
5856 /* One of ec_image */
5857 uint32_t current_image;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005858} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005859
5860/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005861#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005862
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005863struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005864 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005865} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005866
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005867/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005868#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005869struct ec_params_usb_pd_discovery_entry {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005870 uint16_t vid; /* USB-IF VID */
5871 uint16_t pid; /* USB-IF PID */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005872 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005873} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005874
5875/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005876#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005877
5878/* Negative port parameters have special meaning */
5879enum usb_pd_override_ports {
5880 OVERRIDE_DONT_CHARGE = -2,
5881 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005882 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005883};
5884
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005885struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005886 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005887} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005888
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005889/*
5890 * Read (and delete) one entry of PD event log.
5891 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5892 * future non-PD logs that use the same internal EC event_log.
5893 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005894#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005895
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005896struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005897 uint32_t timestamp; /* relative timestamp in milliseconds */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005898 uint8_t type; /* event type : see PD_EVENT_xx below */
5899 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5900 uint16_t data; /* type-defined data payload */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005901 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005902} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005903
5904/* The timestamp is the microsecond counter shifted to get about a ms. */
5905#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5906
Caveh Jalali024ffe32023-01-30 14:35:19 -08005907#define PD_LOG_SIZE_MASK 0x1f
5908#define PD_LOG_PORT_MASK 0xe0
5909#define PD_LOG_PORT_SHIFT 5
5910#define PD_LOG_PORT_SIZE(port, size) \
5911 (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK))
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005912#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08005913#define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005914
5915/* PD event log : entry types */
5916/* PD MCU events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005917#define PD_EVENT_MCU_BASE 0x00
5918#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
5919#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005920/* Reserved for custom board event */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005921#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005922/* PD generic accessory events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005923#define PD_EVENT_ACC_BASE 0x20
5924#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
5925#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005926/* PD power supply events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005927#define PD_EVENT_PS_BASE 0x40
5928#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005929/* PD video dongles events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005930#define PD_EVENT_VIDEO_BASE 0x60
5931#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
5932#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005933/* Returned in the "type" field, when there is no entry available */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005934#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005935
5936/*
5937 * PD_EVENT_MCU_CHARGE event definition :
5938 * the payload is "struct usb_chg_measures"
5939 * the data field contains the port state flags as defined below :
5940 */
5941/* Port partner is a dual role device */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005942#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005943/* Port is the pending override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005944#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005945/* Port is the override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005946#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005947/* Charger type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005948#define CHARGE_FLAGS_TYPE_SHIFT 3
5949#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005950/* Power delivery role */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005951#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005952
5953/*
5954 * PD_EVENT_PS_FAULT data field flags definition :
5955 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005956#define PS_FAULT_OCP 1
5957#define PS_FAULT_FAST_OCP 2
5958#define PS_FAULT_OVP 3
5959#define PS_FAULT_DISCH 4
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005960
5961/*
5962 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5963 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005964struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005965 uint8_t major;
5966 uint8_t minor;
5967 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005968} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005969
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005970struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005971 uint8_t family[2];
5972 uint8_t chipid[2];
5973 struct mcdp_version irom;
5974 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005975} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005976
5977/* struct mcdp_info field decoding */
5978#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5979#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5980
5981/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005982#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005983struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005984 uint16_t svid_idx; /* SVID index to get */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005985 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005986} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005987
Caveh Jalali839ada12022-10-31 23:16:48 -07005988#define VDO_MAX_SIZE 7
5989/* Max number of VDM data objects without VDM header */
5990#define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1)
5991
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005992struct ec_params_usb_pd_get_mode_response {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005993 uint16_t svid; /* SVID */
5994 uint16_t opos; /* Object Position */
Caveh Jalali839ada12022-10-31 23:16:48 -07005995 uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005996} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005997
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005998#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005999
6000enum pd_mode_cmd {
6001 PD_EXIT_MODE = 0,
6002 PD_ENTER_MODE = 1,
6003 /* Not a command. Do NOT remove. */
6004 PD_MODE_CMD_COUNT,
6005};
6006
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006007struct ec_params_usb_pd_set_mode_request {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006008 uint32_t cmd; /* enum pd_mode_cmd */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006009 uint16_t svid; /* SVID to set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006010 uint8_t opos; /* Object Position */
6011 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006012} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006013
6014/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006015#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006016
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006017struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006018 uint8_t type; /* event type : see PD_EVENT_xx above */
6019 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006020} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006021
Gwendal Grignou880b4582016-06-20 08:49:25 -07006022/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006023#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07006024
6025enum ec_pd_control_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006026 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6027 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6028 PD_RESET, /* Force reset the PD chip */
6029 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6030 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006031};
6032
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006033struct ec_params_pd_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006034 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006035 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006036} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07006037
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006038/* Get info about USB-C SS muxes */
6039#define EC_CMD_USB_PD_MUX_INFO 0x011A
6040
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006041struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006042 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006043} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006044
6045/* Flags representing mux state */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006046#define USB_PD_MUX_NONE 0 /* Open switch */
6047#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6048#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6049#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6050#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6051#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6052#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6053#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6054#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006055#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006056#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006057
6058/* USB-C Dock connected */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006059#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006060
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006061struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006062 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006063} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006064
Caveh Jalali024ffe32023-01-30 14:35:19 -08006065#define EC_CMD_PD_CHIP_INFO 0x011B
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006066
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006067struct ec_params_pd_chip_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006068 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006069 /*
6070 * Fetch the live chip info or hard-coded + cached chip info
6071 * 0: hardcoded value for VID/PID, cached value for FW version
6072 * 1: live chip value for VID/PID/FW Version
6073 */
6074 uint8_t live;
6075} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006076
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006077struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006078 uint16_t vendor_id;
6079 uint16_t product_id;
6080 uint16_t device_id;
6081 union {
6082 uint8_t fw_version_string[8];
6083 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006084 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006085} __ec_align2;
6086
6087struct ec_response_pd_chip_info_v1 {
6088 uint16_t vendor_id;
6089 uint16_t product_id;
6090 uint16_t device_id;
6091 union {
6092 uint8_t fw_version_string[8];
6093 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006094 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006095 union {
6096 uint8_t min_req_fw_version_string[8];
6097 uint64_t min_req_fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006098 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006099} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006100
6101/* Run RW signature verification and get status */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006102#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006103
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006104struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006105 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006106} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006107
6108/* For controlling RWSIG task */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006109#define EC_CMD_RWSIG_ACTION 0x011D
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006110
6111enum rwsig_action {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006112 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6113 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006114};
6115
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006116struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006117 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006118} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006119
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006120/* Run verification on a slot */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006121#define EC_CMD_EFS_VERIFY 0x011E
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006123struct ec_params_efs_verify {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006124 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006125} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006126
6127/*
6128 * Retrieve info from Cros Board Info store. Response is based on the data
6129 * type. Integers return a uint32. Strings return a string, using the response
6130 * size to determine how big it is.
6131 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006132#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006133/*
6134 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6135 * hardware write-protect enabled.
6136 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006137#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006138
Daisuke Nojirif984a052018-02-15 12:38:15 -08006139enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006140 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006141 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6142 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06006143 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006144 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6145 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6146 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6147 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08006148 /* Second Source Factory Cache */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006149 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6150 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006151 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006152 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006153};
6154
6155/*
6156 * Flags to control read operation
6157 *
6158 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6159 * write was successful without reboot.
6160 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006161#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006162
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006163struct ec_params_get_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006164 uint32_t tag; /* enum cbi_data_tag */
6165 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006166} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006167
6168/*
6169 * Flags to control write behavior.
6170 *
6171 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6172 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006173 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006174 * will be initialized to zero first.
6175 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006176#define CBI_SET_NO_SYNC BIT(0)
6177#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006178
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006179struct ec_params_set_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006180 uint32_t tag; /* enum cbi_data_tag */
6181 uint32_t flag; /* CBI_SET_* */
6182 uint32_t size; /* Data size */
6183 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006184} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006185
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006186/*
6187 * Information about resets of the AP by the EC and the EC's own uptime.
6188 */
6189#define EC_CMD_GET_UPTIME_INFO 0x0121
6190
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006191/* EC reset causes */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006192#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6193#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6194#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6195#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6196#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6197#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6198#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6199#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6200#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6201#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6202#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6203#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6204#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006205/* Some reset flags preserved from previous boot */
6206#define EC_RESET_FLAG_PRESERVED BIT(13)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006207#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6208#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6209#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6210#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006211/* AP experienced a watchdog reset */
6212#define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6213/* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6214#define EC_RESET_FLAG_STAY_IN_RO BIT(19)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006215#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6216#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6217#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006218
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006219/*
6220 * Reason codes used by the AP after a shutdown to figure out why it was reset
6221 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6222 * compatibility:
6223 * - New entries must be inserted prior to the _COUNT field
6224 * - If an existing entry is no longer in service, it must be replaced with a
6225 * RESERVED entry instead.
6226 * - The semantic meaning of an entry should not change.
6227 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6228 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006229enum chipset_shutdown_reason {
6230 /*
6231 * Beginning of reset reasons.
6232 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006233 CHIPSET_RESET_BEGIN = 0,
6234 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6235 /* Custom reason defined by a board.c or baseboard.c file */
6236 CHIPSET_RESET_BOARD_CUSTOM,
6237 /* Believe that the AP has hung */
6238 CHIPSET_RESET_HANG_REBOOT,
6239 /* Reset by EC console command */
6240 CHIPSET_RESET_CONSOLE_CMD,
6241 /* Reset by EC host command */
6242 CHIPSET_RESET_HOST_CMD,
6243 /* Keyboard module reset key combination */
6244 CHIPSET_RESET_KB_SYSRESET,
6245 /* Keyboard module warm reboot */
6246 CHIPSET_RESET_KB_WARM_REBOOT,
6247 /* Debug module warm reboot */
6248 CHIPSET_RESET_DBG_WARM_REBOOT,
6249 /* I cannot self-terminate. You must lower me into the steel. */
6250 CHIPSET_RESET_AP_REQ,
6251 /* Reset as side-effect of startup sequence */
6252 CHIPSET_RESET_INIT,
6253 /* EC detected an AP watchdog event. */
6254 CHIPSET_RESET_AP_WATCHDOG,
6255
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006256 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006257
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006258 /*
6259 * Beginning of shutdown reasons.
6260 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006261 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6262 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6263 /* Forcing a shutdown as part of EC initialization */
6264 CHIPSET_SHUTDOWN_INIT,
6265 /* Custom reason on a per-board basis. */
6266 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6267 /* This is a reason to inhibit startup, not cause shut down. */
6268 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6269 /* A power_wait_signal is being asserted */
6270 CHIPSET_SHUTDOWN_WAIT,
6271 /* Critical battery level. */
6272 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6273 /* Because you told me to. */
6274 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6275 /* Forcing a shutdown to effect entry to G3. */
6276 CHIPSET_SHUTDOWN_G3,
6277 /* Force shutdown due to over-temperature. */
6278 CHIPSET_SHUTDOWN_THERMAL,
6279 /* Force a chipset shutdown from the power button through EC */
6280 CHIPSET_SHUTDOWN_BUTTON,
6281
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006282 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006283};
6284
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006285struct ec_response_uptime_info {
6286 /*
6287 * Number of milliseconds since the last EC boot. Sysjump resets
6288 * typically do not restart the EC's time_since_boot epoch.
6289 *
6290 * WARNING: The EC's sense of time is much less accurate than the AP's
6291 * sense of time, in both phase and frequency. This timebase is similar
6292 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6293 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006294 uint32_t time_since_ec_boot_ms;
6295
6296 /*
6297 * Number of times the AP was reset by the EC since the last EC boot.
6298 * Note that the AP may be held in reset by the EC during the initial
6299 * boot sequence, such that the very first AP boot may count as more
6300 * than one here.
6301 */
6302 uint32_t ap_resets_since_ec_boot;
6303
6304 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006305 * The set of flags which describe the EC's most recent reset.
6306 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006307 */
6308 uint32_t ec_reset_flags;
6309
6310 /* Empty log entries have both the cause and timestamp set to zero. */
6311 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006312 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006313 uint16_t reset_cause;
6314
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006315 /* Reserved for protocol growth. */
6316 uint16_t reserved;
6317
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006318 /*
6319 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006320 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6321 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006322 */
6323 uint32_t reset_time_ms;
6324 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006325} __ec_align4;
6326
6327/*
6328 * Add entropy to the device secret (stored in the rollback region).
6329 *
6330 * Depending on the chip, the operation may take a long time (e.g. to erase
6331 * flash), so the commands are asynchronous.
6332 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006333#define EC_CMD_ADD_ENTROPY 0x0122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006334
6335enum add_entropy_action {
6336 /* Add entropy to the current secret. */
6337 ADD_ENTROPY_ASYNC = 0,
6338 /*
6339 * Add entropy, and also make sure that the previous secret is erased.
6340 * (this can be implemented by adding entropy multiple times until
6341 * all rolback blocks have been overwritten).
6342 */
6343 ADD_ENTROPY_RESET_ASYNC = 1,
6344 /* Read back result from the previous operation. */
6345 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006346};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006347
6348struct ec_params_rollback_add_entropy {
6349 uint8_t action;
6350} __ec_align1;
6351
6352/*
6353 * Perform a single read of a given ADC channel.
6354 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006355#define EC_CMD_ADC_READ 0x0123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006356
6357struct ec_params_adc_read {
6358 uint8_t adc_channel;
6359} __ec_align1;
6360
6361struct ec_response_adc_read {
6362 int32_t adc_value;
6363} __ec_align4;
6364
6365/*
6366 * Read back rollback info
6367 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006368#define EC_CMD_ROLLBACK_INFO 0x0124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006369
6370struct ec_response_rollback_info {
6371 int32_t id; /* Incrementing number to indicate which region to use. */
6372 int32_t rollback_min_version;
6373 int32_t rw_rollback_version;
6374} __ec_align4;
6375
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006376/* Issue AP reset */
6377#define EC_CMD_AP_RESET 0x0125
6378
6379/*****************************************************************************/
6380/* Locate peripheral chips
6381 *
6382 * Return values:
6383 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6384 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6385 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6386 */
6387#define EC_CMD_LOCATE_CHIP 0x0126
6388
6389enum ec_chip_type {
6390 EC_CHIP_TYPE_CBI_EEPROM = 0,
6391 EC_CHIP_TYPE_TCPC = 1,
6392 EC_CHIP_TYPE_COUNT,
6393 EC_CHIP_TYPE_MAX = 0xFF,
6394};
6395
6396enum ec_bus_type {
6397 EC_BUS_TYPE_I2C = 0,
6398 EC_BUS_TYPE_EMBEDDED = 1,
6399 EC_BUS_TYPE_COUNT,
6400 EC_BUS_TYPE_MAX = 0xFF,
6401};
6402
6403struct ec_i2c_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006404 uint16_t port; /* Physical port for device */
6405 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006406};
6407
6408struct ec_params_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006409 uint8_t type; /* enum ec_chip_type */
6410 uint8_t index; /* Specifies one instance of chip type */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006411 /* Used for type specific parameters in future */
6412 union {
6413 uint16_t reserved;
6414 };
6415} __ec_align2;
6416
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006417struct ec_response_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006418 uint8_t bus_type; /* enum ec_bus_type */
6419 uint8_t reserved; /* Aligning the following union to 2 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006420 union {
6421 struct ec_i2c_info i2c_info;
6422 };
6423} __ec_align2;
6424
Jett Rinkba2edaf2020-01-14 11:49:06 -07006425/*
6426 * Reboot AP on G3
6427 *
6428 * This command is used for validation purpose, where the AP needs to be
6429 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006430 * wake events.
6431 * - With command version 0:
6432 * AP reboots immediately from G3
6433 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6434 * - With command version 1:
6435 * AP reboots after the user specified delay
6436 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006437 */
6438#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6439
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006440struct ec_params_reboot_ap_on_g3_v1 {
6441 /* configurable delay in seconds in G3 state */
6442 uint32_t reboot_ap_at_g3_delay;
6443} __ec_align4;
6444
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006445/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006446/* Get PD port capabilities
6447 *
6448 * Returns the following static *capabilities* of the given port:
6449 * 1) Power role: source, sink, or dual. It is not anticipated that
6450 * future CrOS devices would ever be only a source, so the options are
6451 * sink or dual.
6452 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6453 * believe any CrOS device would support Try.SNK, so this would be source
6454 * or none).
6455 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6456 * for CrOS devices.
6457 */
6458#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6459
6460enum ec_pd_power_role_caps {
6461 EC_PD_POWER_ROLE_SOURCE = 0,
6462 EC_PD_POWER_ROLE_SINK = 1,
6463 EC_PD_POWER_ROLE_DUAL = 2,
6464};
6465
6466enum ec_pd_try_power_role_caps {
6467 EC_PD_TRY_POWER_ROLE_NONE = 0,
6468 EC_PD_TRY_POWER_ROLE_SINK = 1,
6469 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6470};
6471
6472enum ec_pd_data_role_caps {
6473 EC_PD_DATA_ROLE_DFP = 0,
6474 EC_PD_DATA_ROLE_UFP = 1,
6475 EC_PD_DATA_ROLE_DUAL = 2,
6476};
6477
6478/* From: power_manager/power_supply_properties.proto */
6479enum ec_pd_port_location {
6480 /* The location of the port is unknown, or there's only one port. */
6481 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6482
6483 /*
6484 * Various positions on the device. The first word describes the side of
6485 * the device where the port is located while the second clarifies the
6486 * position. For example, LEFT_BACK means the farthest-back port on the
6487 * left side, while BACK_LEFT means the leftmost port on the back of the
6488 * device.
6489 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006490 EC_PD_PORT_LOCATION_LEFT = 1,
6491 EC_PD_PORT_LOCATION_RIGHT = 2,
6492 EC_PD_PORT_LOCATION_BACK = 3,
6493 EC_PD_PORT_LOCATION_FRONT = 4,
6494 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6495 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006496 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006497 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6498 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6499 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006500};
6501
6502struct ec_params_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006503 uint8_t port; /* Which port to interrogate */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006504} __ec_align1;
6505
6506struct ec_response_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006507 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6508 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6509 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6510 uint8_t pd_port_location; /* enum ec_pd_port_location */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006511} __ec_align1;
6512
6513/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006514/*
6515 * Button press simulation
6516 *
6517 * This command is used to simulate a button press.
6518 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6519 * Time duration for which button needs to be pressed is an optional parameter.
6520 *
6521 * NOTE: This is only available on unlocked devices for testing purposes only.
6522 */
6523#define EC_CMD_BUTTON 0x0129
6524
6525struct ec_params_button {
6526 /* Button mask aligned to enum keyboard_button_type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006527 uint32_t btn_mask;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006528
6529 /* Duration in milliseconds button needs to be pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006530 uint32_t press_ms;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006531} __ec_align1;
6532
6533enum keyboard_button_type {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006534 KEYBOARD_BUTTON_POWER = 0,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006535 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006536 KEYBOARD_BUTTON_VOLUME_UP = 2,
6537 KEYBOARD_BUTTON_RECOVERY = 3,
6538 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6539 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6540 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6541 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6542 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6543 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6544 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6545 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006546
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006547 KEYBOARD_BUTTON_COUNT,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006548};
Yidi Lin42f79592020-09-21 18:04:10 +08006549
Rajat Jainc0495722020-04-02 23:58:35 -07006550/*****************************************************************************/
6551/*
6552 * "Get the Keyboard Config". An EC implementing this command is expected to be
6553 * vivaldi capable, i.e. can send action codes for the top row keys.
6554 * Additionally, capability to send function codes for the same keys is
6555 * optional and acceptable.
6556 *
6557 * Note: If the top row can generate both function and action codes by
6558 * using a dedicated Fn key, it does not matter whether the key sends
6559 * "function" or "action" codes by default. In both cases, the response
6560 * for this command will look the same.
6561 */
6562#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6563
6564/* Possible values for the top row keys */
6565enum action_key {
6566 TK_ABSENT = 0,
6567 TK_BACK = 1,
6568 TK_FORWARD = 2,
6569 TK_REFRESH = 3,
6570 TK_FULLSCREEN = 4,
6571 TK_OVERVIEW = 5,
6572 TK_BRIGHTNESS_DOWN = 6,
6573 TK_BRIGHTNESS_UP = 7,
6574 TK_VOL_MUTE = 8,
6575 TK_VOL_DOWN = 9,
6576 TK_VOL_UP = 10,
6577 TK_SNAPSHOT = 11,
6578 TK_PRIVACY_SCRN_TOGGLE = 12,
6579 TK_KBD_BKLIGHT_DOWN = 13,
6580 TK_KBD_BKLIGHT_UP = 14,
6581 TK_PLAY_PAUSE = 15,
6582 TK_NEXT_TRACK = 16,
6583 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006584 TK_KBD_BKLIGHT_TOGGLE = 18,
6585 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006586 TK_MENU = 20,
Rajat Jainc0495722020-04-02 23:58:35 -07006587};
6588
6589/*
6590 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6591 * If this needs to change, please create a new version of the command.
6592 */
6593#define MAX_TOP_ROW_KEYS 15
6594#define MIN_TOP_ROW_KEYS 10
6595
6596/*
6597 * Is the keyboard capable of sending function keys *in addition to*
6598 * action keys. This is possible for e.g. if the keyboard has a
6599 * dedicated Fn key.
6600 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006601#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
Rajat Jainc0495722020-04-02 23:58:35 -07006602/*
6603 * Whether the keyboard has a dedicated numeric keyboard.
6604 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006605#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
Rajat Jainc0495722020-04-02 23:58:35 -07006606/*
6607 * Whether the keyboard has a screenlock key.
6608 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006609#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
Rajat Jainc0495722020-04-02 23:58:35 -07006610
6611struct ec_response_keybd_config {
6612 /*
6613 * Number of top row keys, excluding Esc and Screenlock.
6614 * If this is 0, all Vivaldi keyboard code is disabled.
6615 * (i.e. does not expose any tables to the kernel).
6616 */
6617 uint8_t num_top_row_keys;
6618
6619 /*
6620 * The action keys in the top row, in order from left to right.
6621 * The values are filled from enum action_key. Esc and Screenlock
6622 * keys are not considered part of top row keys.
6623 */
6624 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6625
6626 /* Capability flags */
6627 uint8_t capabilities;
6628
6629} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006630
Yidi Lin42f79592020-09-21 18:04:10 +08006631/*
6632 * Configure smart discharge
6633 */
6634#define EC_CMD_SMART_DISCHARGE 0x012B
6635
Caveh Jalali024ffe32023-01-30 14:35:19 -08006636#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
Yidi Lin42f79592020-09-21 18:04:10 +08006637
6638/* Discharge rates when the system is in cutoff or hibernation. */
6639struct discharge_rate {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006640 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6641 uint16_t hibern; /* Discharge rate (uA) in hibernation */
Yidi Lin42f79592020-09-21 18:04:10 +08006642};
6643
6644struct smart_discharge_zone {
6645 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6646 int cutoff;
6647 /* When the capacity (mAh) is below this, EC stays up. */
6648 int stayup;
6649};
6650
6651struct ec_params_smart_discharge {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006652 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
Yidi Lin42f79592020-09-21 18:04:10 +08006653 /*
6654 * Desired hours for the battery to survive before reaching 0%. Set to
6655 * zero to disable smart discharging. That is, the system hibernates as
6656 * soon as the G3 idle timer expires.
6657 */
6658 uint16_t hours_to_zero;
6659 /* Set both to zero to keep the current rates. */
6660 struct discharge_rate drate;
6661};
6662
6663struct ec_response_smart_discharge {
6664 uint16_t hours_to_zero;
6665 struct discharge_rate drate;
6666 struct smart_discharge_zone dzone;
6667};
6668
6669/*****************************************************************************/
6670/* Voltage regulator controls */
6671
6672/*
6673 * Get basic info of voltage regulator for given index.
6674 *
6675 * Returns the regulator name and supported voltage list in mV.
6676 */
6677#define EC_CMD_REGULATOR_GET_INFO 0x012C
6678
6679/* Maximum length of regulator name */
6680#define EC_REGULATOR_NAME_MAX_LEN 16
6681
6682/* Maximum length of the supported voltage list. */
6683#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6684
6685struct ec_params_regulator_get_info {
6686 uint32_t index;
6687} __ec_align4;
6688
6689struct ec_response_regulator_get_info {
6690 char name[EC_REGULATOR_NAME_MAX_LEN];
6691 uint16_t num_voltages;
6692 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6693} __ec_align2;
6694
6695/*
6696 * Configure the regulator as enabled / disabled.
6697 */
6698#define EC_CMD_REGULATOR_ENABLE 0x012D
6699
6700struct ec_params_regulator_enable {
6701 uint32_t index;
6702 uint8_t enable;
6703} __ec_align4;
6704
6705/*
6706 * Query if the regulator is enabled.
6707 *
6708 * Returns 1 if the regulator is enabled, 0 if not.
6709 */
6710#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6711
6712struct ec_params_regulator_is_enabled {
6713 uint32_t index;
6714} __ec_align4;
6715
6716struct ec_response_regulator_is_enabled {
6717 uint8_t enabled;
6718} __ec_align1;
6719
6720/*
6721 * Set voltage for the voltage regulator within the range specified.
6722 *
6723 * The driver should select the voltage in range closest to min_mv.
6724 *
6725 * Also note that this might be called before the regulator is enabled, and the
6726 * setting should be in effect after the regulator is enabled.
6727 */
6728#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6729
6730struct ec_params_regulator_set_voltage {
6731 uint32_t index;
6732 uint32_t min_mv;
6733 uint32_t max_mv;
6734} __ec_align4;
6735
6736/*
6737 * Get the currently configured voltage for the voltage regulator.
6738 *
6739 * Note that this might be called before the regulator is enabled, and this
6740 * should return the configured output voltage if the regulator is enabled.
6741 */
6742#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6743
6744struct ec_params_regulator_get_voltage {
6745 uint32_t index;
6746} __ec_align4;
6747
6748struct ec_response_regulator_get_voltage {
6749 uint32_t voltage_mv;
6750} __ec_align4;
6751
6752/*
6753 * Gather all discovery information for the given port and partner type.
6754 *
6755 * Note that if discovery has not yet completed, only the currently completed
6756 * responses will be filled in. If the discovery data structures are changed
6757 * in the process of the command running, BUSY will be returned.
6758 *
6759 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6760 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6761 * maximum parameter size.
6762 */
6763#define EC_CMD_TYPEC_DISCOVERY 0x0131
6764
6765enum typec_partner_type {
6766 TYPEC_PARTNER_SOP = 0,
6767 TYPEC_PARTNER_SOP_PRIME = 1,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006768 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
Yidi Lin42f79592020-09-21 18:04:10 +08006769};
6770
6771struct ec_params_typec_discovery {
6772 uint8_t port;
6773 uint8_t partner_type; /* enum typec_partner_type */
6774} __ec_align1;
6775
6776struct svid_mode_info {
6777 uint16_t svid;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006778 uint16_t mode_count; /* Number of modes partner sent */
Caveh Jalali839ada12022-10-31 23:16:48 -07006779 uint32_t mode_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08006780};
6781
6782struct ec_response_typec_discovery {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006783 uint8_t identity_count; /* Number of identity VDOs partner sent */
6784 uint8_t svid_count; /* Number of SVIDs partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08006785 uint16_t reserved;
Caveh Jalali839ada12022-10-31 23:16:48 -07006786 uint32_t discovery_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08006787 struct svid_mode_info svids[0];
6788} __ec_align1;
6789
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006790/* USB Type-C commands for AP-controlled device policy. */
6791#define EC_CMD_TYPEC_CONTROL 0x0132
6792
6793enum typec_control_command {
6794 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6795 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006796 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006797 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006798 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006799 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
6800 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006801};
6802
6803/* Modes (USB or alternate) that a type-C port may enter. */
6804enum typec_mode {
6805 TYPEC_MODE_DP,
6806 TYPEC_MODE_TBT,
6807 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006808};
6809
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006810/* Replies the AP may specify to the TBT EnterMode command as a UFP */
6811enum typec_tbt_ufp_reply {
6812 TYPEC_TBT_UFP_REPLY_NAK,
6813 TYPEC_TBT_UFP_REPLY_ACK,
6814};
6815
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006816#define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
6817
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006818struct typec_usb_mux_set {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006819 /* Index of the mux to set in the chain */
6820 uint8_t mux_index;
6821
6822 /* USB_PD_MUX_*-encoded USB mux state to set */
6823 uint8_t mux_flags;
6824} __ec_align1;
6825
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006826struct typec_vdm_req {
6827 /* VDM data, including VDM header */
6828 uint32_t vdm_data[VDO_MAX_SIZE];
6829 /* Number of 32-bit fields filled in */
6830 uint8_t vdm_data_objects;
6831 /* Partner to address - see enum typec_partner_type */
6832 uint8_t partner_type;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006833} __ec_align1;
6834
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006835struct ec_params_typec_control {
6836 uint8_t port;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006837 uint8_t command; /* enum typec_control_command */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006838 uint16_t reserved;
6839
6840 /*
6841 * This section will be interpreted based on |command|. Define a
6842 * placeholder structure to avoid having to increase the size and bump
6843 * the command version when adding new sub-commands.
6844 */
6845 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006846 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006847 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006848 /* Used for ENTER_MODE - enum typec_mode */
6849 uint8_t mode_to_enter;
6850 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
6851 uint8_t tbt_ufp_reply;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006852 /* Used for USB_MUX_SET */
6853 struct typec_usb_mux_set mux_params;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006854 /* Used for BIST_SHARE_MODE */
6855 uint8_t bist_share_mode;
6856 /* Used for VMD_REQ */
6857 struct typec_vdm_req vdm_req_params;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006858 uint8_t placeholder[128];
6859 };
6860} __ec_align1;
6861
6862/*
6863 * Gather all status information for a port.
6864 *
6865 * Note: this covers many of the return fields from the deprecated
6866 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6867 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6868 * EC_CMD_USB_PD_CONTROL command.
6869 *
6870 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006871 */
6872#define EC_CMD_TYPEC_STATUS 0x0133
6873
6874/*
6875 * Power role.
6876 *
6877 * Note this is also used for PD header creation, and values align to those in
6878 * the Power Delivery Specification Revision 3.0 (See
6879 * 6.2.1.1.4 Port Power Role).
6880 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006881enum pd_power_role {
6882 PD_ROLE_SINK = 0,
6883 PD_ROLE_SOURCE = 1,
6884};
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006885
6886/*
6887 * Data role.
6888 *
6889 * Note this is also used for PD header creation, and the first two values
6890 * align to those in the Power Delivery Specification Revision 3.0 (See
6891 * 6.2.1.1.6 Port Data Role).
6892 */
6893enum pd_data_role {
6894 PD_ROLE_UFP = 0,
6895 PD_ROLE_DFP = 1,
6896 PD_ROLE_DISCONNECTED = 2,
6897};
6898
6899enum pd_vconn_role {
6900 PD_ROLE_VCONN_OFF = 0,
6901 PD_ROLE_VCONN_SRC = 1,
6902};
6903
6904/*
6905 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6906 * regardless of whether a debug accessory is connected.
6907 */
6908enum tcpc_cc_polarity {
6909 /*
6910 * _CCx: is used to indicate the polarity while not connected to
6911 * a Debug Accessory. Only one CC line will assert a resistor and
6912 * the other will be open.
6913 */
6914 POLARITY_CC1 = 0,
6915 POLARITY_CC2 = 1,
6916
6917 /*
6918 * _CCx_DTS is used to indicate the polarity while connected to a
6919 * SRC Debug Accessory. Assert resistors on both lines.
6920 */
6921 POLARITY_CC1_DTS = 2,
6922 POLARITY_CC2_DTS = 3,
6923
6924 /*
6925 * The current TCPC code relies on these specific POLARITY values.
6926 * Adding in a check to verify if the list grows for any reason
6927 * that this will give a hint that other places need to be
6928 * adjusted.
6929 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006930 POLARITY_COUNT,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006931};
6932
Caveh Jalali024ffe32023-01-30 14:35:19 -08006933#define MODE_DP_PIN_A BIT(0)
6934#define MODE_DP_PIN_B BIT(1)
6935#define MODE_DP_PIN_C BIT(2)
6936#define MODE_DP_PIN_D BIT(3)
6937#define MODE_DP_PIN_E BIT(4)
6938#define MODE_DP_PIN_F BIT(5)
6939#define MODE_DP_PIN_ALL GENMASK(5, 0)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006940
Caveh Jalali024ffe32023-01-30 14:35:19 -08006941#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6942#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
6943#define PD_STATUS_EVENT_HARD_RESET BIT(2)
6944#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
6945#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
6946#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006947#define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
6948#define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
6949#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006950
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006951/*
6952 * Encode and decode for BCD revision response
6953 *
6954 * Note: the major revision set is written assuming that the value given is the
6955 * Specification Revision from the PD header, which currently only maps to PD
6956 * 1.0-3.0 with the major revision being one greater than the binary value.
6957 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006958#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6959#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6960#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006961
6962/*
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006963 * Encode revision from partner RMDO
6964 *
6965 * Unlike the specification revision given in the PD header, specification and
6966 * version information returned in the revision message data object (RMDO) is
6967 * not offset.
6968 */
6969#define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
6970#define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
6971#define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
6972#define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
6973
6974/*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006975 * Decode helpers for Source and Sink Capability PDOs
6976 *
6977 * Note: The Power Delivery Specification should be considered the ultimate
6978 * source of truth on the decoding of these PDOs
6979 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006980#define PDO_TYPE_FIXED (0 << 30)
6981#define PDO_TYPE_BATTERY (1 << 30)
6982#define PDO_TYPE_VARIABLE (2 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006983#define PDO_TYPE_AUGMENTED (3 << 30)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006984#define PDO_TYPE_MASK (3 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006985
6986/*
6987 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6988 *
6989 * <31:30> : Fixed Supply
6990 * <29> : Dual-Role Power
6991 * <28> : SNK/SRC dependent
6992 * <27> : Unconstrained Power
6993 * <26> : USB Communications Capable
6994 * <25> : Dual-Role Data
6995 * <24:20> : SNK/SRC dependent
6996 * <19:10> : Voltage in 50mV Units
6997 * <9:0> : Maximum Current in 10mA units
6998 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006999#define PDO_FIXED_DUAL_ROLE BIT(29)
7000#define PDO_FIXED_UNCONSTRAINED BIT(27)
7001#define PDO_FIXED_COMM_CAP BIT(26)
7002#define PDO_FIXED_DATA_SWAP BIT(25)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007003#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007004#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7005#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007006
7007/*
7008 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
7009 *
7010 * <31:30> : Battery
7011 * <29:20> : Maximum Voltage in 50mV units
7012 * <19:10> : Minimum Voltage in 50mV units
7013 * <9:0> : Maximum Allowable Power in 250mW units
7014 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007015#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7016#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7017#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007018
7019/*
7020 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7021 *
7022 * <31:30> : Variable Supply (non-Battery)
7023 * <29:20> : Maximum Voltage in 50mV units
7024 * <19:10> : Minimum Voltage in 50mV units
7025 * <9:0> : Operational Current in 10mA units
7026 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007027#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7028#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7029#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007030
7031/*
7032 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7033 *
7034 * Note this type is reserved in PD 2.0, and only one type of APDO is
7035 * supported as of the cited version.
7036 *
7037 * <31:30> : Augmented Power Data Object
7038 * <29:28> : Programmable Power Supply
7039 * <27> : PPS Power Limited
7040 * <26:25> : Reserved
7041 * <24:17> : Maximum Voltage in 100mV increments
7042 * <16> : Reserved
7043 * <15:8> : Minimum Voltage in 100mV increments
7044 * <7> : Reserved
7045 * <6:0> : Maximum Current in 50mA increments
7046 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007047#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7048#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7049#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007050
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007051struct ec_params_typec_status {
7052 uint8_t port;
7053} __ec_align1;
7054
Caveh Jalali839ada12022-10-31 23:16:48 -07007055/*
7056 * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1.
7057 * If you need to support old ECs who speak only v0, use
7058 * ec_response_typec_status_v0 instead. They're binary-compatible.
7059 */
7060struct ec_response_typec_status /* DEPRECATED */ {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007061 uint8_t pd_enabled; /* PD communication enabled - bool */
7062 uint8_t dev_connected; /* Device connected - bool */
7063 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7064 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007065
Caveh Jalali024ffe32023-01-30 14:35:19 -08007066 uint8_t power_role; /* enum pd_power_role */
7067 uint8_t data_role; /* enum pd_data_role */
7068 uint8_t vconn_role; /* enum pd_vconn_role */
7069 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007070
Caveh Jalali024ffe32023-01-30 14:35:19 -08007071 uint8_t polarity; /* enum tcpc_cc_polarity */
7072 uint8_t cc_state; /* enum pd_cc_states */
7073 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7074 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007075
Caveh Jalali024ffe32023-01-30 14:35:19 -08007076 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007077
Caveh Jalali024ffe32023-01-30 14:35:19 -08007078 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007079
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007080 /*
7081 * BCD PD revisions for partners
7082 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007083 * The format has the PD major revision in the upper nibble, and the PD
7084 * minor revision in the next nibble. The following two nibbles hold the
7085 * major and minor specification version. If a partner does not support
7086 * the Revision message, only the major revision will be given.
7087 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007088 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007089 * PD revision/version will be 0 if no PD device is connected.
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007090 */
7091 uint16_t sop_revision;
7092 uint16_t sop_prime_revision;
7093
Caveh Jalali024ffe32023-01-30 14:35:19 -08007094 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007095
Caveh Jalali024ffe32023-01-30 14:35:19 -08007096 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007097} __ec_align1;
7098
Caveh Jalali839ada12022-10-31 23:16:48 -07007099struct cros_ec_typec_status {
7100 uint8_t pd_enabled; /* PD communication enabled - bool */
7101 uint8_t dev_connected; /* Device connected - bool */
7102 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7103 uint8_t source_cap_count; /* Number of Source Cap PDOs */
7104
7105 uint8_t power_role; /* enum pd_power_role */
7106 uint8_t data_role; /* enum pd_data_role */
7107 uint8_t vconn_role; /* enum pd_vconn_role */
7108 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
7109
7110 uint8_t polarity; /* enum tcpc_cc_polarity */
7111 uint8_t cc_state; /* enum pd_cc_states */
7112 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7113 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
7114
7115 char tc_state[32]; /* TC state name */
7116
7117 uint32_t events; /* PD_STATUS_EVENT bitmask */
7118
7119 /*
7120 * BCD PD revisions for partners
7121 *
7122 * The format has the PD major revision in the upper nibble, and the PD
7123 * minor revision in the next nibble. The following two nibbles hold the
7124 * major and minor specification version. If a partner does not support
7125 * the Revision message, only the major revision will be given.
7126 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
7127 *
7128 * PD revision/version will be 0 if no PD device is connected.
7129 */
7130 uint16_t sop_revision;
7131 uint16_t sop_prime_revision;
7132} __ec_align1;
7133
7134struct ec_response_typec_status_v0 {
7135 struct cros_ec_typec_status typec_status;
7136 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
7137 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
7138} __ec_align1;
7139
7140struct ec_response_typec_status_v1 {
7141 struct cros_ec_typec_status typec_status;
7142 uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */
7143 uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */
7144} __ec_align1;
7145
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007146/**
7147 * Get the number of peripheral charge ports
7148 */
7149#define EC_CMD_PCHG_COUNT 0x0134
7150
7151#define EC_PCHG_MAX_PORTS 8
7152
7153struct ec_response_pchg_count {
7154 uint8_t port_count;
7155} __ec_align1;
7156
7157/**
7158 * Get the status of a peripheral charge port
7159 */
7160#define EC_CMD_PCHG 0x0135
7161
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007162/* For v1 and v2 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007163struct ec_params_pchg {
7164 uint8_t port;
7165} __ec_align1;
7166
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007167struct ec_params_pchg_v3 {
7168 uint8_t port;
7169 /* Below are new in v3. */
7170 uint8_t reserved1;
7171 uint8_t reserved2;
7172 uint8_t reserved3;
7173 /* Errors acked by the host (thus to be cleared) */
7174 uint32_t error;
7175} __ec_align1;
7176
7177/* For v1 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007178struct ec_response_pchg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007179 uint32_t error; /* enum pchg_error */
7180 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007181 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007182 uint8_t unused0;
7183 uint8_t unused1;
7184 /* Fields added in version 1 */
7185 uint32_t fw_version;
7186 uint32_t dropped_event_count;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007187} __ec_align4;
7188
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007189/* For v2 and v3 */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007190struct ec_response_pchg_v2 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007191 uint32_t error; /* enum pchg_error */
7192 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007193 uint8_t battery_percentage;
7194 uint8_t unused0;
7195 uint8_t unused1;
7196 /* Fields added in version 1 */
7197 uint32_t fw_version;
7198 uint32_t dropped_event_count;
7199 /* Fields added in version 2 */
7200 uint32_t dropped_host_event_count;
7201} __ec_align4;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007202
7203enum pchg_state {
7204 /* Charger is reset and not initialized. */
7205 PCHG_STATE_RESET = 0,
7206 /* Charger is initialized or disabled. */
7207 PCHG_STATE_INITIALIZED,
7208 /* Charger is enabled and ready to detect a device. */
7209 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007210 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007211 PCHG_STATE_DETECTED,
7212 /* Device is being charged. */
7213 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007214 /* Device is fully charged. It implies DETECTED (& not charging). */
7215 PCHG_STATE_FULL,
7216 /* In download (a.k.a. firmware update) mode */
7217 PCHG_STATE_DOWNLOAD,
7218 /* In download mode. Ready for receiving data. */
7219 PCHG_STATE_DOWNLOADING,
7220 /* Device is ready for data communication. */
7221 PCHG_STATE_CONNECTED,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007222 /* Charger is in Built-In Self Test mode. */
7223 PCHG_STATE_BIST,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007224 /* Put no more entry below */
7225 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007226};
7227
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007228/* clang-format off */
7229#define EC_PCHG_STATE_TEXT \
7230 { \
7231 [PCHG_STATE_RESET] = "RESET", \
7232 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7233 [PCHG_STATE_ENABLED] = "ENABLED", \
7234 [PCHG_STATE_DETECTED] = "DETECTED", \
7235 [PCHG_STATE_CHARGING] = "CHARGING", \
7236 [PCHG_STATE_FULL] = "FULL", \
7237 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7238 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7239 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7240 [PCHG_STATE_BIST] = "BIST", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007241 }
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007242/* clang-format on */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007243
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007244/**
7245 * Update firmware of peripheral chip
7246 */
7247#define EC_CMD_PCHG_UPDATE 0x0136
7248
7249/* Port number is encoded in bit[28:31]. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007250#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007251/* Utility macros for converting MKBP event <-> port number. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007252#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7253#define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007254/* Utility macro for extracting event bits. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007255#define EC_MKBP_PCHG_EVENT_MASK(e) ((e)&GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007256
Caveh Jalali024ffe32023-01-30 14:35:19 -08007257#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7258#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7259#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7260#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7261#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007262
7263enum ec_pchg_update_cmd {
7264 /* Reset chip to normal mode. */
7265 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7266 /* Reset and put a chip in update (a.k.a. download) mode. */
7267 EC_PCHG_UPDATE_CMD_OPEN,
7268 /* Write a block of data containing FW image. */
7269 EC_PCHG_UPDATE_CMD_WRITE,
7270 /* Close update session. */
7271 EC_PCHG_UPDATE_CMD_CLOSE,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007272 /* Reset chip (without mode change). */
7273 EC_PCHG_UPDATE_CMD_RESET,
7274 /* Enable pass-through mode. */
7275 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007276 /* End of commands */
7277 EC_PCHG_UPDATE_CMD_COUNT,
7278};
7279
7280struct ec_params_pchg_update {
7281 /* PCHG port number */
7282 uint8_t port;
7283 /* enum ec_pchg_update_cmd */
7284 uint8_t cmd;
7285 /* Padding */
7286 uint8_t reserved0;
7287 uint8_t reserved1;
7288 /* Version of new firmware */
7289 uint32_t version;
7290 /* CRC32 of new firmware */
7291 uint32_t crc32;
7292 /* Address in chip memory where <data> is written to */
7293 uint32_t addr;
7294 /* Size of <data> */
7295 uint32_t size;
7296 /* Partial data of new firmware */
7297 uint8_t data[];
7298} __ec_align4;
7299
Caveh Jalali024ffe32023-01-30 14:35:19 -08007300BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7301 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007302
7303struct ec_response_pchg_update {
7304 /* Block size */
7305 uint32_t block_size;
7306} __ec_align4;
7307
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007308#define EC_CMD_DISPLAY_SOC 0x0137
7309
7310struct ec_response_display_soc {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007311 /* Display charge in 10ths of a % (1000=100.0%) */
7312 int16_t display_soc;
7313 /* Full factor in 10ths of a % (1000=100.0%) */
7314 int16_t full_factor;
7315 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7316 int16_t shutdown_soc;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007317} __ec_align2;
7318
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007319#define EC_CMD_SET_BASE_STATE 0x0138
7320
7321struct ec_params_set_base_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007322 uint8_t cmd; /* enum ec_set_base_state_cmd */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007323} __ec_align1;
7324
7325enum ec_set_base_state_cmd {
7326 EC_SET_BASE_STATE_DETACH = 0,
7327 EC_SET_BASE_STATE_ATTACH,
7328 EC_SET_BASE_STATE_RESET,
7329};
7330
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007331#define EC_CMD_I2C_CONTROL 0x0139
7332
7333/* Subcommands for I2C control */
7334
7335enum ec_i2c_control_command {
7336 EC_I2C_CONTROL_GET_SPEED,
7337 EC_I2C_CONTROL_SET_SPEED,
7338};
7339
7340#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7341
7342struct ec_params_i2c_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007343 uint8_t port; /* I2C port number */
7344 uint8_t cmd; /* enum ec_i2c_control_command */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007345 union {
7346 uint16_t speed_khz;
7347 } cmd_params;
7348} __ec_align_size1;
7349
7350struct ec_response_i2c_control {
7351 union {
7352 uint16_t speed_khz;
7353 } cmd_response;
7354} __ec_align_size1;
7355
Caveh Jalali024ffe32023-01-30 14:35:19 -08007356#define EC_CMD_RGBKBD_SET_COLOR 0x013A
7357#define EC_CMD_RGBKBD 0x013B
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007358
Caveh Jalali024ffe32023-01-30 14:35:19 -08007359#define EC_RGBKBD_MAX_KEY_COUNT 128
7360#define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7361#define EC_RGBKBD_MAX_SCALE 0xFF
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007362
7363enum rgbkbd_state {
7364 /* RGB keyboard is reset and not initialized. */
7365 RGBKBD_STATE_RESET = 0,
7366 /* RGB keyboard is initialized but not enabled. */
7367 RGBKBD_STATE_INITIALIZED,
7368 /* RGB keyboard is disabled. */
7369 RGBKBD_STATE_DISABLED,
7370 /* RGB keyboard is enabled and ready to receive a command. */
7371 RGBKBD_STATE_ENABLED,
7372
7373 /* Put no more entry below */
7374 RGBKBD_STATE_COUNT,
7375};
7376
7377enum ec_rgbkbd_subcmd {
7378 EC_RGBKBD_SUBCMD_CLEAR = 1,
7379 EC_RGBKBD_SUBCMD_DEMO = 2,
7380 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007381 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007382 EC_RGBKBD_SUBCMD_COUNT
7383};
7384
7385enum ec_rgbkbd_demo {
7386 EC_RGBKBD_DEMO_OFF = 0,
7387 EC_RGBKBD_DEMO_FLOW = 1,
7388 EC_RGBKBD_DEMO_DOT = 2,
7389 EC_RGBKBD_DEMO_COUNT,
7390};
7391
7392BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7393
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007394enum ec_rgbkbd_type {
7395 EC_RGBKBD_TYPE_UNKNOWN = 0,
7396 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7397 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7398 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7399 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7400 EC_RGBKBD_TYPE_COUNT,
7401};
7402
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007403struct ec_rgbkbd_set_scale {
7404 uint8_t key;
7405 struct rgb_s scale;
7406};
7407
7408struct ec_params_rgbkbd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007409 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007410 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007411 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7412 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007413 struct ec_rgbkbd_set_scale set_scale;
7414 };
7415} __ec_align1;
7416
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007417struct ec_response_rgbkbd {
7418 /*
7419 * RGBKBD type supported by the device.
7420 */
7421
7422 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7423} __ec_align1;
7424
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007425struct ec_params_rgbkbd_set_color {
7426 /* Specifies the starting key ID whose color is being changed. */
7427 uint8_t start_key;
7428 /* Specifies # of elements in <color>. */
7429 uint8_t length;
7430 /* RGB color data array of length up to MAX_KEY_COUNT. */
7431 struct rgb_s color[];
7432} __ec_align1;
7433
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007434/*
7435 * Gather the response to the most recent VDM REQ from the AP, as well
7436 * as popping the oldest VDM:Attention from the DPM queue
7437 */
7438#define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7439
7440struct ec_params_typec_vdm_response {
7441 uint8_t port;
7442} __ec_align1;
7443
7444struct ec_response_typec_vdm_response {
7445 /* Number of 32-bit fields filled in */
7446 uint8_t vdm_data_objects;
7447 /* Partner to address - see enum typec_partner_type */
7448 uint8_t partner_type;
7449 /* enum ec_status describing VDM response */
7450 uint16_t vdm_response_err;
7451 /* VDM data, including VDM header */
7452 uint32_t vdm_response[VDO_MAX_SIZE];
7453 /* Number of 32-bit Attention fields filled in */
7454 uint8_t vdm_attention_objects;
7455 /* Number of remaining messages to consume */
7456 uint8_t vdm_attention_left;
7457 /* Reserved */
7458 uint16_t reserved1;
7459 /* VDM:Attention contents */
7460 uint32_t vdm_attention[2];
7461} __ec_align1;
7462
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007463/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007464/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007465
7466/*****************************************************************************/
7467/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007468 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007469 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007470#define EC_CMD_CR51_BASE 0x0300
7471#define EC_CMD_CR51_LAST 0x03FF
7472
7473/*****************************************************************************/
7474/* Fingerprint MCU commands: range 0x0400-0x040x */
7475
7476/* Fingerprint SPI sensor passthru command: prototyping ONLY */
7477#define EC_CMD_FP_PASSTHRU 0x0400
7478
7479#define EC_FP_FLAG_NOT_COMPLETE 0x1
7480
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007481struct ec_params_fp_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007482 uint16_t len; /* Number of bytes to write then read */
7483 uint16_t flags; /* EC_FP_FLAG_xxx */
7484 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007485} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007486
7487/* Configure the Fingerprint MCU behavior */
7488#define EC_CMD_FP_MODE 0x0402
7489
7490/* Put the sensor in its lowest power mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007491#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007492/* Wait to see a finger on the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007493#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007494/* Poll until the finger has left the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007495#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007496/* Capture the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007497#define FP_MODE_CAPTURE BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007498/* Finger enrollment session on-going */
7499#define FP_MODE_ENROLL_SESSION BIT(4)
7500/* Enroll the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007501#define FP_MODE_ENROLL_IMAGE BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007502/* Try to match the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007503#define FP_MODE_MATCH BIT(6)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007504/* Reset and re-initialize the sensor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007505#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007506/* Sensor maintenance for dead pixels. */
7507#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007508/* special value: don't change anything just read back current mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007509#define FP_MODE_DONT_CHANGE BIT(31)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007510
Caveh Jalali024ffe32023-01-30 14:35:19 -08007511#define FP_VALID_MODES \
7512 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
7513 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
7514 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
7515 FP_MODE_DONT_CHANGE)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007516
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007517/* Capture types defined in bits [30..28] */
7518#define FP_MODE_CAPTURE_TYPE_SHIFT 28
Caveh Jalali024ffe32023-01-30 14:35:19 -08007519#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007520/**
7521 * enum fp_capture_type - Specifies the "mode" when capturing images.
7522 *
7523 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
7524 * image (produces 'frame_size' bytes)
7525 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
7526 * bpp bits)
7527 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
7528 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
7529 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
7530 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
7531 * @FP_CAPTURE_TYPE_MAX: End of enum
7532 *
7533 * @note This enum must remain ordered, if you add new values you must ensure
7534 * that FP_CAPTURE_TYPE_MAX is still the last one.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007535 */
7536enum fp_capture_type {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007537 FP_CAPTURE_VENDOR_FORMAT = 0,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007538 FP_CAPTURE_SIMPLE_IMAGE = 1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007539 FP_CAPTURE_PATTERN0 = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007540 FP_CAPTURE_PATTERN1 = 3,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007541 FP_CAPTURE_QUALITY_TEST = 4,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007542 FP_CAPTURE_RESET_TEST = 5,
7543 FP_CAPTURE_TYPE_MAX,
7544};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007545/* Extracts the capture type from the sensor 'mode' word */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007546#define FP_CAPTURE_TYPE(mode) \
7547 (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007548
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007549struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007550 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007551} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007552
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007553struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007554 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007555} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007556
7557/* Retrieve Fingerprint sensor information */
7558#define EC_CMD_FP_INFO 0x0403
7559
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007560/* Number of dead pixels detected on the last maintenance */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007561#define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007562/* Unknown number of dead pixels detected on the last maintenance */
7563#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007564/* No interrupt from the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007565#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007566/* SPI communication error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007567#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007568/* Invalid sensor Hardware ID */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007569#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007570/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007571#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007572
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007573struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007574 /* Sensor identification */
7575 uint32_t vendor_id;
7576 uint32_t product_id;
7577 uint32_t model_id;
7578 uint32_t version;
7579 /* Image frame characteristics */
7580 uint32_t frame_size;
7581 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7582 uint16_t width;
7583 uint16_t height;
7584 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007585 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007586} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007587
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007588struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007589 /* Sensor identification */
7590 uint32_t vendor_id;
7591 uint32_t product_id;
7592 uint32_t model_id;
7593 uint32_t version;
7594 /* Image frame characteristics */
7595 uint32_t frame_size;
7596 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7597 uint16_t width;
7598 uint16_t height;
7599 uint16_t bpp;
7600 uint16_t errors; /* see FP_ERROR_ flags above */
7601 /* Template/finger current information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007602 uint32_t template_size; /* max template size in bytes */
7603 uint16_t template_max; /* maximum number of fingers/templates */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007604 uint16_t template_valid; /* number of valid fingers/templates */
7605 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007606 uint32_t template_version; /* version of the template format */
7607} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007608
7609/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007610#define EC_CMD_FP_FRAME 0x0404
7611
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007612/* constants defining the 'offset' field which also contains the frame index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007613#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007614/* Frame buffer where the captured image is stored */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007615#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007616/* First frame buffer holding a template */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007617#define FP_FRAME_INDEX_TEMPLATE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007618#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007619#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007620
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007621/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007622#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007623
7624/* Constants for encryption parameters */
7625#define FP_CONTEXT_NONCE_BYTES 12
7626#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7627#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007628#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007629#define FP_CONTEXT_TPM_BYTES 32
7630
Jett Rinkba2edaf2020-01-14 11:49:06 -07007631/* Constants for positive match parameters. */
7632#define FP_POSITIVE_MATCH_SALT_BYTES 16
7633
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007634struct ec_fp_template_encryption_metadata {
7635 /*
7636 * Version of the structure format (N=3).
7637 */
7638 uint16_t struct_version;
7639 /* Reserved bytes, set to 0. */
7640 uint16_t reserved;
7641 /*
7642 * The salt is *only* ever used for key derivation. The nonce is unique,
7643 * a different one is used for every message.
7644 */
7645 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007646 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007647 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7648};
7649
7650struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007651 /*
7652 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7653 * in the high nibble, and the real offset within the frame in
7654 * FP_FRAME_OFFSET_MASK.
7655 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007656 uint32_t offset;
7657 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007658} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007659
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007660/* Load a template into the MCU */
7661#define EC_CMD_FP_TEMPLATE 0x0405
7662
7663/* Flag in the 'size' field indicating that the full template has been sent */
7664#define FP_TEMPLATE_COMMIT 0x80000000
7665
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007666struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007667 uint32_t offset;
7668 uint32_t size;
7669 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007670} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007671
7672/* Clear the current fingerprint user context and set a new one */
7673#define EC_CMD_FP_CONTEXT 0x0406
7674
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007675struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007676 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007677} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007678
Jett Rinkba2edaf2020-01-14 11:49:06 -07007679enum fp_context_action {
7680 FP_CONTEXT_ASYNC = 0,
7681 FP_CONTEXT_GET_RESULT = 1,
7682};
7683
7684/* Version 1 of the command is "asynchronous". */
7685struct ec_params_fp_context_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007686 uint8_t action; /**< enum fp_context_action */
7687 uint8_t reserved[3]; /**< padding for alignment */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007688 uint32_t userid[FP_CONTEXT_USERID_WORDS];
7689} __ec_align4;
7690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007691#define EC_CMD_FP_STATS 0x0407
7692
Caveh Jalali024ffe32023-01-30 14:35:19 -08007693#define FPSTATS_CAPTURE_INV BIT(0)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007694#define FPSTATS_MATCHING_INV BIT(1)
7695
7696struct ec_response_fp_stats {
7697 uint32_t capture_time_us;
7698 uint32_t matching_time_us;
7699 uint32_t overall_time_us;
7700 struct {
7701 uint32_t lo;
7702 uint32_t hi;
7703 } overall_t0;
7704 uint8_t timestamps_invalid;
7705 int8_t template_matched;
7706} __ec_align2;
7707
7708#define EC_CMD_FP_SEED 0x0408
7709struct ec_params_fp_seed {
7710 /*
7711 * Version of the structure format (N=3).
7712 */
7713 uint16_t struct_version;
7714 /* Reserved bytes, set to 0. */
7715 uint16_t reserved;
7716 /* Seed from the TPM. */
7717 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7718} __ec_align4;
7719
7720#define EC_CMD_FP_ENC_STATUS 0x0409
7721
7722/* FP TPM seed has been set or not */
7723#define FP_ENC_STATUS_SEED_SET BIT(0)
7724
7725struct ec_response_fp_encryption_status {
7726 /* Used bits in encryption engine status */
7727 uint32_t valid_flags;
7728 /* Encryption engine status */
7729 uint32_t status;
7730} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007731
Jett Rinkba2edaf2020-01-14 11:49:06 -07007732#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7733struct ec_params_fp_read_match_secret {
7734 uint16_t fgr;
7735} __ec_align4;
7736
7737/* The positive match secret has the length of the SHA256 digest. */
7738#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7739struct ec_response_fp_read_match_secret {
7740 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7741} __ec_align4;
7742
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007743/*****************************************************************************/
7744/* Touchpad MCU commands: range 0x0500-0x05FF */
7745
7746/* Perform touchpad self test */
7747#define EC_CMD_TP_SELF_TEST 0x0500
7748
7749/* Get number of frame types, and the size of each type */
7750#define EC_CMD_TP_FRAME_INFO 0x0501
7751
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007752struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007753 uint32_t n_frames;
7754 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007755} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007756
7757/* Create a snapshot of current frame readings */
7758#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7759
7760/* Read the frame */
7761#define EC_CMD_TP_FRAME_GET 0x0503
7762
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007763struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007764 uint32_t frame_index;
7765 uint32_t offset;
7766 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007767} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007768
7769/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007770/* EC-EC communication commands: range 0x0600-0x06FF */
7771
7772#define EC_COMM_TEXT_MAX 8
7773
7774/*
7775 * Get battery static information, i.e. information that never changes, or
7776 * very infrequently.
7777 */
7778#define EC_CMD_BATTERY_GET_STATIC 0x0600
7779
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007780/**
7781 * struct ec_params_battery_static_info - Battery static info parameters
7782 * @index: Battery index.
7783 */
7784struct ec_params_battery_static_info {
7785 uint8_t index;
7786} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007787
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007788/**
7789 * struct ec_response_battery_static_info - Battery static info response
7790 * @design_capacity: Battery Design Capacity (mAh)
7791 * @design_voltage: Battery Design Voltage (mV)
7792 * @manufacturer: Battery Manufacturer String
7793 * @model: Battery Model Number String
7794 * @serial: Battery Serial Number String
7795 * @type: Battery Type String
7796 * @cycle_count: Battery Cycle Count
7797 */
7798struct ec_response_battery_static_info {
7799 uint16_t design_capacity;
7800 uint16_t design_voltage;
7801 char manufacturer[EC_COMM_TEXT_MAX];
7802 char model[EC_COMM_TEXT_MAX];
7803 char serial[EC_COMM_TEXT_MAX];
7804 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007805 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007806 uint32_t cycle_count;
7807} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007808
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007809/**
7810 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7811 * Equivalent to struct ec_response_battery_static_info, but with longer
7812 * strings.
7813 * @design_capacity: battery design capacity (in mAh)
7814 * @design_voltage: battery design voltage (in mV)
7815 * @cycle_count: battery cycle count
7816 * @manufacturer_ext: battery manufacturer string
7817 * @model_ext: battery model string
7818 * @serial_ext: battery serial number string
7819 * @type_ext: battery type string
7820 */
7821struct ec_response_battery_static_info_v1 {
7822 uint16_t design_capacity;
7823 uint16_t design_voltage;
7824 uint32_t cycle_count;
7825 char manufacturer_ext[12];
7826 char model_ext[12];
7827 char serial_ext[12];
7828 char type_ext[12];
7829} __ec_align4;
7830
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007831/**
7832 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
7833 *
7834 * Equivalent to struct ec_response_battery_static_info, but with strings
7835 * further lengthened (relative to v1) to accommodate the maximum string length
7836 * permitted by the Smart Battery Data Specification revision 1.1 and fields
7837 * renamed to better match that specification.
7838 *
7839 * @design_capacity: battery design capacity (in mAh)
7840 * @design_voltage: battery design voltage (in mV)
7841 * @cycle_count: battery cycle count
7842 * @manufacturer: battery manufacturer string
7843 * @device_name: battery model string
7844 * @serial: battery serial number string
7845 * @chemistry: battery type string
7846 */
7847struct ec_response_battery_static_info_v2 {
7848 uint16_t design_capacity;
7849 uint16_t design_voltage;
7850 uint32_t cycle_count;
7851 char manufacturer[32];
7852 char device_name[32];
7853 char serial[32];
7854 char chemistry[32];
7855} __ec_align4;
7856
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007857/*
7858 * Get battery dynamic information, i.e. information that is likely to change
7859 * every time it is read.
7860 */
7861#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7862
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007863/**
7864 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7865 * @index: Battery index.
7866 */
7867struct ec_params_battery_dynamic_info {
7868 uint8_t index;
7869} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007870
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007871/**
7872 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7873 * @actual_voltage: Battery voltage (mV)
7874 * @actual_current: Battery current (mA); negative=discharging
7875 * @remaining_capacity: Remaining capacity (mAh)
7876 * @full_capacity: Capacity (mAh, might change occasionally)
7877 * @flags: Flags, see EC_BATT_FLAG_*
7878 * @desired_voltage: Charging voltage desired by battery (mV)
7879 * @desired_current: Charging current desired by battery (mA)
7880 */
7881struct ec_response_battery_dynamic_info {
7882 int16_t actual_voltage;
7883 int16_t actual_current;
7884 int16_t remaining_capacity;
7885 int16_t full_capacity;
7886 int16_t flags;
7887 int16_t desired_voltage;
7888 int16_t desired_current;
7889} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007890
7891/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007892 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007893 */
7894#define EC_CMD_CHARGER_CONTROL 0x0602
7895
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007896/**
7897 * struct ec_params_charger_control - Charger control parameters
7898 * @max_current: Charger current (mA). Positive to allow base to draw up to
7899 * max_current and (possibly) charge battery, negative to request current
7900 * from base (OTG).
7901 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7902 * >= 0.
7903 * @allow_charging: Allow base battery charging (only makes sense if
7904 * max_current > 0).
7905 */
7906struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007907 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007908 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007909 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007910} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007911
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007912/* Get ACK from the USB-C SS muxes */
7913#define EC_CMD_USB_PD_MUX_ACK 0x0603
7914
7915struct ec_params_usb_pd_mux_ack {
7916 uint8_t port; /* USB-C port number */
7917} __ec_align1;
7918
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007919/* Get boot time */
7920#define EC_CMD_GET_BOOT_TIME 0x0604
7921
7922enum boot_time_param {
7923 ARAIL = 0,
7924 RSMRST,
7925 ESPIRST,
7926 PLTRST_LOW,
7927 PLTRST_HIGH,
7928 EC_CUR_TIME,
7929 RESET_CNT,
7930};
7931
7932struct ec_response_get_boot_time {
7933 uint64_t timestamp[RESET_CNT];
7934 uint16_t cnt;
7935} __ec_align4;
7936
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007937/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007938/*
7939 * Reserve a range of host commands for board-specific, experimental, or
7940 * special purpose features. These can be (re)used without updating this file.
7941 *
7942 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7943 * their EC commands for easier development, testing, debugging, and support.
7944 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007945 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7946 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7947 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007948 * In your experimental code, you may want to do something like this:
7949 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007950 * #define EC_CMD_MAGIC_FOO 0x0000
7951 * #define EC_CMD_MAGIC_BAR 0x0001
7952 * #define EC_CMD_MAGIC_HEY 0x0002
7953 *
7954 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7955 * EC_VER_MASK(0);
7956 *
7957 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7958 * EC_VER_MASK(0);
7959 *
7960 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7961 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007962 */
7963#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7964#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7965
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007966/*
7967 * Given the private host command offset, calculate the true private host
7968 * command value.
7969 */
7970#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7971 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7972
Duncan Laurie93e24442014-01-06 12:30:52 -08007973/*****************************************************************************/
7974/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007975 * Passthru commands
7976 *
7977 * Some platforms have sub-processors chained to each other. For example.
7978 *
7979 * AP <--> EC <--> PD MCU
7980 *
7981 * The top 2 bits of the command number are used to indicate which device the
7982 * command is intended for. Device 0 is always the device receiving the
7983 * command; other device mapping is board-specific.
7984 *
7985 * When a device receives a command to be passed to a sub-processor, it passes
7986 * it on with the device number set back to 0. This allows the sub-processor
7987 * to remain blissfully unaware of whether the command originated on the next
7988 * device up the chain, or was passed through from the AP.
7989 *
7990 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7991 * AP sends command 0x4002 to the EC
7992 * EC sends command 0x0002 to the PD MCU
7993 * EC forwards PD MCU response back to the AP
7994 */
7995
7996/* Offset and max command number for sub-device n */
7997#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7998#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7999
8000/*****************************************************************************/
8001/*
Duncan Laurie93e24442014-01-06 12:30:52 -08008002 * Deprecated constants. These constants have been renamed for clarity. The
8003 * meaning and size has not changed. Programs that use the old names should
8004 * switch to the new names soon, as the old names may not be carried forward
8005 * forever.
8006 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008007#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
8008#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
8009#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
Duncan Laurie93e24442014-01-06 12:30:52 -08008010
Caveh Jalali024ffe32023-01-30 14:35:19 -08008011#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008012
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008013#ifdef __cplusplus
8014}
8015#endif
8016
Caveh Jalali024ffe32023-01-30 14:35:19 -08008017#endif /* __CROS_EC_EC_COMMANDS_H */