blob: b66f9d387db029081b77147920713ce8ce83b9c0 [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));
Simon Glassd3870a22023-11-09 08:43:30 -0700696#ifdef CONFIG_EC_HOST_CMD
697/*
698 * Make sure Zephyre uses the same status codes.
699 */
700#include <zephyr/mgmt/ec_host_cmd/ec_host_cmd.h>
701
702BUILD_ASSERT((uint16_t)EC_RES_SUCCESS == (uint16_t)EC_HOST_CMD_SUCCESS);
703BUILD_ASSERT((uint16_t)EC_RES_INVALID_COMMAND ==
704 (uint16_t)EC_HOST_CMD_INVALID_COMMAND);
705BUILD_ASSERT((uint16_t)EC_RES_ERROR == (uint16_t)EC_HOST_CMD_ERROR);
706BUILD_ASSERT((uint16_t)EC_RES_INVALID_PARAM ==
707 (uint16_t)EC_HOST_CMD_INVALID_PARAM);
708BUILD_ASSERT((uint16_t)EC_RES_ACCESS_DENIED ==
709 (uint16_t)EC_HOST_CMD_ACCESS_DENIED);
710BUILD_ASSERT((uint16_t)EC_RES_INVALID_RESPONSE ==
711 (uint16_t)EC_HOST_CMD_INVALID_RESPONSE);
712BUILD_ASSERT((uint16_t)EC_RES_INVALID_VERSION ==
713 (uint16_t)EC_HOST_CMD_INVALID_VERSION);
714BUILD_ASSERT((uint16_t)EC_RES_INVALID_CHECKSUM ==
715 (uint16_t)EC_HOST_CMD_INVALID_CHECKSUM);
716BUILD_ASSERT((uint16_t)EC_RES_IN_PROGRESS == (uint16_t)EC_HOST_CMD_IN_PROGRESS);
717BUILD_ASSERT((uint16_t)EC_RES_UNAVAILABLE == (uint16_t)EC_HOST_CMD_UNAVAILABLE);
718BUILD_ASSERT((uint16_t)EC_RES_TIMEOUT == (uint16_t)EC_HOST_CMD_TIMEOUT);
719BUILD_ASSERT((uint16_t)EC_RES_OVERFLOW == (uint16_t)EC_HOST_CMD_OVERFLOW);
720BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER ==
721 (uint16_t)EC_HOST_CMD_INVALID_HEADER);
722BUILD_ASSERT((uint16_t)EC_RES_REQUEST_TRUNCATED ==
723 (uint16_t)EC_HOST_CMD_REQUEST_TRUNCATED);
724BUILD_ASSERT((uint16_t)EC_RES_RESPONSE_TOO_BIG ==
725 (uint16_t)EC_HOST_CMD_RESPONSE_TOO_BIG);
726BUILD_ASSERT((uint16_t)EC_RES_BUS_ERROR == (uint16_t)EC_HOST_CMD_BUS_ERROR);
727BUILD_ASSERT((uint16_t)EC_RES_BUSY == (uint16_t)EC_HOST_CMD_BUSY);
728BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_VERSION ==
729 (uint16_t)EC_HOST_CMD_INVALID_HEADER_VERSION);
730BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_CRC ==
731 (uint16_t)EC_HOST_CMD_INVALID_HEADER_CRC);
732BUILD_ASSERT((uint16_t)EC_RES_INVALID_DATA_CRC ==
733 (uint16_t)EC_HOST_CMD_INVALID_DATA_CRC);
734BUILD_ASSERT((uint16_t)EC_RES_DUP_UNAVAILABLE ==
735 (uint16_t)EC_HOST_CMD_DUP_UNAVAILABLE);
736BUILD_ASSERT((uint16_t)EC_RES_MAX == (uint16_t)EC_HOST_CMD_MAX);
737
738#endif
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800739
740/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600741 * Host event codes. ACPI query EC command uses code 0 to mean "no event
742 * pending". We explicitly specify each value in the enum listing so they won't
743 * change if we delete/insert an item or rearrange the list (it needs to be
744 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800745 */
746enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600747 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800748 EC_HOST_EVENT_LID_CLOSED = 1,
749 EC_HOST_EVENT_LID_OPEN = 2,
750 EC_HOST_EVENT_POWER_BUTTON = 3,
751 EC_HOST_EVENT_AC_CONNECTED = 4,
752 EC_HOST_EVENT_AC_DISCONNECTED = 5,
753 EC_HOST_EVENT_BATTERY_LOW = 6,
754 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
755 EC_HOST_EVENT_BATTERY = 8,
756 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700757 /* Event generated by a device attached to the EC */
758 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800759 EC_HOST_EVENT_THERMAL = 11,
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800760 /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */
761 EC_HOST_EVENT_GPU = 12,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800762 EC_HOST_EVENT_KEY_PRESSED = 13,
763 /*
764 * EC has finished initializing the host interface. The host can check
765 * for this event following sending a EC_CMD_REBOOT_EC command to
766 * determine when the EC is ready to accept subsequent commands.
767 */
768 EC_HOST_EVENT_INTERFACE_READY = 14,
769 /* Keyboard recovery combo has been pressed */
770 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
771
772 /* Shutdown due to thermal overload */
773 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
774 /* Shutdown due to battery level too low */
775 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
776
Duncan Laurie93e24442014-01-06 12:30:52 -0800777 /* Suggest that the AP throttle itself */
778 EC_HOST_EVENT_THROTTLE_START = 18,
779 /* Suggest that the AP resume normal speed */
780 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700781
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800782 /* Hang detect logic detected a hang and host event timeout expired */
783 EC_HOST_EVENT_HANG_DETECT = 20,
784 /* Hang detect logic detected a hang and warm rebooted the AP */
785 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700786
787 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700788 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800789
Duncan Lauried8401182014-09-29 08:32:19 -0700790 /* Battery Status flags have changed */
791 EC_HOST_EVENT_BATTERY_STATUS = 23,
792
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700793 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800794 EC_HOST_EVENT_PANIC = 24,
795
Furquan Shaikh066cc852015-06-20 15:53:03 -0700796 /* Keyboard fastboot combo has been pressed */
797 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
798
Gwendal Grignou880b4582016-06-20 08:49:25 -0700799 /* EC RTC event occurred */
800 EC_HOST_EVENT_RTC = 26,
801
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700802 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700803 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700804
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700805 /* EC desires to change state of host-controlled USB mux */
806 EC_HOST_EVENT_USB_MUX = 28,
807
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800808 /*
809 * The device has changed "modes". This can be one of the following:
810 *
811 * - TABLET/LAPTOP mode
812 * - detachable base attach/detach event
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800813 * - on body/off body transition event
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800814 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400815 EC_HOST_EVENT_MODE_CHANGE = 29,
816
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700817 /* Keyboard recovery combo with hardware reinitialization */
818 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
819
Jett Rinkba2edaf2020-01-14 11:49:06 -0700820 /* WoV */
821 EC_HOST_EVENT_WOV = 31,
822
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700823 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800824 * The high bit of the event mask is not used as a host event code. If
825 * it reads back as set, then the entire event mask should be
826 * considered invalid by the host. This can happen when reading the
827 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
828 * not initialized on the EC, or improperly configured on the host.
829 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800830 EC_HOST_EVENT_INVALID = 32,
Tim Van Pattencab60602023-02-24 12:27:04 -0700831
832 /* Body detect (lap/desk) change event */
833 EC_HOST_EVENT_BODY_DETECT_CHANGE = 33,
834
835 /*
836 * Only 64 host events are supported. This enum uses 1-based counting so
837 * it can skip 0 (NONE), so the last legal host event number is 64.
838 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800839};
Tim Van Pattencab60602023-02-24 12:27:04 -0700840
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800841/* Host event mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800842#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800843
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800844/* clang-format off */
845#define HOST_EVENT_TEXT \
846 { \
847 [EC_HOST_EVENT_NONE] = "NONE", \
848 [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \
849 [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \
850 [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \
851 [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \
852 [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \
853 [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \
854 [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \
855 [EC_HOST_EVENT_BATTERY] = "BATTERY", \
856 [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \
857 [EC_HOST_EVENT_DEVICE] = "DEVICE", \
858 [EC_HOST_EVENT_THERMAL] = "THERMAL", \
859 [EC_HOST_EVENT_GPU] = "GPU", \
860 [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \
861 [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \
862 [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \
863 [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \
864 [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \
865 [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \
866 [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \
867 [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \
868 [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \
869 [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \
870 [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \
871 [EC_HOST_EVENT_PANIC] = "PANIC", \
872 [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \
873 [EC_HOST_EVENT_RTC] = "RTC", \
874 [EC_HOST_EVENT_MKBP] = "MKBP", \
875 [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \
876 [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \
877 [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \
878 "KEYBOARD_RECOVERY_HW_REINIT", \
879 [EC_HOST_EVENT_WOV] = "WOV", \
880 [EC_HOST_EVENT_INVALID] = "INVALID", \
Tim Van Pattencab60602023-02-24 12:27:04 -0700881 [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800882 }
883/* clang-format on */
884
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800885/**
886 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
887 * @flags: The host argument flags.
888 * @command_version: Command version.
889 * @data_size: The length of data.
890 * @checksum: Checksum; sum of command + flags + command_version + data_size +
891 * all params/response data bytes.
892 */
893struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800894 uint8_t flags;
895 uint8_t command_version;
896 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800897 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800898} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800899
900/* Flags for ec_lpc_host_args.flags */
901/*
902 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
903 * params.
904 *
905 * If EC gets a command and this flag is not set, this is an old-style command.
906 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
907 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700908 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800909 */
910#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
911/*
912 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
913 *
914 * If EC responds to a command and this flag is not set, this is an old-style
915 * response. Command version is 0 and response data from EC is at
916 * EC_LPC_ADDR_OLD_PARAM with unknown length.
917 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800918#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800919
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800920/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800921/*
922 * Byte codes returned by EC over SPI interface.
923 *
924 * These can be used by the AP to debug the EC interface, and to determine
925 * when the EC is not in a state where it will ever get around to responding
926 * to the AP.
927 *
928 * Example of sequence of bytes read from EC for a current good transfer:
929 * 1. - - AP asserts chip select (CS#)
930 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
931 * 3. - - EC starts handling CS# interrupt
932 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
933 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
934 * bytes looking for EC_SPI_FRAME_START
935 * 6. - - EC finishes processing and sets up response
936 * 7. EC_SPI_FRAME_START - AP reads frame byte
937 * 8. (response packet) - AP reads response packet
938 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
939 * 10 - - AP deasserts chip select
940 * 11 - - EC processes CS# interrupt and sets up DMA for
941 * next request
942 *
943 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
944 * the following byte values:
945 * EC_SPI_OLD_READY
946 * EC_SPI_RX_READY
947 * EC_SPI_RECEIVING
948 * EC_SPI_PROCESSING
949 *
950 * Then the EC found an error in the request, or was not ready for the request
951 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
952 * because the EC is unable to tell when the AP is done sending its request.
953 */
954
955/*
956 * Framing byte which precedes a response packet from the EC. After sending a
957 * request, the AP will clock in bytes until it sees the framing byte, then
958 * clock in the response packet.
959 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800960#define EC_SPI_FRAME_START 0xec
Duncan Laurie93e24442014-01-06 12:30:52 -0800961
962/*
963 * Padding bytes which are clocked out after the end of a response packet.
964 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800965#define EC_SPI_PAST_END 0xed
Duncan Laurie93e24442014-01-06 12:30:52 -0800966
967/*
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800968 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
Duncan Laurie93e24442014-01-06 12:30:52 -0800969 * that the AP will send a valid packet header (starting with
970 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800971 *
972 * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
973 * CS goes low. This macro has the Most Significant Bit set to zero,
974 * so SDO will not be driven high when CS goes low.
Duncan Laurie93e24442014-01-06 12:30:52 -0800975 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800976#define EC_SPI_RX_READY 0x78
Duncan Laurie93e24442014-01-06 12:30:52 -0800977
978/*
979 * EC has started receiving the request from the AP, but hasn't started
980 * processing it yet.
981 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800982#define EC_SPI_RECEIVING 0xf9
Duncan Laurie93e24442014-01-06 12:30:52 -0800983
984/* EC has received the entire request from the AP and is processing it. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800985#define EC_SPI_PROCESSING 0xfa
Duncan Laurie93e24442014-01-06 12:30:52 -0800986
987/*
988 * EC received bad data from the AP, such as a packet header with an invalid
989 * length. EC will ignore all data until chip select deasserts.
990 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800991#define EC_SPI_RX_BAD_DATA 0xfb
Duncan Laurie93e24442014-01-06 12:30:52 -0800992
993/*
994 * EC received data from the AP before it was ready. That is, the AP asserted
995 * chip select and started clocking data before the EC was ready to receive it.
996 * EC will ignore all data until chip select deasserts.
997 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800998#define EC_SPI_NOT_READY 0xfc
Duncan Laurie93e24442014-01-06 12:30:52 -0800999
1000/*
1001 * EC was ready to receive a request from the AP. EC has treated the byte sent
1002 * by the AP as part of a request packet, or (for old-style ECs) is processing
1003 * a fully received packet but is not ready to respond yet.
1004 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001005#define EC_SPI_OLD_READY 0xfd
Duncan Laurie93e24442014-01-06 12:30:52 -08001006
1007/*****************************************************************************/
1008
1009/*
1010 * Protocol version 2 for I2C and SPI send a request this way:
1011 *
1012 * 0 EC_CMD_VERSION0 + (command version)
1013 * 1 Command number
1014 * 2 Length of params = N
1015 * 3..N+2 Params, if any
1016 * N+3 8-bit checksum of bytes 0..N+2
1017 *
1018 * The corresponding response is:
1019 *
1020 * 0 Result code (EC_RES_*)
1021 * 1 Length of params = M
1022 * 2..M+1 Params, if any
1023 * M+2 8-bit checksum of bytes 0..M+1
1024 */
1025#define EC_PROTO2_REQUEST_HEADER_BYTES 3
1026#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08001027#define EC_PROTO2_REQUEST_OVERHEAD \
1028 (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -08001029
1030#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
1031#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08001032#define EC_PROTO2_RESPONSE_OVERHEAD \
1033 (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -08001034
1035/* Parameter length was limited by the LPC interface */
1036#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
1037
1038/* Maximum request and response packet sizes for protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001039#define EC_PROTO2_MAX_REQUEST_SIZE \
1040 (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
1041#define EC_PROTO2_MAX_RESPONSE_SIZE \
1042 (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
Duncan Laurie93e24442014-01-06 12:30:52 -08001043
1044/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001045
1046/*
1047 * Value written to legacy command port / prefix byte to indicate protocol
1048 * 3+ structs are being used. Usage is bus-dependent.
1049 */
1050#define EC_COMMAND_PROTOCOL_3 0xda
1051
1052#define EC_HOST_REQUEST_VERSION 3
1053
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001054/**
1055 * struct ec_host_request - Version 3 request from host.
1056 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
1057 * receives a header with a version it doesn't know how to
1058 * parse.
1059 * @checksum: Checksum of request and data; sum of all bytes including checksum
1060 * should total to 0.
1061 * @command: Command to send (EC_CMD_...)
1062 * @command_version: Command version.
1063 * @reserved: Unused byte in current protocol version; set to 0.
1064 * @data_len: Length of data which follows this header.
1065 */
1066struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001067 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001068 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001069 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001070 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001071 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001072 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001073} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001074
1075#define EC_HOST_RESPONSE_VERSION 3
1076
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001077/**
1078 * struct ec_host_response - Version 3 response from EC.
1079 * @struct_version: Struct version (=3).
1080 * @checksum: Checksum of response and data; sum of all bytes including
1081 * checksum should total to 0.
1082 * @result: EC's response to the command (separate from communication failure)
1083 * @data_len: Length of data which follows this header.
1084 * @reserved: Unused bytes in current protocol version; set to 0.
1085 */
1086struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001087 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001088 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001089 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001090 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001091 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001092} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001093
1094/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001095
1096/*
1097 * Host command protocol V4.
1098 *
1099 * Packets always start with a request or response header. They are followed
1100 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +01001101 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001102 * polynomial.
1103 *
1104 * Host algorithm when sending a request q:
1105 *
1106 * 101) tries_left=(some value, e.g. 3);
1107 * 102) q.seq_num++
1108 * 103) q.seq_dup=0
1109 * 104) Calculate q.header_crc.
1110 * 105) Send request q to EC.
1111 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
1112 *
1113 * 201) If r.struct_version != 4, go to 301.
1114 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
1115 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
1116 * 204) If r.seq_num != q.seq_num, go to 301.
1117 * 205) If r.seq_dup == q.seq_dup, return success.
1118 * 207) If r.seq_dup == 1, go to 301.
1119 * 208) Return error.
1120 *
1121 * 301) If --tries_left <= 0, return error.
1122 * 302) If q.seq_dup == 1, go to 105.
1123 * 303) q.seq_dup = 1
1124 * 304) Go to 104.
1125 *
1126 * EC algorithm when receiving a request q.
1127 * EC has response buffer r, error buffer e.
1128 *
1129 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
1130 * and go to 301
1131 * 102) If q.header_crc mismatches calculated CRC, set e.result =
1132 * EC_RES_INVALID_HEADER_CRC and go to 301
1133 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
1134 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
1135 * and go to 301.
1136 * 104) If q.seq_dup == 0, go to 201.
1137 * 105) If q.seq_num != r.seq_num, go to 201.
1138 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
1139 *
1140 * 201) Process request q into response r.
1141 * 202) r.seq_num = q.seq_num
1142 * 203) r.seq_dup = q.seq_dup
1143 * 204) Calculate r.header_crc
1144 * 205) If r.data_len > 0 and data is no longer available, set e.result =
1145 * EC_RES_DUP_UNAVAILABLE and go to 301.
1146 * 206) Send response r.
1147 *
1148 * 301) e.seq_num = q.seq_num
1149 * 302) e.seq_dup = q.seq_dup
1150 * 303) Calculate e.header_crc.
1151 * 304) Send error response e.
1152 */
1153
1154/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001155struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001156 /*
1157 * bits 0-3: struct_version: Structure version (=4)
1158 * bit 4: is_response: Is response (=0)
1159 * bits 5-6: seq_num: Sequence number
1160 * bit 7: seq_dup: Sequence duplicate flag
1161 */
1162 uint8_t fields0;
1163
1164 /*
1165 * bits 0-4: command_version: Command version
1166 * bits 5-6: Reserved (set 0, ignore on read)
1167 * bit 7: data_crc_present: Is data CRC present after data
1168 */
1169 uint8_t fields1;
1170
1171 /* Command code (EC_CMD_*) */
1172 uint16_t command;
1173
1174 /* Length of data which follows this header (not including data CRC) */
1175 uint16_t data_len;
1176
1177 /* Reserved (set 0, ignore on read) */
1178 uint8_t reserved;
1179
1180 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1181 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001182} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001183
1184/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001185struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001186 /*
1187 * bits 0-3: struct_version: Structure version (=4)
1188 * bit 4: is_response: Is response (=1)
1189 * bits 5-6: seq_num: Sequence number
1190 * bit 7: seq_dup: Sequence duplicate flag
1191 */
1192 uint8_t fields0;
1193
1194 /*
1195 * bits 0-6: Reserved (set 0, ignore on read)
1196 * bit 7: data_crc_present: Is data CRC present after data
1197 */
1198 uint8_t fields1;
1199
1200 /* Result code (EC_RES_*) */
1201 uint16_t result;
1202
1203 /* Length of data which follows this header (not including data CRC) */
1204 uint16_t data_len;
1205
1206 /* Reserved (set 0, ignore on read) */
1207 uint8_t reserved;
1208
1209 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1210 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001211} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001212
1213/* Fields in fields0 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001214#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1215#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1216#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1217#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1218#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001219
1220/* Fields in fields1 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001221#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1222#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001223
1224/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001225/*
1226 * Notes on commands:
1227 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001228 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001229 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001230 * specified, the command does not input or output data, respectively.
1231 * Parameter/response length is implicit in the structs. Some underlying
1232 * communication protocols (I2C, SPI) may add length or checksum headers, but
1233 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001234 *
1235 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1236 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001237 */
1238
1239/*****************************************************************************/
1240/* General / test commands */
1241
1242/*
1243 * Get protocol version, used to deal with non-backward compatible protocol
1244 * changes.
1245 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001246#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001247
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001248/**
1249 * struct ec_response_proto_version - Response to the proto version command.
1250 * @version: The protocol version.
1251 */
1252struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001253 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001254} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001255
1256/*
1257 * Hello. This is a simple command to test the EC is responsive to
1258 * commands.
1259 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001260#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001261
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001262/**
1263 * struct ec_params_hello - Parameters to the hello command.
1264 * @in_data: Pass anything here.
1265 */
1266struct ec_params_hello {
1267 uint32_t in_data;
1268} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001269
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001270/**
1271 * struct ec_response_hello - Response to the hello command.
1272 * @out_data: Output will be in_data + 0x01020304.
1273 */
1274struct ec_response_hello {
1275 uint32_t out_data;
1276} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001277
1278/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001279#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001280
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001281enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001282 EC_IMAGE_UNKNOWN = 0,
1283 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001284 EC_IMAGE_RW,
1285 EC_IMAGE_RW_A = EC_IMAGE_RW,
1286 EC_IMAGE_RO_B,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001287 EC_IMAGE_RW_B,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001288};
1289
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001290/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001291 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001292 * @version_string_ro: Null-terminated RO firmware version string.
1293 * @version_string_rw: Null-terminated RW firmware version string.
1294 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001295 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001296 */
1297struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001298 char version_string_ro[32];
1299 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001300 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001301 uint32_t current_image;
1302} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001303
Rob Barnes5ab14662021-09-17 10:24:45 -06001304/**
1305 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1306 *
1307 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1308 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1309 * and adds one additional field (cros_fwid_rw).
1310 *
1311 * @version_string_ro: Null-terminated RO firmware version string.
1312 * @version_string_rw: Null-terminated RW firmware version string.
1313 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1314 * @current_image: One of ec_image.
1315 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1316 */
1317struct ec_response_get_version_v1 {
1318 char version_string_ro[32];
1319 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001320 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
Rob Barnes5ab14662021-09-17 10:24:45 -06001321 uint32_t current_image;
Caveh Jalali024ffe32023-01-30 14:35:19 -08001322 char cros_fwid_rw[32]; /* Added in version 1 */
Rob Barnes5ab14662021-09-17 10:24:45 -06001323} __ec_align4;
1324
Caveh Jalali839ada12022-10-31 23:16:48 -07001325/* Read test - OBSOLETE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001326#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001327
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001328/*
1329 * Get build information
1330 *
1331 * Response is null-terminated string.
1332 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001333#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001334
1335/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001336#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001337
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001338/**
1339 * struct ec_response_get_chip_info - Response to the get chip info command.
1340 * @vendor: Null-terminated string for chip vendor.
1341 * @name: Null-terminated string for chip name.
1342 * @revision: Null-terminated string for chip mask version.
1343 */
1344struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001345 char vendor[32];
1346 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001347 char revision[32];
1348} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001349
1350/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001351#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001352
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001353/**
1354 * struct ec_response_board_version - Response to the board version command.
1355 * @board_version: A monotonously incrementing number.
1356 */
1357struct ec_response_board_version {
1358 uint16_t board_version;
1359} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001360
1361/*
1362 * Read memory-mapped data.
1363 *
1364 * This is an alternate interface to memory-mapped data for bus protocols
1365 * which don't support direct-mapped memory - I2C, SPI, etc.
1366 *
1367 * Response is params.size bytes of data.
1368 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001369#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001370
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001371/**
1372 * struct ec_params_read_memmap - Parameters for the read memory map command.
1373 * @offset: Offset in memmap (EC_MEMMAP_*).
1374 * @size: Size to read in bytes.
1375 */
1376struct ec_params_read_memmap {
1377 uint8_t offset;
1378 uint8_t size;
1379} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001380
1381/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001382#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001383
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001384/**
1385 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1386 * @cmd: Command to check.
1387 */
1388struct ec_params_get_cmd_versions {
1389 uint8_t cmd;
1390} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001391
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001392/**
1393 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1394 * versions (v1)
1395 * @cmd: Command to check.
1396 */
1397struct ec_params_get_cmd_versions_v1 {
1398 uint16_t cmd;
1399} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001400
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001401/**
1402 * struct ec_response_get_cmd_version - Response to the get command versions.
1403 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1404 * a desired version.
1405 */
1406struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001407 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001408} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001409
Duncan Laurie433432b2013-06-03 10:38:22 -07001410/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001411 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001412 * on lpc since it has its own out-of-band busy indicator.
1413 *
1414 * lpc must read the status from the command register. Attempting this on
1415 * lpc will overwrite the args/parameter space and corrupt its data.
1416 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001417#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001418
1419/* Avoid using ec_status which is for return values */
1420enum ec_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001421 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001422};
1423
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001424/**
1425 * struct ec_response_get_comms_status - Response to the get comms status
1426 * command.
1427 * @flags: Mask of enum ec_comms_status.
1428 */
1429struct ec_response_get_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001430 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001431} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001432
Duncan Laurie93e24442014-01-06 12:30:52 -08001433/* Fake a variety of responses, purely for testing purposes. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001434#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001435
1436/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001437struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001438 uint32_t ec_result;
1439 uint32_t ret_len;
1440 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001441} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001442
1443/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001444struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001445 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001446} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001447
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001448/* Get protocol information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001449#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001450
1451/* Flags for ec_response_get_protocol_info.flags */
1452/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001453#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001454
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001455/**
1456 * struct ec_response_get_protocol_info - Response to the get protocol info.
1457 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1458 * version n).
1459 * @max_request_packet_size: Maximum request packet size in bytes.
1460 * @max_response_packet_size: Maximum response packet size in bytes.
1461 * @flags: see EC_PROTOCOL_INFO_*
1462 */
1463struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001464 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001465 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001466 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001467 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001468 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001469} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001470
Duncan Laurie93e24442014-01-06 12:30:52 -08001471/*****************************************************************************/
1472/* Get/Set miscellaneous values */
1473
1474/* The upper byte of .flags tells what to do (nothing means "get") */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001475#define EC_GSV_SET 0x80000000
Duncan Laurie93e24442014-01-06 12:30:52 -08001476
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001477/*
1478 * The lower three bytes of .flags identifies the parameter, if that has
1479 * meaning for an individual command.
1480 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001481#define EC_GSV_PARAM_MASK 0x00ffffff
1482
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001483struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001484 uint32_t flags;
1485 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001486} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001487
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001488struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001489 uint32_t flags;
1490 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001491} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001492
Duncan Laurieeb316852015-12-01 18:51:18 -08001493/* More than one command can use these structs to get/set parameters. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001494#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001495
Duncan Laurieeb316852015-12-01 18:51:18 -08001496/*****************************************************************************/
1497/* List the features supported by the firmware */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001498#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001499
1500/* Supported features */
1501enum ec_feature_code {
1502 /*
1503 * This image contains a limited set of features. Another image
1504 * in RW partition may support more features.
1505 */
1506 EC_FEATURE_LIMITED = 0,
1507 /*
1508 * Commands for probing/reading/writing/erasing the flash in the
1509 * EC are present.
1510 */
1511 EC_FEATURE_FLASH = 1,
1512 /*
1513 * Can control the fan speed directly.
1514 */
1515 EC_FEATURE_PWM_FAN = 2,
1516 /*
1517 * Can control the intensity of the keyboard backlight.
1518 */
1519 EC_FEATURE_PWM_KEYB = 3,
1520 /*
1521 * Support Google lightbar, introduced on Pixel.
1522 */
1523 EC_FEATURE_LIGHTBAR = 4,
1524 /* Control of LEDs */
1525 EC_FEATURE_LED = 5,
1526 /* Exposes an interface to control gyro and sensors.
1527 * The host goes through the EC to access these sensors.
1528 * In addition, the EC may provide composite sensors, like lid angle.
1529 */
1530 EC_FEATURE_MOTION_SENSE = 6,
1531 /* The keyboard is controlled by the EC */
1532 EC_FEATURE_KEYB = 7,
1533 /* The AP can use part of the EC flash as persistent storage. */
1534 EC_FEATURE_PSTORE = 8,
1535 /* The EC monitors BIOS port 80h, and can return POST codes. */
1536 EC_FEATURE_PORT80 = 9,
1537 /*
1538 * Thermal management: include TMP specific commands.
1539 * Higher level than direct fan control.
1540 */
1541 EC_FEATURE_THERMAL = 10,
1542 /* Can switch the screen backlight on/off */
1543 EC_FEATURE_BKLIGHT_SWITCH = 11,
1544 /* Can switch the wifi module on/off */
1545 EC_FEATURE_WIFI_SWITCH = 12,
1546 /* Monitor host events, through for example SMI or SCI */
1547 EC_FEATURE_HOST_EVENTS = 13,
1548 /* The EC exposes GPIO commands to control/monitor connected devices. */
1549 EC_FEATURE_GPIO = 14,
1550 /* The EC can send i2c messages to downstream devices. */
1551 EC_FEATURE_I2C = 15,
1552 /* Command to control charger are included */
1553 EC_FEATURE_CHARGER = 16,
1554 /* Simple battery support. */
1555 EC_FEATURE_BATTERY = 17,
1556 /*
1557 * Support Smart battery protocol
1558 * (Common Smart Battery System Interface Specification)
1559 */
1560 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001561 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001562 EC_FEATURE_HANG_DETECT = 19,
1563 /* Report power information, for pit only */
1564 EC_FEATURE_PMU = 20,
1565 /* Another Cros EC device is present downstream of this one */
1566 EC_FEATURE_SUB_MCU = 21,
1567 /* Support USB Power delivery (PD) commands */
1568 EC_FEATURE_USB_PD = 22,
1569 /* Control USB multiplexer, for audio through USB port for instance. */
1570 EC_FEATURE_USB_MUX = 23,
1571 /* Motion Sensor code has an internal software FIFO */
1572 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1573 /* Support temporary secure vstore */
1574 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001575 /* EC decides on USB-C SS mux state, muxes configured by host */
1576 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1577 /* EC has RTC feature that can be controlled by host commands */
1578 EC_FEATURE_RTC = 27,
1579 /* The MCU exposes a Fingerprint sensor */
1580 EC_FEATURE_FINGERPRINT = 28,
1581 /* The MCU exposes a Touchpad */
1582 EC_FEATURE_TOUCHPAD = 29,
1583 /* The MCU has RWSIG task enabled */
1584 EC_FEATURE_RWSIG = 30,
1585 /* EC has device events support */
1586 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001587 /* EC supports the unified wake masks for LPC/eSPI systems */
1588 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001589 /* EC supports 64-bit host events */
1590 EC_FEATURE_HOST_EVENT64 = 33,
1591 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1592 EC_FEATURE_EXEC_IN_RAM = 34,
1593 /* EC supports CEC commands */
1594 EC_FEATURE_CEC = 35,
1595 /* EC supports tight sensor timestamping. */
1596 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001597 /*
1598 * EC supports tablet mode detection aligned to Chrome and allows
1599 * setting of threshold by host command using
1600 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1601 */
1602 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001603 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001604 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001605 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1606 * be sent to RO to be precise.
1607 */
1608 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001609 /* The MCU is a System Companion Processor (SCP). */
1610 EC_FEATURE_SCP = 39,
1611 /* The MCU is an Integrated Sensor Hub */
1612 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001613 /* New TCPMv2 TYPEC_ prefaced commands supported */
1614 EC_FEATURE_TYPEC_CMD = 41,
1615 /*
1616 * The EC will wait for direction from the AP to enter Type-C alternate
1617 * modes or USB4.
1618 */
1619 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1620 /*
1621 * The EC will wait for an acknowledge from the AP after setting the
1622 * mux.
1623 */
1624 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001625 /*
1626 * The EC supports entering and residing in S4.
1627 */
1628 EC_FEATURE_S4_RESIDENCY = 44,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001629 /*
1630 * The EC supports the AP directing mux sets for the board.
1631 */
1632 EC_FEATURE_TYPEC_AP_MUX_SET = 45,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001633 /*
1634 * The EC supports the AP composing VDMs for us to send.
1635 */
1636 EC_FEATURE_TYPEC_AP_VDM_SEND = 46,
Simon Glassd3870a22023-11-09 08:43:30 -07001637 /*
1638 * The EC supports system safe mode panic recovery.
1639 */
1640 EC_FEATURE_SYSTEM_SAFE_MODE = 47,
1641 /*
1642 * The EC will reboot on runtime assertion failures.
1643 */
1644 EC_FEATURE_ASSERT_REBOOTS = 48,
1645 /*
1646 * The EC image is built with tokenized logging enabled.
1647 */
1648 EC_FEATURE_TOKENIZED_LOGGING = 49,
1649 /*
1650 * The EC supports triggering an STB dump.
1651 */
1652 EC_FEATURE_AMD_STB_DUMP = 50,
1653 /*
1654 * The EC supports memory dump commands.
1655 */
1656 EC_FEATURE_MEMORY_DUMP = 51,
1657 /*
1658 * The EC supports DP2.1 capability
1659 */
1660 EC_FEATURE_TYPEC_DP2_1 = 52,
Duncan Laurieeb316852015-12-01 18:51:18 -08001661};
1662
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001663#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1664#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1665
1666struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001667 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001668} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001669
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001670/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001671/* Get the board's SKU ID from EC */
1672#define EC_CMD_GET_SKU_ID 0x000E
1673
Kevin Chiue2bb0592017-09-12 09:13:41 +08001674/* Set SKU ID from AP */
1675#define EC_CMD_SET_SKU_ID 0x000F
1676
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001677struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001678 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001679} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001680
1681/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001682/* Flash commands */
1683
1684/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001685#define EC_CMD_FLASH_INFO 0x0010
1686#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001687
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001688/**
1689 * struct ec_response_flash_info - Response to the flash info command.
1690 * @flash_size: Usable flash size in bytes.
1691 * @write_block_size: Write block size. Write offset and size must be a
1692 * multiple of this.
1693 * @erase_block_size: Erase block size. Erase offset and size must be a
1694 * multiple of this.
1695 * @protect_block_size: Protection block size. Protection offset and size
1696 * must be a multiple of this.
1697 *
1698 * Version 0 returns these fields.
1699 */
1700struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001701 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001702 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001703 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001704 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001705} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001706
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001707/*
1708 * Flags for version 1+ flash info command
1709 * EC flash erases bits to 0 instead of 1.
1710 */
1711#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001712
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001713/*
1714 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001715 * be necessary on a chip where write/erase can be corrupted by other board
1716 * activity, or where the chip needs to enable some sort of programming voltage,
1717 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001718 * chip functionality.
1719 */
1720#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001721
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001722/**
1723 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1724 * @flash_size: Usable flash size in bytes.
1725 * @write_block_size: Write block size. Write offset and size must be a
1726 * multiple of this.
1727 * @erase_block_size: Erase block size. Erase offset and size must be a
1728 * multiple of this.
1729 * @protect_block_size: Protection block size. Protection offset and size
1730 * must be a multiple of this.
1731 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1732 * size is exactly this and offset is a multiple of this.
1733 * For example, an EC may have a write buffer which can do
1734 * half-page operations if data is aligned, and a slower
1735 * word-at-a-time write mode.
1736 * @flags: Flags; see EC_FLASH_INFO_*
1737 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001738 * Version 1 returns the same initial fields as version 0, with additional
1739 * fields following.
1740 *
1741 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001742 * if they did we'd define the version 0 structure as a sub-structure of this
1743 * one.
1744 *
1745 * Version 2 supports flash banks of different sizes:
1746 * The caller specified the number of banks it has preallocated
1747 * (num_banks_desc)
1748 * The EC returns the number of banks describing the flash memory.
1749 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001750 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001751struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001752 /* Version 0 fields; see above for description */
1753 uint32_t flash_size;
1754 uint32_t write_block_size;
1755 uint32_t erase_block_size;
1756 uint32_t protect_block_size;
1757
1758 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001759 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001760 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001761} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001762
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001763struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001764 /* Number of banks to describe */
1765 uint16_t num_banks_desc;
1766 /* Reserved; set 0; ignore on read */
1767 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001768} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001769
1770struct ec_flash_bank {
1771 /* Number of sector is in this bank. */
1772 uint16_t count;
1773 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1774 uint8_t size_exp;
1775 /* Minimal write size for the sectors in this bank */
1776 uint8_t write_size_exp;
1777 /* Erase size for the sectors in this bank */
1778 uint8_t erase_size_exp;
1779 /* Size for write protection, usually identical to erase size. */
1780 uint8_t protect_size_exp;
1781 /* Reserved; set 0; ignore on read */
1782 uint8_t reserved[2];
1783};
1784
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001785struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001786 /* Total flash in the EC. */
1787 uint32_t flash_size;
1788 /* Flags; see EC_FLASH_INFO_* */
1789 uint32_t flags;
1790 /* Maximum size to use to send data to write to the EC. */
1791 uint32_t write_ideal_size;
1792 /* Number of banks present in the EC. */
1793 uint16_t num_banks_total;
1794 /* Number of banks described in banks array. */
1795 uint16_t num_banks_desc;
1796 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001797} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001798
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001799/*
1800 * Read flash
1801 *
1802 * Response is params.size bytes of data.
1803 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001804#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001805
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001806/**
1807 * struct ec_params_flash_read - Parameters for the flash read command.
1808 * @offset: Byte offset to read.
1809 * @size: Size to read in bytes.
1810 */
1811struct ec_params_flash_read {
1812 uint32_t offset;
1813 uint32_t size;
1814} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001815
1816/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001817#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001818#define EC_VER_FLASH_WRITE 1
1819
1820/* Version 0 of the flash command supported only 64 bytes of data */
1821#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001822
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001823/**
1824 * struct ec_params_flash_write - Parameters for the flash write command.
1825 * @offset: Byte offset to write.
1826 * @size: Size to write in bytes.
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001827 * @data: Data to write.
1828 * @data.words32: uint32_t data to write.
1829 * @data.bytes: uint8_t data to write.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001830 */
1831struct ec_params_flash_write {
1832 uint32_t offset;
1833 uint32_t size;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001834 /* Followed by data to write. This union allows accessing an
1835 * underlying buffer as uint32s or uint8s for convenience.
1836 */
1837 union {
1838 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1839 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1840 } data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001841} __ec_align4;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001842BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001843
1844/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001845#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001846
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001847/**
1848 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1849 * @offset: Byte offset to erase.
1850 * @size: Size to erase in bytes.
1851 */
1852struct ec_params_flash_erase {
1853 uint32_t offset;
1854 uint32_t size;
1855} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001856
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001857/*
1858 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001859 * subcommands can returns:
1860 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1861 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1862 * EC_RES_ERROR : other errors.
1863 * EC_RES_BUSY : an existing erase operation is in progress.
1864 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1865 *
1866 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1867 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1868 * the proper result.
1869 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1870 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1871 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1872 * permitted while erasing. (For instance, STM32F4).
1873 */
1874enum ec_flash_erase_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001875 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1876 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1877 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001878};
1879
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001880/**
1881 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1882 * @cmd: One of ec_flash_erase_cmd.
1883 * @reserved: Pad byte; currently always contains 0.
1884 * @flag: No flags defined yet; set to 0.
1885 * @params: Same as v0 parameters.
1886 */
1887struct ec_params_flash_erase_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001888 uint8_t cmd;
1889 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001890 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001891 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001892} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001893
1894/*
1895 * Get/set flash protection.
1896 *
1897 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1898 * firmware write protect GPIO, not all flags will take effect immediately;
1899 * some flags require a subsequent hard reset to take effect. Check the
1900 * returned flags bits to see what actually happened.
1901 *
1902 * If mask=0, simply returns the current flags state.
1903 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001904#define EC_CMD_FLASH_PROTECT 0x0015
Caveh Jalali024ffe32023-01-30 14:35:19 -08001905#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001906
1907/* Flags for flash protection */
1908/* RO flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001909#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001910/*
1911 * RO flash code protected now. If this bit is set, at-boot status cannot
1912 * be changed.
1913 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001914#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001915/* Entire flash code protected now, until reboot. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001916#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001917/* Flash write protect GPIO is asserted now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001918#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001919/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001920#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001921/*
1922 * Error - flash protection is in inconsistent state. At least one bank of
1923 * flash which should be protected is not protected. Usually fixed by
1924 * re-requesting the desired flags, or by a hard reset if that fails.
1925 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001926#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001927/* Entire flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001928#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001929/* RW flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001930#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001931/* RW flash code protected now. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001932#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001933/* Rollback information flash region protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001934#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001935/* Rollback information flash region protected now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001936#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001937/* Error - Unknown error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001938#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001939
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001940/**
1941 * struct ec_params_flash_protect - Parameters for the flash protect command.
1942 * @mask: Bits in flags to apply.
1943 * @flags: New flags to apply.
1944 */
1945struct ec_params_flash_protect {
1946 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001947 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001948} __ec_align4;
1949
Simon Glassd3870a22023-11-09 08:43:30 -07001950enum flash_protect_action {
1951 FLASH_PROTECT_ASYNC = 0,
1952 FLASH_PROTECT_GET_RESULT = 1,
1953};
1954
1955/* Version 2 of the command is "asynchronous". */
1956struct ec_params_flash_protect_v2 {
1957 uint8_t action; /**< enum flash_protect_action */
1958 uint8_t reserved[3]; /**< padding for alignment */
1959 uint32_t mask;
1960 uint32_t flags;
1961} __ec_align4;
1962
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001963/**
1964 * struct ec_response_flash_protect - Response to the flash protect command.
1965 * @flags: Current value of flash protect flags.
1966 * @valid_flags: Flags which are valid on this platform. This allows the
1967 * caller to distinguish between flags which aren't set vs. flags
1968 * which can't be set on this platform.
1969 * @writable_flags: Flags which can be changed given the current protection
1970 * state.
1971 */
1972struct ec_response_flash_protect {
1973 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001974 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001975 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001976} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001977
1978/*
1979 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1980 * write protect. These commands may be reused with version > 0.
1981 */
1982
1983/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001984#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001985#define EC_VER_FLASH_REGION_INFO 1
1986
1987enum ec_flash_region {
1988 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001989 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001990 /*
1991 * Region which holds active RW image. 'Active' is different from
1992 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1993 * scheduled to run, active/non-active applies only to RW images (for
1994 * the same reason 'update' applies only to RW images. It's a state of
1995 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1996 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1997 * doesn't enter 'running' state but it's still active on a flash.
1998 */
1999 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002000 /*
2001 * Region which should be write-protected in the factory (a superset of
2002 * EC_FLASH_REGION_RO)
2003 */
2004 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002005 /* Region which holds updatable (non-active) RW image */
2006 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08002007 /* Number of regions */
2008 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002009};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002010/*
2011 * 'RW' is vague if there are multiple RW images; we mean the active one,
2012 * so the old constant is deprecated.
2013 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002014#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002015
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002016/**
2017 * struct ec_params_flash_region_info - Parameters for the flash region info
2018 * command.
2019 * @region: Flash region; see EC_FLASH_REGION_*
2020 */
2021struct ec_params_flash_region_info {
2022 uint32_t region;
2023} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002024
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002025struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002026 uint32_t offset;
2027 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002028} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002029
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002030/* Get SPI flash information */
2031#define EC_CMD_FLASH_SPI_INFO 0x0018
2032
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002033struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002034 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
2035 uint8_t jedec[3];
2036
2037 /* Pad byte; currently always contains 0 */
2038 uint8_t reserved0;
2039
2040 /* Manufacturer / device ID from command 0x90 */
2041 uint8_t mfr_dev_id[2];
2042
2043 /* Status registers from command 0x05 and 0x35 */
2044 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002045} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002046
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002047/* Select flash during flash operations */
2048#define EC_CMD_FLASH_SELECT 0x0019
2049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002050/**
2051 * struct ec_params_flash_select - Parameters for the flash select command.
2052 * @select: 1 to select flash, 0 to deselect flash
2053 */
2054struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002055 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002056} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002057
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002058/**
2059 * Request random numbers to be generated and returned.
2060 * Can be used to test the random number generator is truly random.
2061 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
2062 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
2063 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002064#define EC_CMD_RAND_NUM 0x001A
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002065#define EC_VER_RAND_NUM 0
2066
2067struct ec_params_rand_num {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002068 uint16_t num_rand_bytes; /**< num random bytes to generate */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002069} __ec_align4;
2070
2071struct ec_response_rand_num {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002072 /**
2073 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
2074 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
2075 */
2076 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
2077} __ec_align1;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002078BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
2079
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002080/**
2081 * Get information about the key used to sign the RW firmware.
2082 * For more details on the fields, see "struct vb21_packed_key".
2083 */
2084#define EC_CMD_RWSIG_INFO 0x001B
2085#define EC_VER_RWSIG_INFO 0
2086
2087#define VBOOT2_KEY_ID_BYTES 20
2088
2089#ifdef CHROMIUM_EC
2090/* Don't force external projects to depend on the vboot headers. */
2091#include "vb21_struct.h"
2092BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
2093#endif
2094
2095struct ec_response_rwsig_info {
2096 /**
2097 * Signature algorithm used by the key
2098 * (enum vb2_signature_algorithm).
2099 */
2100 uint16_t sig_alg;
2101
2102 /**
2103 * Hash digest algorithm used with the key
2104 * (enum vb2_hash_algorithm).
2105 */
2106 uint16_t hash_alg;
2107
2108 /** Key version. */
2109 uint32_t key_version;
2110
2111 /** Key ID (struct vb2_id). */
2112 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2113
2114 uint8_t key_is_valid;
2115
2116 /** Alignment padding. */
2117 uint8_t reserved[3];
2118} __ec_align4;
2119
2120BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2121
2122/**
2123 * Get information about the system, such as reset flags, locked state, etc.
2124 */
2125#define EC_CMD_SYSINFO 0x001C
2126#define EC_VER_SYSINFO 0
2127
2128enum sysinfo_flags {
2129 SYSTEM_IS_LOCKED = BIT(0),
2130 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2131 SYSTEM_JUMP_ENABLED = BIT(2),
2132 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08002133 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2134 /*
2135 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2136 * set and cleared when the system shuts down (not when the host event
2137 * flag is cleared).
2138 */
2139 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002140};
2141
2142struct ec_response_sysinfo {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002143 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002144 uint32_t current_image; /**< enum ec_image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002145 uint32_t flags; /**< enum sysinfo_flags */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002146} __ec_align4;
2147
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002148/*****************************************************************************/
2149/* PWM commands */
2150
2151/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002152#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002153
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002154struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002155 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002156} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002157
2158/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002159#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002160
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002161/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002162struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002163 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002164} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002165
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002166/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002167struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002168 uint32_t rpm;
2169 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002170} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002171
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002172/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002173/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002174#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002175
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002176struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002177 uint8_t percent;
2178 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002179} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002180
2181/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002182/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002183#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002184
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002185struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002186 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002187} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002188
2189/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002190#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002191
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002192/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002193struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002194 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002195} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002196
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002197/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002198struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002199 uint32_t percent;
2200 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002201} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002202
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002203#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002204/* 16 bit duty cycle, 0xffff = 100% */
2205#define EC_PWM_MAX_DUTY 0xffff
2206
2207enum ec_pwm_type {
2208 /* All types, indexed by board-specific enum pwm_channel */
2209 EC_PWM_TYPE_GENERIC = 0,
2210 /* Keyboard backlight */
2211 EC_PWM_TYPE_KB_LIGHT,
2212 /* Display backlight */
2213 EC_PWM_TYPE_DISPLAY_LIGHT,
2214 EC_PWM_TYPE_COUNT,
2215};
2216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002217struct ec_params_pwm_set_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002218 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2219 uint8_t pwm_type; /* ec_pwm_type */
2220 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002221} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002222
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002223#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002224
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002225struct ec_params_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002226 uint8_t pwm_type; /* ec_pwm_type */
2227 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002228} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002229
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002230struct ec_response_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002231 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002232} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002233
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002234/*****************************************************************************/
2235/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002236 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002237 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2238 * into a subcommand. We'll make separate structs for subcommands with
2239 * different input args, so that we know how much to expect.
2240 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002241#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002242
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002243struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002244 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002245} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002246
Duncan Laurie433432b2013-06-03 10:38:22 -07002247#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002248
2249/*
2250 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002251 * host command, but the alignment is the same regardless. Keep it that way.
2252 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002253struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002254 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002255 int32_t google_ramp_up;
2256 int32_t google_ramp_down;
2257 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002258 int32_t s0_tick_delay[2]; /* AC=0/1 */
2259 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie93e24442014-01-06 12:30:52 -08002260 int32_t s0s3_ramp_down;
2261 int32_t s3_sleep_for;
2262 int32_t s3_ramp_up;
2263 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002264
2265 /* Oscillation */
2266 uint8_t new_s0;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002267 uint8_t osc_min[2]; /* AC=0/1 */
2268 uint8_t osc_max[2]; /* AC=0/1 */
2269 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002270
2271 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002272 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2273 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2274 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002275
2276 /* Battery level thresholds */
2277 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2278
2279 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002280 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2281 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie433432b2013-06-03 10:38:22 -07002282
2283 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002284 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002285} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002286
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002287struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002288 /* Timing */
2289 int32_t google_ramp_up;
2290 int32_t google_ramp_down;
2291 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002292 int32_t s0_tick_delay[2]; /* AC=0/1 */
2293 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002294 int32_t s0s3_ramp_down;
2295 int32_t s3_sleep_for;
2296 int32_t s3_ramp_up;
2297 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002298 int32_t s5_ramp_up;
2299 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002300 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002301 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002302 int32_t tap_display_time;
2303
2304 /* Tap-for-battery params */
2305 uint8_t tap_pct_red;
2306 uint8_t tap_pct_green;
2307 uint8_t tap_seg_min_on;
2308 uint8_t tap_seg_max_on;
2309 uint8_t tap_seg_osc;
2310 uint8_t tap_idx[3];
2311
2312 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002313 uint8_t osc_min[2]; /* AC=0/1 */
2314 uint8_t osc_max[2]; /* AC=0/1 */
2315 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002316
2317 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002318 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2319 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2320 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002321
2322 /* Battery level thresholds */
2323 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2324
2325 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002326 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2327 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002328
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002329 /* s5: single color pulse on inhibited power-up */
2330 uint8_t s5_idx;
2331
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002332 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002333 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002334} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002335
Duncan Laurieeb316852015-12-01 18:51:18 -08002336/* Lightbar command params v2
2337 * crbug.com/467716
2338 *
2339 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2340 * logical groups to make it more manageable ( < 120 bytes).
2341 *
2342 * NOTE: Each of these groups must be less than 120 bytes.
2343 */
2344
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002345struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002346 /* Timing */
2347 int32_t google_ramp_up;
2348 int32_t google_ramp_down;
2349 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002350 int32_t s0_tick_delay[2]; /* AC=0/1 */
2351 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002352 int32_t s0s3_ramp_down;
2353 int32_t s3_sleep_for;
2354 int32_t s3_ramp_up;
2355 int32_t s3_ramp_down;
2356 int32_t s5_ramp_up;
2357 int32_t s5_ramp_down;
2358 int32_t tap_tick_delay;
2359 int32_t tap_gate_delay;
2360 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002361} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002362
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002363struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002364 /* Tap-for-battery params */
2365 uint8_t tap_pct_red;
2366 uint8_t tap_pct_green;
2367 uint8_t tap_seg_min_on;
2368 uint8_t tap_seg_max_on;
2369 uint8_t tap_seg_osc;
2370 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002371} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002372
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002373struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002374 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002375 uint8_t osc_min[2]; /* AC=0/1 */
2376 uint8_t osc_max[2]; /* AC=0/1 */
2377 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002378} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002379
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002380struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002381 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002382 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2383 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2384 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002385} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002386
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002387struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002388 /* Battery level thresholds */
2389 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002390} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002391
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002392struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002393 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002394 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2395 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurieeb316852015-12-01 18:51:18 -08002396
2397 /* s5: single color pulse on inhibited power-up */
2398 uint8_t s5_idx;
2399
2400 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002401 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002402} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002403
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002404/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002405#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002406struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002407 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002408 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002409} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002410
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002411struct ec_params_lightbar {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002412 uint8_t cmd; /* Command (see enum lightbar_command) */
Duncan Laurie433432b2013-06-03 10:38:22 -07002413 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002414 /*
2415 * The following commands have no args:
2416 *
2417 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2418 * version, get_brightness, get_demo, suspend, resume,
2419 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2420 * get_params_v2_bright, get_params_v2_thlds,
2421 * get_params_v2_colors
2422 *
2423 * Don't use an empty struct, because C++ hates that.
2424 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002425
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002426 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002427 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002428 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002429
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002430 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002431 uint8_t ctrl, reg, value;
2432 } reg;
2433
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002434 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002435 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002436 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002437
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002438 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002439 uint8_t led;
2440 } get_rgb;
2441
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002442 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002443 uint8_t enable;
2444 } manual_suspend_ctrl;
2445
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002446 struct lightbar_params_v0 set_params_v0;
2447 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002448
2449 struct lightbar_params_v2_timing set_v2par_timing;
2450 struct lightbar_params_v2_tap set_v2par_tap;
2451 struct lightbar_params_v2_oscillation set_v2par_osc;
2452 struct lightbar_params_v2_brightness set_v2par_bright;
2453 struct lightbar_params_v2_thresholds set_v2par_thlds;
2454 struct lightbar_params_v2_colors set_v2par_colors;
2455
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002456 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002457 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002458} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002459
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002460struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002461 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002462 struct __ec_todo_unpacked {
2463 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002464 uint8_t reg;
2465 uint8_t ic0;
2466 uint8_t ic1;
2467 } vals[23];
2468 } dump;
2469
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002470 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002471 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002472 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002473
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002474 struct lightbar_params_v0 get_params_v0;
2475 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002476
Duncan Laurieeb316852015-12-01 18:51:18 -08002477 struct lightbar_params_v2_timing get_params_v2_timing;
2478 struct lightbar_params_v2_tap get_params_v2_tap;
2479 struct lightbar_params_v2_oscillation get_params_v2_osc;
2480 struct lightbar_params_v2_brightness get_params_v2_bright;
2481 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2482 struct lightbar_params_v2_colors get_params_v2_colors;
2483
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002484 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002485 uint32_t num;
2486 uint32_t flags;
2487 } version;
2488
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002489 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002490 uint8_t red, green, blue;
2491 } get_rgb;
2492
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002493 /*
2494 * The following commands have no response:
2495 *
2496 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2497 * set_params_v0, set_params_v1, set_program,
2498 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2499 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2500 * set_v2par_thlds, set_v2par_colors
2501 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002502 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002503} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002504
2505/* Lightbar commands */
2506enum lightbar_command {
2507 LIGHTBAR_CMD_DUMP = 0,
2508 LIGHTBAR_CMD_OFF = 1,
2509 LIGHTBAR_CMD_ON = 2,
2510 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002511 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002512 LIGHTBAR_CMD_SEQ = 5,
2513 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002514 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002515 LIGHTBAR_CMD_GET_SEQ = 8,
2516 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002517 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2518 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002519 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002520 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2521 LIGHTBAR_CMD_GET_RGB = 14,
2522 LIGHTBAR_CMD_GET_DEMO = 15,
2523 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2524 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002525 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002526 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2527 LIGHTBAR_CMD_SUSPEND = 20,
2528 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002529 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2530 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2531 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2532 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2533 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2534 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2535 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2536 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2537 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2538 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2539 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2540 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002541 LIGHTBAR_NUM_CMDS,
Duncan Laurie433432b2013-06-03 10:38:22 -07002542};
2543
2544/*****************************************************************************/
2545/* LED control commands */
2546
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002547#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002548
Bill Richardsone221aad2013-06-12 10:50:41 -07002549enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002550 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002551 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002552 /*
2553 * LED to indicate system power state (on or in suspend).
2554 * May be on power button or on C-panel.
2555 */
2556 EC_LED_ID_POWER_LED,
2557 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002558 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002559 /* LED to indicate left side */
2560 EC_LED_ID_LEFT_LED,
2561 /* LED to indicate right side */
2562 EC_LED_ID_RIGHT_LED,
2563 /* LED to indicate recovery mode with HW_REINIT */
2564 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2565 /* LED to indicate sysrq debug mode. */
2566 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002567
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002568 EC_LED_ID_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002569};
Duncan Laurie433432b2013-06-03 10:38:22 -07002570
Bill Richardsone221aad2013-06-12 10:50:41 -07002571/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002572#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002573#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002574
2575enum ec_led_colors {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002576 EC_LED_COLOR_INVALID = -1,
Bill Richardsone221aad2013-06-12 10:50:41 -07002577 EC_LED_COLOR_RED = 0,
2578 EC_LED_COLOR_GREEN,
2579 EC_LED_COLOR_BLUE,
2580 EC_LED_COLOR_YELLOW,
2581 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002582 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002583
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002584 EC_LED_COLOR_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002585};
2586
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002587struct ec_params_led_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002588 uint8_t led_id; /* Which LED to control */
2589 uint8_t flags; /* Control flags */
Bill Richardsone221aad2013-06-12 10:50:41 -07002590
2591 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002592} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002593
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002594struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002595 /*
2596 * Available brightness value range.
2597 *
2598 * Range 0 means color channel not present.
2599 * Range 1 means on/off control.
2600 * Other values means the LED is control by PWM.
2601 */
2602 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002603} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002604
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002605/*****************************************************************************/
2606/* Verified boot commands */
2607
2608/*
2609 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2610 * reused for other purposes with version > 0.
2611 */
2612
2613/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002614#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002615
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002616struct ec_params_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002617 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2618 uint8_t hash_type; /* enum ec_vboot_hash_type */
2619 uint8_t nonce_size; /* Nonce size; may be 0 */
2620 uint8_t reserved0; /* Reserved; set 0 */
2621 uint32_t offset; /* Offset in flash to hash */
2622 uint32_t size; /* Number of bytes to hash */
2623 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002624} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002625
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002626struct ec_response_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002627 uint8_t status; /* enum ec_vboot_hash_status */
2628 uint8_t hash_type; /* enum ec_vboot_hash_type */
2629 uint8_t digest_size; /* Size of hash digest in bytes */
2630 uint8_t reserved0; /* Ignore; will be 0 */
2631 uint32_t offset; /* Offset in flash which was hashed */
2632 uint32_t size; /* Number of bytes hashed */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002633 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002634} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002635
2636enum ec_vboot_hash_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002637 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2638 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2639 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2640 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002641};
2642
2643enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002644 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002645};
2646
2647enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002648 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2649 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2650 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002651};
2652
Duncan Laurie433432b2013-06-03 10:38:22 -07002653/*
2654 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2655 * If one of these is specified, the EC will automatically update offset and
2656 * size to the correct values for the specified image (RO or RW).
2657 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002658#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2659#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2660#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002661
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002662/*
2663 * 'RW' is vague if there are multiple RW images; we mean the active one,
2664 * so the old constant is deprecated.
2665 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002666#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002667
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002668/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002669/*
2670 * Motion sense commands. We'll make separate structs for sub-commands with
2671 * different input args, so that we know how much to expect.
2672 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002673#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002674
2675/* Motion sense commands */
2676enum motionsense_command {
2677 /*
2678 * Dump command returns all motion sensor data including motion sense
2679 * module flags and individual sensor flags.
2680 */
2681 MOTIONSENSE_CMD_DUMP = 0,
2682
2683 /*
2684 * Info command returns data describing the details of a given sensor,
2685 * including enum motionsensor_type, enum motionsensor_location, and
2686 * enum motionsensor_chip.
2687 */
2688 MOTIONSENSE_CMD_INFO = 1,
2689
2690 /*
2691 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002692 * in milliseconds.
2693 * It is per sensor, the EC run sample task at the minimum of all
2694 * sensors EC_RATE.
2695 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2696 * to collect all the sensor samples.
2697 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2698 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002699 */
2700 MOTIONSENSE_CMD_EC_RATE = 2,
2701
2702 /*
2703 * Sensor ODR command is a setter/getter command for the output data
2704 * rate of a specific motion sensor in millihertz.
2705 */
2706 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2707
2708 /*
2709 * Sensor range command is a setter/getter command for the range of
2710 * a specified motion sensor in +/-G's or +/- deg/s.
2711 */
2712 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2713
2714 /*
2715 * Setter/getter command for the keyboard wake angle. When the lid
2716 * angle is greater than this value, keyboard wake is disabled in S3,
2717 * and when the lid angle goes less than this value, keyboard wake is
2718 * enabled. Note, the lid angle measurement is an approximate,
2719 * un-calibrated value, hence the wake angle isn't exact.
2720 */
2721 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2722
Duncan Laurieeb316852015-12-01 18:51:18 -08002723 /*
2724 * Returns a single sensor data.
2725 */
2726 MOTIONSENSE_CMD_DATA = 6,
2727
2728 /*
2729 * Return sensor fifo info.
2730 */
2731 MOTIONSENSE_CMD_FIFO_INFO = 7,
2732
2733 /*
2734 * Insert a flush element in the fifo and return sensor fifo info.
2735 * The host can use that element to synchronize its operation.
2736 */
2737 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2738
2739 /*
2740 * Return a portion of the fifo.
2741 */
2742 MOTIONSENSE_CMD_FIFO_READ = 9,
2743
2744 /*
2745 * Perform low level calibration.
2746 * On sensors that support it, ask to do offset calibration.
2747 */
2748 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2749
2750 /*
2751 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002752 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002753 * The offsets can be calculated by the host, or via
2754 * PERFORM_CALIB command.
2755 */
2756 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2757
2758 /*
2759 * List available activities for a MOTION sensor.
2760 * Indicates if they are enabled or disabled.
2761 */
2762 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2763
2764 /*
2765 * Activity management
2766 * Enable/Disable activity recognition.
2767 */
2768 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2769
2770 /*
2771 * Lid Angle
2772 */
2773 MOTIONSENSE_CMD_LID_ANGLE = 14,
2774
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002775 /*
2776 * Allow the FIFO to trigger interrupt via MKBP events.
2777 * By default the FIFO does not send interrupt to process the FIFO
2778 * until the AP is ready or it is coming from a wakeup sensor.
2779 */
2780 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2781
2782 /*
2783 * Spoof the readings of the sensors. The spoofed readings can be set
2784 * to arbitrary values, or will lock to the last read actual values.
2785 */
2786 MOTIONSENSE_CMD_SPOOF = 16,
2787
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002788 /* Set lid angle for tablet mode detection. */
2789 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2790
2791 /*
2792 * Sensor Scale command is a setter/getter command for the calibration
2793 * scale.
2794 */
2795 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2796
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002797 /*
2798 * Read the current online calibration values (if available).
2799 */
2800 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2801
Yidi Lin42f79592020-09-21 18:04:10 +08002802 /*
2803 * Activity management
2804 * Retrieve current status of given activity.
2805 */
2806 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2807
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002808 /* Number of motionsense sub-commands. */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002809 MOTIONSENSE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002810};
2811
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002812/* List of motion sensor types. */
2813enum motionsensor_type {
2814 MOTIONSENSE_TYPE_ACCEL = 0,
2815 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002816 MOTIONSENSE_TYPE_MAG = 2,
2817 MOTIONSENSE_TYPE_PROX = 3,
2818 MOTIONSENSE_TYPE_LIGHT = 4,
2819 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002820 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002821 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002822 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002823 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002824};
2825
2826/* List of motion sensor locations. */
2827enum motionsensor_location {
2828 MOTIONSENSE_LOC_BASE = 0,
2829 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002830 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002831 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002832};
2833
2834/* List of motion sensor chips. */
2835enum motionsensor_chip {
2836 MOTIONSENSE_CHIP_KXCJ9 = 0,
2837 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002838 MOTIONSENSE_CHIP_BMI160 = 2,
2839 MOTIONSENSE_CHIP_SI1141 = 3,
2840 MOTIONSENSE_CHIP_SI1142 = 4,
2841 MOTIONSENSE_CHIP_SI1143 = 5,
2842 MOTIONSENSE_CHIP_KX022 = 6,
2843 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002844 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002845 MOTIONSENSE_CHIP_BMP280 = 9,
2846 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002847 MOTIONSENSE_CHIP_BH1730 = 11,
2848 MOTIONSENSE_CHIP_GPIO = 12,
2849 MOTIONSENSE_CHIP_LIS2DH = 13,
2850 MOTIONSENSE_CHIP_LSM6DSM = 14,
2851 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002852 MOTIONSENSE_CHIP_LIS2MDL = 16,
2853 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2854 MOTIONSENSE_CHIP_LSM6DSO = 18,
2855 MOTIONSENSE_CHIP_LNG2DM = 19,
2856 MOTIONSENSE_CHIP_TCS3400 = 20,
2857 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2858 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002859 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002860 MOTIONSENSE_CHIP_BMI260 = 24,
2861 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002862 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002863 MOTIONSENSE_CHIP_BMA422 = 27,
2864 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002865 MOTIONSENSE_CHIP_BMI220 = 29,
2866 MOTIONSENSE_CHIP_CM32183 = 30,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002867 MOTIONSENSE_CHIP_MAX,
2868};
2869
2870/* List of orientation positions */
2871enum motionsensor_orientation {
2872 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2873 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2874 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2875 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2876 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002877};
2878
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002879struct ec_response_activity_data {
2880 uint8_t activity; /* motionsensor_activity */
2881 uint8_t state;
2882} __ec_todo_packed;
2883
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002884struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002885 /* Flags for each sensor. */
2886 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002887 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002888 uint8_t sensor_num;
2889 /* Each sensor is up to 3-axis. */
2890 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002891 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002892 /* for sensors using unsigned data */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002893 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002894 struct __ec_todo_packed {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002895 uint16_t reserved;
2896 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002897 };
2898 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002899 struct ec_response_activity_data activity_data;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002900 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002901 };
2902 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002903} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002904
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002905/* Response to AP reporting calibration data for a given sensor. */
2906struct ec_response_online_calibration_data {
2907 /** The calibration values. */
2908 int16_t data[3];
2909};
2910
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002911/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002912struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002913 /* Size of the fifo */
2914 uint16_t size;
2915 /* Amount of space used in the fifo */
2916 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002917 /* Timestamp recorded in us.
2918 * aka accurate timestamp when host event was triggered.
2919 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002920 uint32_t timestamp;
2921 /* Total amount of vector lost */
2922 uint16_t total_lost;
2923 /* Lost events since the last fifo_info, per sensors */
2924 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002925} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002926
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002927struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002928 uint32_t number_data;
2929 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002930} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002931
2932/* List supported activity recognition */
2933enum motionsensor_activity {
2934 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2935 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2936 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002937 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002938 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002939};
2940
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002941struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002942 uint8_t sensor_num;
2943 uint8_t activity; /* one of enum motionsensor_activity */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002944 uint8_t enable; /* 1: enable, 0: disable */
Duncan Laurieeb316852015-12-01 18:51:18 -08002945 uint8_t reserved;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002946 uint16_t parameters[4]; /* activity dependent parameters */
2947} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002948
2949/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002950#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002951
2952/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002953#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002954
2955/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002956 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002957 * data contains time stamp
2958 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002959#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2960#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2961#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2962#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2963#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002964
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002965#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2966
Duncan Laurieeb316852015-12-01 18:51:18 -08002967/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002968 * Send this value for the data element to only perform a read. If you
2969 * send any other value, the EC will interpret it as data to set and will
2970 * return the actual value set.
2971 */
2972#define EC_MOTION_SENSE_NO_VALUE -1
2973
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002974#define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
Duncan Laurieeb316852015-12-01 18:51:18 -08002975
2976/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2977/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002978#define MOTION_SENSE_SET_OFFSET BIT(0)
2979
2980/* Default Scale value, factor 1. */
2981#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002982
2983#define LID_ANGLE_UNRELIABLE 500
2984
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002985enum motionsense_spoof_mode {
2986 /* Disable spoof mode. */
2987 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2988
2989 /* Enable spoof mode, but use provided component values. */
2990 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2991
2992 /* Enable spoof mode, but use the current sensor values. */
2993 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2994
2995 /* Query the current spoof mode status for the sensor. */
2996 MOTIONSENSE_SPOOF_MODE_QUERY,
2997};
2998
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002999struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003000 uint8_t cmd;
3001 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003002 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003003 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003004 /*
3005 * Maximal number of sensor the host is expecting.
3006 * 0 means the host is only interested in the number
3007 * of sensors controlled by the EC.
3008 */
3009 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003010 } dump;
3011
3012 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08003013 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003014 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003015 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003016 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08003017 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08003018 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003019 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08003020 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003021
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003022 /*
3023 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
3024 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003025 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003026 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003027 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003028
3029 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003030 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
3031 * Allow entering/exiting the calibration mode.
3032 */
3033 struct __ec_todo_unpacked {
3034 uint8_t sensor_num;
3035 uint8_t enable;
3036 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003037
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003038 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08003039 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
3040 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003041 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003042 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003043 uint8_t sensor_num;
3044
3045 /* Rounding flag, true for round-up, false for down. */
3046 uint8_t roundup;
3047
3048 uint16_t reserved;
3049
3050 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
3051 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08003052 } ec_rate, sensor_odr, sensor_range;
3053
3054 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003055 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003056 uint8_t sensor_num;
3057
3058 /*
3059 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3060 * the calibration information in the EC.
3061 * If unset, just retrieve calibration information.
3062 */
3063 uint16_t flags;
3064
3065 /*
3066 * Temperature at calibration, in units of 0.01 C
3067 * 0x8000: invalid / unknown.
3068 * 0x0: 0C
3069 * 0x7fff: +327.67C
3070 */
3071 int16_t temp;
3072
3073 /*
3074 * Offset for calibration.
3075 * Unit:
3076 * Accelerometer: 1/1024 g
3077 * Gyro: 1/1024 deg/s
3078 * Compass: 1/16 uT
3079 */
3080 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003081 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08003082
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003083 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3084 struct __ec_todo_packed {
3085 uint8_t sensor_num;
3086
3087 /*
3088 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3089 * the calibration information in the EC.
3090 * If unset, just retrieve calibration information.
3091 */
3092 uint16_t flags;
3093
3094 /*
3095 * Temperature at calibration, in units of 0.01 C
3096 * 0x8000: invalid / unknown.
3097 * 0x0: 0C
3098 * 0x7fff: +327.67C
3099 */
3100 int16_t temp;
3101
3102 /*
3103 * Scale for calibration:
3104 * By default scale is 1, it is encoded on 16bits:
3105 * 1 = BIT(15)
3106 * ~2 = 0xFFFF
3107 * ~0 = 0.
3108 */
3109 uint16_t scale[3];
3110 } sensor_scale;
3111
Duncan Laurieeb316852015-12-01 18:51:18 -08003112 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003113 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08003114
3115 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003116 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003117 /*
3118 * Number of expected vector to return.
3119 * EC may return less or 0 if none available.
3120 */
3121 uint32_t max_data_vector;
3122 } fifo_read;
3123
Yidi Lin42f79592020-09-21 18:04:10 +08003124 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08003125 struct ec_motion_sense_activity set_activity;
3126
3127 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003128 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003129
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003130 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3131 struct __ec_todo_unpacked {
3132 /*
3133 * 1: enable, 0 disable fifo,
3134 * EC_MOTION_SENSE_NO_VALUE return value.
3135 */
3136 int8_t enable;
3137 } fifo_int_enable;
3138
3139 /* Used for MOTIONSENSE_CMD_SPOOF */
3140 struct __ec_todo_packed {
3141 uint8_t sensor_id;
3142
3143 /* See enum motionsense_spoof_mode. */
3144 uint8_t spoof_enable;
3145
3146 /* Ignored, used for alignment. */
3147 uint8_t reserved;
3148
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003149 union {
3150 /* Individual component values to spoof. */
3151 int16_t components[3];
3152
3153 /* Used when spoofing an activity */
3154 struct {
3155 /* enum motionsensor_activity */
3156 uint8_t activity_num;
3157
3158 /* spoof activity state */
3159 uint8_t activity_state;
3160 };
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003161 } __ec_todo_packed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003162 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003163
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003164 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3165 struct __ec_todo_unpacked {
3166 /*
3167 * Lid angle threshold for switching between tablet and
3168 * clamshell mode.
3169 */
3170 int16_t lid_angle;
3171
3172 /*
3173 * Hysteresis degree to prevent fluctuations between
3174 * clamshell and tablet mode if lid angle keeps
3175 * changing around the threshold. Lid motion driver will
3176 * use lid_angle + hys_degree to trigger tablet mode and
3177 * lid_angle - hys_degree to trigger clamshell mode.
3178 */
3179 int16_t hys_degree;
3180 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003181
3182 /*
3183 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3184 * Allow reading a single sensor's online calibration value.
3185 */
3186 struct __ec_todo_unpacked {
3187 uint8_t sensor_num;
3188 } online_calib_read;
3189
Yidi Lin42f79592020-09-21 18:04:10 +08003190 /*
3191 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3192 */
3193 struct __ec_todo_unpacked {
3194 uint8_t sensor_num;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003195 uint8_t activity; /* enum motionsensor_activity */
Yidi Lin42f79592020-09-21 18:04:10 +08003196 } get_activity;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003197 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003198} __ec_todo_packed;
3199
Jett Rinkba2edaf2020-01-14 11:49:06 -07003200enum motion_sense_cmd_info_flags {
3201 /* The sensor supports online calibration */
3202 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3203};
3204
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003205struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003206 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003207 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003208 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003209 /* Flags representing the motion sensor module. */
3210 uint8_t module_flags;
3211
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003212 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003213 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003214
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003215 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003216 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003217 * for holding all the data.
3218 */
3219 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003220 } dump;
3221
3222 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003223 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003224 /* Should be element of enum motionsensor_type. */
3225 uint8_t type;
3226
3227 /* Should be element of enum motionsensor_location. */
3228 uint8_t location;
3229
3230 /* Should be element of enum motionsensor_chip. */
3231 uint8_t chip;
3232 } info;
3233
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003234 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3235 struct __ec_todo_unpacked {
3236 /* Should be element of enum motionsensor_type. */
3237 uint8_t type;
3238
3239 /* Should be element of enum motionsensor_location. */
3240 uint8_t location;
3241
3242 /* Should be element of enum motionsensor_chip. */
3243 uint8_t chip;
3244
3245 /* Minimum sensor sampling frequency */
3246 uint32_t min_frequency;
3247
3248 /* Maximum sensor sampling frequency */
3249 uint32_t max_frequency;
3250
3251 /* Max number of sensor events that could be in fifo */
3252 uint32_t fifo_max_event_count;
3253 } info_3;
3254
Jett Rinkba2edaf2020-01-14 11:49:06 -07003255 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3256 struct __ec_align4 {
3257 /* Should be element of enum motionsensor_type. */
3258 uint8_t type;
3259
3260 /* Should be element of enum motionsensor_location. */
3261 uint8_t location;
3262
3263 /* Should be element of enum motionsensor_chip. */
3264 uint8_t chip;
3265
3266 /* Minimum sensor sampling frequency */
3267 uint32_t min_frequency;
3268
3269 /* Maximum sensor sampling frequency */
3270 uint32_t max_frequency;
3271
3272 /* Max number of sensor events that could be in fifo */
3273 uint32_t fifo_max_event_count;
3274
3275 /*
3276 * Should be elements of
3277 * enum motion_sense_cmd_info_flags
3278 */
3279 uint32_t flags;
3280 } info_4;
3281
Duncan Laurieeb316852015-12-01 18:51:18 -08003282 /* Used for MOTIONSENSE_CMD_DATA */
3283 struct ec_response_motion_sensor_data data;
3284
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003285 /*
3286 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003287 * MOTIONSENSE_CMD_SENSOR_RANGE,
3288 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3289 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3290 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003291 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003292 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003293 /* Current value of the parameter queried. */
3294 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003295 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Caveh Jalali024ffe32023-01-30 14:35:19 -08003296 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003297
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003298 /*
3299 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3300 * PERFORM_CALIB.
3301 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003302 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003303 int16_t temp;
3304 int16_t offset[3];
3305 } sensor_offset, perform_calib;
3306
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003307 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003308 struct __ec_todo_unpacked {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003309 int16_t temp;
3310 uint16_t scale[3];
3311 } sensor_scale;
3312
Duncan Laurieeb316852015-12-01 18:51:18 -08003313 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3314
3315 struct ec_response_motion_sense_fifo_data fifo_read;
3316
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003317 struct ec_response_online_calibration_data online_calib_read;
3318
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003319 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003320 uint16_t reserved;
3321 uint32_t enabled;
3322 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003323 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003324
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003325 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003326
Duncan Laurieeb316852015-12-01 18:51:18 -08003327 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003328 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003329 /*
3330 * Angle between 0 and 360 degree if available,
3331 * LID_ANGLE_UNRELIABLE otherwise.
3332 */
3333 uint16_t value;
3334 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003335
3336 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3337 struct __ec_todo_unpacked {
3338 /*
3339 * Lid angle threshold for switching between tablet and
3340 * clamshell mode.
3341 */
3342 uint16_t lid_angle;
3343
3344 /* Hysteresis degree. */
3345 uint16_t hys_degree;
3346 } tablet_mode_threshold;
3347
Yidi Lin42f79592020-09-21 18:04:10 +08003348 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3349 struct __ec_todo_unpacked {
3350 uint8_t state;
3351 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003352 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003353} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003354
3355/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003356/* Force lid open command */
3357
3358/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003359#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003360
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003361struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003362 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003363} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003364
3365/*****************************************************************************/
3366/* Configure the behavior of the power button */
3367#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3368
3369enum ec_config_power_button_flags {
3370 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003371 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003372};
3373
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003374struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003375 /* See enum ec_config_power_button_flags */
3376 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003377} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003378
3379/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003380/* USB charging control commands */
3381
3382/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003383#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003384
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003385enum usb_charge_mode {
3386 /* Disable USB port. */
3387 USB_CHARGE_MODE_DISABLED,
3388 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3389 USB_CHARGE_MODE_SDP2,
3390 /* Set USB port to Charging Downstream Port, BC 1.2. */
3391 USB_CHARGE_MODE_CDP,
3392 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3393 USB_CHARGE_MODE_DCP_SHORT,
3394 /* Enable USB port (for dumb ports). */
3395 USB_CHARGE_MODE_ENABLED,
3396 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3397 USB_CHARGE_MODE_DEFAULT,
3398
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003399 USB_CHARGE_MODE_COUNT,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003400};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003401
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003402enum usb_suspend_charge {
3403 /* Enable charging in suspend */
3404 USB_ALLOW_SUSPEND_CHARGE,
3405 /* Disable charging in suspend */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003406 USB_DISALLOW_SUSPEND_CHARGE,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003407};
3408
3409struct ec_params_usb_charge_set_mode {
3410 uint8_t usb_port_id;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003411 uint8_t mode : 7; /* enum usb_charge_mode */
3412 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003413} __ec_align1;
3414
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003415/*****************************************************************************/
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003416/* Tablet mode commands */
3417
3418/* Set tablet mode */
3419#define EC_CMD_SET_TABLET_MODE 0x0031
3420
3421enum tablet_mode_override {
3422 TABLET_MODE_DEFAULT,
3423 TABLET_MODE_FORCE_TABLET,
3424 TABLET_MODE_FORCE_CLAMSHELL,
3425};
3426
3427struct ec_params_set_tablet_mode {
3428 uint8_t tablet_mode; /* enum tablet_mode_override */
3429} __ec_align1;
3430
3431/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003432/* Persistent storage for host */
3433
3434/* Maximum bytes that can be read/written in a single command */
3435#define EC_PSTORE_SIZE_MAX 64
3436
3437/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003438#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003440struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003441 /* Persistent storage size, in bytes */
3442 uint32_t pstore_size;
3443 /* Access size; read/write offset and size must be a multiple of this */
3444 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003445} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003446
3447/*
3448 * Read persistent storage
3449 *
3450 * Response is params.size bytes of data.
3451 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003452#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003453
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003454struct ec_params_pstore_read {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003455 uint32_t offset; /* Byte offset to read */
3456 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003457} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003458
3459/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003460#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003461
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003462struct ec_params_pstore_write {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003463 uint32_t offset; /* Byte offset to write */
3464 uint32_t size; /* Size to write in bytes */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003465 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003466} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003467
3468/*****************************************************************************/
3469/* Real-time clock */
3470
3471/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003472struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003473 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003474} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003475
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003476struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003477 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003478} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003479
3480/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003481#define EC_CMD_RTC_GET_VALUE 0x0044
3482#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003483
3484/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003485#define EC_CMD_RTC_SET_VALUE 0x0046
3486#define EC_CMD_RTC_SET_ALARM 0x0047
3487
3488/* Pass as time param to SET_ALARM to clear the current alarm */
3489#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003490
3491/*****************************************************************************/
3492/* Port80 log access */
3493
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003494/* Maximum entries that can be read/written in a single command */
3495#define EC_PORT80_SIZE_MAX 32
3496
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003497/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003498#define EC_CMD_PORT80_LAST_BOOT 0x0048
3499#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003500
3501enum ec_port80_subcmd {
3502 EC_PORT80_GET_INFO = 0,
3503 EC_PORT80_READ_BUFFER,
3504};
3505
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003506struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003507 uint16_t subcmd;
3508 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003509 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003510 uint32_t offset;
3511 uint32_t num_entries;
3512 } read_buffer;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003513 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003514} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003516struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003517 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003518 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003519 uint32_t writes;
3520 uint32_t history_size;
3521 uint32_t last_boot;
3522 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003523 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003524 uint16_t codes[EC_PORT80_SIZE_MAX];
3525 } data;
3526 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003527} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003528
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003529struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003530 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003531} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003532
3533/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003534/* Temporary secure storage for host verified boot use */
3535
3536/* Number of bytes in a vstore slot */
3537#define EC_VSTORE_SLOT_SIZE 64
3538
3539/* Maximum number of vstore slots */
3540#define EC_VSTORE_SLOT_MAX 32
3541
3542/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003543#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003544struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003545 /* Indicates which slots are locked */
3546 uint32_t slot_locked;
3547 /* Total number of slots available */
3548 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003549} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003550
3551/*
3552 * Read temporary secure storage
3553 *
3554 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3555 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003556#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003557
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003558struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003559 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003560} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003561
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003562struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003563 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003564} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003565
3566/*
3567 * Write temporary secure storage and lock it.
3568 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003569#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003570
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003571struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003572 uint8_t slot; /* Slot to write to */
3573 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003574} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003575
3576/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003577/* Thermal engine commands. Note that there are two implementations. We'll
3578 * reuse the command number, but the data and behavior is incompatible.
3579 * Version 0 is what originally shipped on Link.
3580 * Version 1 separates the CPU thermal limits from the fan control.
3581 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003582
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003583#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3584#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003585
Duncan Laurie93e24442014-01-06 12:30:52 -08003586/* The version 0 structs are opaque. You have to know what they are for
3587 * the get/set commands to make any sense.
3588 */
3589
3590/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003591struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003592 uint8_t sensor_type;
3593 uint8_t threshold_id;
3594 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003595} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003596
Duncan Laurie93e24442014-01-06 12:30:52 -08003597/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003598struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003599 uint8_t sensor_type;
3600 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003601} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003602
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003603struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003604 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003605} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003606
Duncan Laurie93e24442014-01-06 12:30:52 -08003607/* The version 1 structs are visible. */
3608enum ec_temp_thresholds {
3609 EC_TEMP_THRESH_WARN = 0,
3610 EC_TEMP_THRESH_HIGH,
3611 EC_TEMP_THRESH_HALT,
3612
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003613 EC_TEMP_THRESH_COUNT,
Duncan Laurie93e24442014-01-06 12:30:52 -08003614};
3615
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003616/*
3617 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003618 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003619 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003620 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3621 * hysteresis.
3622 * For example,
3623 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3624 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3625 * EC will throttle ap when temperature >= 301 K, and release throttling when
3626 * temperature <= 299 K.
3627 *
3628 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3629 * For example,
3630 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3631 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3632 * EC will throttle ap when temperature >= 301 K, and release throttling when
3633 * temperature <= 294 K.
3634 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003635 * Note that this structure is a sub-structure of
3636 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003637 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003638struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003639 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003640 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003641 uint32_t temp_fan_off; /* no active cooling needed */
3642 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003643} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003644
3645/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003646struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003647 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003648} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003649/* This returns a struct ec_thermal_config */
3650
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003651/*
3652 * Version 1 - set config for one sensor.
3653 * Use read-modify-write for best results!
3654 */
3655struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003656 uint32_t sensor_num;
3657 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003658} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003659/* This returns no data */
3660
3661/****************************************************************************/
3662
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003663/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003664#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003665
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003666/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003667struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003668 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003669} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003670
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003671/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003672#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3673#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003674
3675/*
3676 * The original TMP006 calibration only needed four params, but now we need
3677 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3678 * the params opaque. The v1 "get" response will include the algorithm number
3679 * and how many params it requires. That way we can change the EC code without
3680 * needing to update this file. We can also use a different algorithm on each
3681 * sensor.
3682 */
3683
3684/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003685struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003686 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003687} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003688
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003689/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003690struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003691 float s0;
3692 float b0;
3693 float b1;
3694 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003695} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003696
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003697struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003698 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003699 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003700 float s0;
3701 float b0;
3702 float b1;
3703 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003704} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003705
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003706/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003707struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003708 uint8_t algorithm;
3709 uint8_t num_params;
3710 uint8_t reserved[2];
3711 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003712} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003713
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003714struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003715 uint8_t index;
3716 uint8_t algorithm;
3717 uint8_t num_params;
3718 uint8_t reserved;
3719 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003720} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003721
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003722/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003723#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003724
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003725struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003726 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003727} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003728
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003729struct ec_response_tmp006_get_raw {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003730 int32_t t; /* In 1/100 K */
3731 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003732} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003733
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003734/*****************************************************************************/
3735/* MKBP - Matrix KeyBoard Protocol */
3736
3737/*
3738 * Read key state
3739 *
3740 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3741 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003742 *
3743 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3744 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3745 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003746 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003747#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003748
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003749/*
3750 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3751 */
3752#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003753
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003754struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003755 uint32_t rows;
3756 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003757 /* Formerly "switches", which was 0. */
3758 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003759} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003760
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003761struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003762 uint8_t info_type;
3763 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003764} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003765
3766enum ec_mkbp_info_type {
3767 /*
3768 * Info about the keyboard matrix: number of rows and columns.
3769 *
3770 * Returns struct ec_response_mkbp_info.
3771 */
3772 EC_MKBP_INFO_KBD = 0,
3773
3774 /*
3775 * For buttons and switches, info about which specifically are
3776 * supported. event_type must be set to one of the values in enum
3777 * ec_mkbp_event.
3778 *
3779 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3780 * bitmask indicating which buttons or switches are present. See the
3781 * bit inidices below.
3782 */
3783 EC_MKBP_INFO_SUPPORTED = 1,
3784
3785 /*
3786 * Instantaneous state of buttons and switches.
3787 *
3788 * event_type must be set to one of the values in enum ec_mkbp_event.
3789 *
3790 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3791 * indicating the current state of the keyboard matrix.
3792 *
3793 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3794 * event state.
3795 *
3796 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3797 * state of supported buttons.
3798 *
3799 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3800 * state of supported switches.
3801 */
3802 EC_MKBP_INFO_CURRENT = 2,
3803};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003804
3805/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003806#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003807
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003808struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003809 uint8_t col;
3810 uint8_t row;
3811 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003812} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003813
Duncan Laurie433432b2013-06-03 10:38:22 -07003814/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003815#define EC_CMD_MKBP_SET_CONFIG 0x0064
3816#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003817
3818/* flags */
3819enum mkbp_config_flags {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003820 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
Duncan Laurie433432b2013-06-03 10:38:22 -07003821};
3822
3823enum mkbp_config_valid {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003824 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3825 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3826 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3827 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3828 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3829 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3830 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003831};
3832
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003833/*
3834 * Configuration for our key scanning algorithm.
3835 *
3836 * Note that this is used as a sub-structure of
3837 * ec_{params/response}_mkbp_get_config.
3838 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003839struct ec_mkbp_config {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003840 uint32_t valid_mask; /* valid fields */
3841 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3842 uint8_t valid_flags; /* which flags are valid */
3843 uint16_t scan_period_us; /* period between start of scans */
Duncan Laurie433432b2013-06-03 10:38:22 -07003844 /* revert to interrupt mode after no activity for this long */
3845 uint32_t poll_timeout_us;
3846 /*
3847 * minimum post-scan relax time. Once we finish a scan we check
3848 * the time until we are due to start the next one. If this time is
3849 * shorter this field, we use this instead.
3850 */
3851 uint16_t min_post_scan_delay_us;
3852 /* delay between setting up output and waiting for it to settle */
3853 uint16_t output_settle_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003854 uint16_t debounce_down_us; /* time for debounce on key down */
3855 uint16_t debounce_up_us; /* time for debounce on key up */
Duncan Laurie433432b2013-06-03 10:38:22 -07003856 /* maximum depth to allow for fifo (0 = no keyscan output) */
3857 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003858} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003859
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003860struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003861 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003862} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003863
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003864struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003865 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003866} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003867
3868/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003869#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003870
3871enum ec_keyscan_seq_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003872 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3873 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3874 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3875 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3876 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003877};
3878
3879enum ec_collect_flags {
3880 /*
3881 * Indicates this scan was processed by the EC. Due to timing, some
3882 * scans may be skipped.
3883 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003884 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003885};
3886
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003887struct ec_collect_item {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003888 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003889} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003890
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003891struct ec_params_keyscan_seq_ctrl {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003892 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
Duncan Laurie433432b2013-06-03 10:38:22 -07003893 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003894 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003895 uint8_t active; /* still active */
3896 uint8_t num_items; /* number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003897 /* Current item being presented */
3898 uint8_t cur_item;
3899 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003900 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003901 /*
3902 * Absolute time for this scan, measured from the
3903 * start of the sequence.
3904 */
3905 uint32_t time_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003906 uint8_t scan[0]; /* keyscan data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003907 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003908 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003909 uint8_t start_item; /* First item to return */
3910 uint8_t num_items; /* Number of items to return */
Duncan Laurie433432b2013-06-03 10:38:22 -07003911 } collect;
3912 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003913} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003914
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003915struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003916 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003917 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003918 uint8_t num_items; /* Number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003919 /* Data for each item */
3920 struct ec_collect_item item[0];
3921 } collect;
3922 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003923} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003924
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003925/*
3926 * Get the next pending MKBP event.
3927 *
3928 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3929 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003930#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003931
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003932#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3933
3934/*
3935 * We use the most significant bit of the event type to indicate to the host
3936 * that the EC has more MKBP events available to provide.
3937 */
3938#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3939
3940/* The mask to apply to get the raw event type */
3941#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3942
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003943enum ec_mkbp_event {
3944 /* Keyboard matrix changed. The event data is the new matrix state. */
3945 EC_MKBP_EVENT_KEY_MATRIX = 0,
3946
3947 /* New host event. The event data is 4 bytes of host event flags. */
3948 EC_MKBP_EVENT_HOST_EVENT = 1,
3949
Duncan Laurieeb316852015-12-01 18:51:18 -08003950 /* New Sensor FIFO data. The event data is fifo_info structure. */
3951 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3952
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003953 /* The state of the non-matrixed buttons have changed. */
3954 EC_MKBP_EVENT_BUTTON = 3,
3955
3956 /* The state of the switches have changed. */
3957 EC_MKBP_EVENT_SWITCH = 4,
3958
3959 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3960 EC_MKBP_EVENT_FINGERPRINT = 5,
3961
3962 /*
3963 * Sysrq event: send emulated sysrq. The event data is sysrq,
3964 * corresponding to the key to be pressed.
3965 */
3966 EC_MKBP_EVENT_SYSRQ = 6,
3967
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003968 /*
3969 * New 64-bit host event.
3970 * The event data is 8 bytes of host event flags.
3971 */
3972 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3973
3974 /* Notify the AP that something happened on CEC */
3975 EC_MKBP_EVENT_CEC_EVENT = 8,
3976
3977 /* Send an incoming CEC message to the AP */
3978 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3979
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003980 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3981 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3982
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003983 /* New online calibration values are available. */
3984 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3985
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003986 /* Peripheral device charger event */
3987 EC_MKBP_EVENT_PCHG = 12,
3988
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003989 /* Number of MKBP events */
3990 EC_MKBP_EVENT_COUNT,
3991};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003992BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003993
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003994/* clang-format off */
3995#define EC_MKBP_EVENT_TEXT \
3996 { \
3997 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
3998 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
3999 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
4000 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
4001 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
4002 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
4003 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
4004 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
4005 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
4006 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
4007 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
4008 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
4009 [EC_MKBP_EVENT_PCHG] = "PCHG", \
4010 }
4011/* clang-format on */
4012
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004013union __ec_align_offset1 ec_response_get_next_data {
4014 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08004015
4016 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004017 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004018 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08004019
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004020 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08004021 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004022 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08004023 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004024 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08004025
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004026 uint32_t buttons;
4027
4028 uint32_t switches;
4029
4030 uint32_t fp_events;
4031
4032 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004033
4034 /* CEC events from enum mkbp_cec_event */
4035 uint32_t cec_events;
4036};
4037
4038union __ec_align_offset1 ec_response_get_next_data_v1 {
4039 uint8_t key_matrix[16];
4040
4041 /* Unaligned */
4042 uint32_t host_event;
4043 uint64_t host_event64;
4044
4045 struct __ec_todo_unpacked {
4046 /* For aligning the fifo_info */
4047 uint8_t reserved[3];
4048 struct ec_response_motion_sense_fifo_info info;
4049 } sensor_fifo;
4050
4051 uint32_t buttons;
4052
4053 uint32_t switches;
4054
4055 uint32_t fp_events;
4056
4057 uint32_t sysrq;
4058
4059 /* CEC events from enum mkbp_cec_event */
4060 uint32_t cec_events;
4061
4062 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004063};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004064BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004065
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004066struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004067 uint8_t event_type;
4068 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08004069 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004070} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004071
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004072struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004073 uint8_t event_type;
4074 /* Followed by event data if any */
4075 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004076} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004077
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004078/* Bit indices for buttons and switches.*/
4079/* Buttons */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004080#define EC_MKBP_POWER_BUTTON 0
4081#define EC_MKBP_VOL_UP 1
4082#define EC_MKBP_VOL_DOWN 2
4083#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004084
4085/* Switches */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004086#define EC_MKBP_LID_OPEN 0
4087#define EC_MKBP_TABLET_MODE 1
4088#define EC_MKBP_BASE_ATTACHED 2
4089#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004090
Gwendal Grignou880b4582016-06-20 08:49:25 -07004091/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004092#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07004093
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004094struct ec_response_keyboard_factory_test {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004095 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004096} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004097
4098/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004099#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF)
4100#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004101#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
Caveh Jalali024ffe32023-01-30 14:35:19 -08004102#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
4103 (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004104#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4105#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
Caveh Jalali024ffe32023-01-30 14:35:19 -08004106#define EC_MKBP_FP_MATCH_IDX(fpe) \
4107 (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
4108#define EC_MKBP_FP_ENROLL BIT(27)
4109#define EC_MKBP_FP_MATCH BIT(28)
4110#define EC_MKBP_FP_FINGER_DOWN BIT(29)
4111#define EC_MKBP_FP_FINGER_UP BIT(30)
4112#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004113/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004114#define EC_MKBP_FP_ERR_ENROLL_OK 0
4115#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4116#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4117#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4118#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004119/* Can be used to detect if image was usable for enrollment or not. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004120#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004121/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004122#define EC_MKBP_FP_ERR_MATCH_NO 0
4123#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4124#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
4125#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4126#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4127#define EC_MKBP_FP_ERR_MATCH_YES 1
4128#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004129#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4130
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004131#define EC_CMD_MKBP_WAKE_MASK 0x0069
4132enum ec_mkbp_event_mask_action {
4133 /* Retrieve the value of a wake mask. */
4134 GET_WAKE_MASK = 0,
4135
4136 /* Set the value of a wake mask. */
4137 SET_WAKE_MASK,
4138};
4139
4140enum ec_mkbp_mask_type {
4141 /*
4142 * These are host events sent via MKBP.
4143 *
4144 * Some examples are:
4145 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4146 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4147 *
4148 * The only things that should be in this mask are:
4149 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4150 */
4151 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4152
4153 /*
4154 * These are MKBP events. Some examples are:
4155 *
4156 * EC_MKBP_EVENT_KEY_MATRIX
4157 * EC_MKBP_EVENT_SWITCH
4158 *
4159 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4160 */
4161 EC_MKBP_EVENT_WAKE_MASK,
4162};
4163
4164struct ec_params_mkbp_event_wake_mask {
4165 /* One of enum ec_mkbp_event_mask_action */
4166 uint8_t action;
4167
4168 /*
4169 * Which MKBP mask are you interested in acting upon? This is one of
4170 * ec_mkbp_mask_type.
4171 */
4172 uint8_t mask_type;
4173
4174 /* If setting a new wake mask, this contains the mask to set. */
4175 uint32_t new_wake_mask;
4176};
4177
4178struct ec_response_mkbp_event_wake_mask {
4179 uint32_t wake_mask;
4180};
4181
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004182/*****************************************************************************/
4183/* Temperature sensor commands */
4184
4185/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004186#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004187
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004188struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004189 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004190} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004191
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004192struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004193 char sensor_name[32];
4194 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004195} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004196
4197/*****************************************************************************/
4198
4199/*
4200 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4201 * commands accidentally sent to the wrong interface. See the ACPI section
4202 * below.
4203 */
4204
4205/*****************************************************************************/
4206/* Host event commands */
4207
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004208/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004209/*
4210 * Host event mask params and response structures, shared by all of the host
4211 * event commands below.
4212 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004213struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004214 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004215} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004217struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004218 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004219} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004220
4221/* These all use ec_response_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004222#define EC_CMD_HOST_EVENT_GET_B 0x0087
4223#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4224#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004225#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004226
4227/* These all use ec_params_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004228#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4229#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4230#define EC_CMD_HOST_EVENT_CLEAR 0x008C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004231#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
Caveh Jalali024ffe32023-01-30 14:35:19 -08004232#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004233
Jenny TC1dfc2c32017-12-14 14:24:39 +05304234/*
4235 * Unified host event programming interface - Should be used by newer versions
4236 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004237 *
4238 * EC returns:
4239 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4240 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304241 */
4242
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004243struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304244 /* Action requested by host - one of enum ec_host_event_action. */
4245 uint8_t action;
4246
4247 /*
4248 * Mask type that the host requested the action on - one of
4249 * enum ec_host_event_mask_type.
4250 */
4251 uint8_t mask_type;
4252
4253 /* Set to 0, ignore on read */
4254 uint16_t reserved;
4255
4256 /* Value to be used in case of set operations. */
4257 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004258} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304259
4260/*
4261 * Response structure returned by EC_CMD_HOST_EVENT.
4262 * Update the value on a GET request. Set to 0 on GET/CLEAR
4263 */
4264
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004265struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304266 /* Mask value in case of get operation */
4267 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004268} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304269
4270enum ec_host_event_action {
4271 /*
4272 * params.value is ignored. Value of mask_type populated
4273 * in response.value
4274 */
4275 EC_HOST_EVENT_GET,
4276
4277 /* Bits in params.value are set */
4278 EC_HOST_EVENT_SET,
4279
4280 /* Bits in params.value are cleared */
4281 EC_HOST_EVENT_CLEAR,
4282};
4283
4284enum ec_host_event_mask_type {
4285
4286 /* Main host event copy */
4287 EC_HOST_EVENT_MAIN,
4288
4289 /* Copy B of host events */
4290 EC_HOST_EVENT_B,
4291
4292 /* SCI Mask */
4293 EC_HOST_EVENT_SCI_MASK,
4294
4295 /* SMI Mask */
4296 EC_HOST_EVENT_SMI_MASK,
4297
4298 /* Mask of events that should be always reported in hostevents */
4299 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4300
4301 /* Active wake mask */
4302 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4303
4304 /* Lazy wake mask for S0ix */
4305 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4306
4307 /* Lazy wake mask for S3 */
4308 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4309
4310 /* Lazy wake mask for S5 */
4311 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4312};
4313
Caveh Jalali024ffe32023-01-30 14:35:19 -08004314#define EC_CMD_HOST_EVENT 0x00A4
Jenny TC1dfc2c32017-12-14 14:24:39 +05304315
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004316/*****************************************************************************/
4317/* Switch commands */
4318
4319/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004320#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004321
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004322struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004323 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004324} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004325
4326/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004327#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004328#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004329
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004330/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004331struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004332 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004333} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004334
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004335/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004336struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004337 /* Flags to enable now */
4338 uint8_t now_flags;
4339
4340 /* Which flags to copy from now_flags */
4341 uint8_t now_mask;
4342
4343 /*
4344 * Flags to leave enabled in S3, if they're on at the S0->S3
4345 * transition. (Other flags will be disabled by the S0->S3
4346 * transition.)
4347 */
4348 uint8_t suspend_flags;
4349
4350 /* Which flags to copy from suspend_flags */
4351 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004352} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004353
4354/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004355struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004356 /* Flags to enable now */
4357 uint8_t now_flags;
4358
4359 /* Flags to leave enabled in S3 */
4360 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004361} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004362
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004363/*****************************************************************************/
4364/* GPIO commands. Only available on EC if write protect has been disabled. */
4365
4366/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004367#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004368
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004369struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004370 char name[32];
4371 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004372} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004373
4374/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004375#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004376
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004377/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004378struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004379 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004380} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004381
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004382struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004383 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004384} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004385
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004386/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004387struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004388 uint8_t subcmd;
4389 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004390 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004391 char name[32];
4392 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004393 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004394 uint8_t index;
4395 } get_info;
4396 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004397} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004398
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004399struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004400 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004401 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004402 uint8_t val;
4403 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004404 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004405 uint8_t val;
4406 char name[32];
4407 uint32_t flags;
4408 } get_info;
4409 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004410} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004411
4412enum gpio_get_subcmd {
4413 EC_GPIO_GET_BY_NAME = 0,
4414 EC_GPIO_GET_COUNT = 1,
4415 EC_GPIO_GET_INFO = 2,
4416};
4417
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004418/*****************************************************************************/
4419/* I2C commands. Only available when flash write protect is unlocked. */
4420
Duncan Laurie93e24442014-01-06 12:30:52 -08004421/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004422 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4423 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4424 *
4425 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004426 */
4427
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004428/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004429#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004430
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004431struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004432 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004433 uint8_t read_size; /* Either 8 or 16. */
4434 uint8_t port;
4435 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004436} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004437
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004438struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004439 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004440} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004441
4442/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004443#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004444
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004445struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004446 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004447 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004448 uint8_t write_size; /* Either 8 or 16. */
4449 uint8_t port;
4450 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004451} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004452
4453/*****************************************************************************/
4454/* Charge state commands. Only available when flash write protect unlocked. */
4455
Duncan Laurie93e24442014-01-06 12:30:52 -08004456/* Force charge state machine to stop charging the battery or force it to
4457 * discharge the battery.
4458 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004459#define EC_CMD_CHARGE_CONTROL 0x0096
Simon Glassd3870a22023-11-09 08:43:30 -07004460#define EC_VER_CHARGE_CONTROL 3
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004461
Duncan Laurie93e24442014-01-06 12:30:52 -08004462enum ec_charge_control_mode {
4463 CHARGE_CONTROL_NORMAL = 0,
4464 CHARGE_CONTROL_IDLE,
4465 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004466 /* Add no more entry below. */
4467 CHARGE_CONTROL_COUNT,
4468};
4469
Caveh Jalali024ffe32023-01-30 14:35:19 -08004470#define EC_CHARGE_MODE_TEXT \
4471 { \
4472 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4473 [CHARGE_CONTROL_IDLE] = "IDLE", \
4474 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
Scott Chao18141d8c2021-07-30 10:40:57 +08004475 }
4476
4477enum ec_charge_control_cmd {
4478 EC_CHARGE_CONTROL_CMD_SET = 0,
4479 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004480};
4481
Simon Glassd3870a22023-11-09 08:43:30 -07004482enum ec_charge_control_flag {
4483 EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0),
4484};
4485
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004486struct ec_params_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004487 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004488
4489 /* Below are the fields added in V2. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004490 uint8_t cmd; /* enum ec_charge_control_cmd. */
Simon Glassd3870a22023-11-09 08:43:30 -07004491 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
Scott Chao18141d8c2021-07-30 10:40:57 +08004492 /*
4493 * Lower and upper thresholds for battery sustainer. This struct isn't
4494 * named to avoid tainting foreign projects' name spaces.
4495 *
4496 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4497 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4498 * lower=-1, upper=-1.
4499 */
4500 struct {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004501 int8_t lower; /* Display SoC in percentage. */
4502 int8_t upper; /* Display SoC in percentage. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004503 } sustain_soc;
4504} __ec_align4;
4505
4506/* Added in v2 */
4507struct ec_response_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004508 uint32_t mode; /* enum charge_control_mode */
4509 struct { /* Battery sustainer thresholds */
Scott Chao18141d8c2021-07-30 10:40:57 +08004510 int8_t lower;
4511 int8_t upper;
4512 } sustain_soc;
Simon Glassd3870a22023-11-09 08:43:30 -07004513 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
4514 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004515} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004516
4517/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004518
4519/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004520#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004521
4522/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004523 * Read data from the saved snapshot. If the subcmd parameter is
4524 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4525 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4526 * end of the previous snapshot.
4527 *
4528 * The params are only looked at in version >= 1 of this command. Prior
4529 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004530 *
4531 * Response is null-terminated string. Empty string, if there is no more
4532 * remaining output.
4533 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004534#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004535
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004536enum ec_console_read_subcmd {
4537 CONSOLE_READ_NEXT = 0,
4538 CONSOLE_READ_RECENT,
4539};
Duncan Laurieeb316852015-12-01 18:51:18 -08004540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004541struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004542 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004543} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004544
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004545/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004546
4547/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004548 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004549 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004550 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4551 * EC_RES_SUCCESS if the command was successful.
4552 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004553 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004554#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004555
Caveh Jalali024ffe32023-01-30 14:35:19 -08004556#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004557
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004558struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004559 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004560} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004561
Duncan Laurie433432b2013-06-03 10:38:22 -07004562/*****************************************************************************/
4563/* USB port mux control. */
4564
4565/*
4566 * Switch USB mux or return to automatic switching.
4567 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004568#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004569
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004570struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004571 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004572} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004573
4574/*****************************************************************************/
4575/* LDOs / FETs control. */
4576
4577enum ec_ldo_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004578 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4579 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
Duncan Laurie433432b2013-06-03 10:38:22 -07004580};
4581
4582/*
4583 * Switch on/off a LDO.
4584 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004585#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004586
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004587struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004588 uint8_t index;
4589 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004590} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004591
4592/*
4593 * Get LDO state.
4594 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004595#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004596
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004597struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004598 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004599} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004600
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004601struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004602 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004603} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004604
4605/*****************************************************************************/
4606/* Power info. */
4607
4608/*
4609 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004610 *
4611 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004612 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004613#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004614
Jett Rinkba2edaf2020-01-14 11:49:06 -07004615/*
4616 * v1 of EC_CMD_POWER_INFO
4617 */
4618enum system_power_source {
4619 /*
4620 * Haven't established which power source is used yet,
4621 * or no presence signals are available
4622 */
4623 POWER_SOURCE_UNKNOWN = 0,
4624 /* System is running on battery alone */
4625 POWER_SOURCE_BATTERY = 1,
4626 /* System is running on A/C alone */
4627 POWER_SOURCE_AC = 2,
4628 /* System is running on A/C and battery */
4629 POWER_SOURCE_AC_BATTERY = 3,
4630};
4631
4632struct ec_response_power_info_v1 {
4633 /* enum system_power_source */
4634 uint8_t system_power_source;
4635 /* Battery state-of-charge, 0-100, 0 if not present */
4636 uint8_t battery_soc;
4637 /* AC Adapter 100% rating, Watts */
4638 uint8_t ac_adapter_100pct;
4639 /* AC Adapter 10ms rating, Watts */
4640 uint8_t ac_adapter_10ms;
4641 /* Battery 1C rating, derated */
4642 uint8_t battery_1cd;
4643 /* Rest of Platform average, Watts */
4644 uint8_t rop_avg;
4645 /* Rest of Platform peak, Watts */
4646 uint8_t rop_peak;
4647 /* Nominal charger efficiency, % */
4648 uint8_t nominal_charger_eff;
4649 /* Rest of Platform VR Average Efficiency, % */
4650 uint8_t rop_avg_eff;
4651 /* Rest of Platform VR Peak Efficiency, % */
4652 uint8_t rop_peak_eff;
4653 /* SoC VR Efficiency at Average level, % */
4654 uint8_t soc_avg_eff;
4655 /* SoC VR Efficiency at Peak level, % */
4656 uint8_t soc_peak_eff;
4657 /* Intel-specific items */
4658 struct {
4659 /* Battery's level of DBPT support: 0, 2 */
4660 uint8_t batt_dbpt_support_level;
4661 /*
4662 * Maximum peak power from battery (10ms), Watts
4663 * If DBPT is not supported, this is 0
4664 */
4665 uint8_t batt_dbpt_max_peak_power;
4666 /*
4667 * Sustained peak power from battery, Watts
4668 * If DBPT is not supported, this is 0
4669 */
4670 uint8_t batt_dbpt_sus_peak_power;
4671 } intel;
4672} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004673
4674/*****************************************************************************/
4675/* I2C passthru command */
4676
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004677#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004678
Duncan Laurie433432b2013-06-03 10:38:22 -07004679/* Read data; if not present, message is a write */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004680#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004681
4682/* Mask for address */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004683#define EC_I2C_ADDR_MASK 0x3ff
Duncan Laurie433432b2013-06-03 10:38:22 -07004684
Caveh Jalali024ffe32023-01-30 14:35:19 -08004685#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4686#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004687
4688/* Any error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004689#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
Duncan Laurie433432b2013-06-03 10:38:22 -07004690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004691struct ec_params_i2c_passthru_msg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004692 uint16_t addr_flags; /* I2C peripheral address and flags */
4693 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004694} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004695
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004696struct ec_params_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004697 uint8_t port; /* I2C port number */
4698 uint8_t num_msgs; /* Number of messages */
Duncan Laurie433432b2013-06-03 10:38:22 -07004699 struct ec_params_i2c_passthru_msg msg[];
4700 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004701} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004702
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004703struct ec_response_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004704 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4705 uint8_t num_msgs; /* Number of messages processed */
4706 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004707} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004708
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004709/*****************************************************************************/
4710/* Power button hang detect */
4711
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004712#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004713
4714/* Reasons to start hang detection timer */
4715/* Power button pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004716#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004717
4718/* Lid closed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004719#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004720
Caveh Jalali024ffe32023-01-30 14:35:19 -08004721/* Lid opened */
4722#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004723
4724/* Start of AP S3->S0 transition (booting or resuming from suspend) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004725#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004726
4727/* Reasons to cancel hang detection */
4728
4729/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004730#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004731
4732/* Any host command from AP received */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004733#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004734
4735/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004736#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004737
4738/*
4739 * If this flag is set, all the other fields are ignored, and the hang detect
4740 * timer is started. This provides the AP a way to start the hang timer
4741 * without reconfiguring any of the other hang detect settings. Note that
4742 * you must previously have configured the timeouts.
4743 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004744#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004745
4746/*
4747 * If this flag is set, all the other fields are ignored (including
4748 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4749 * without reconfiguring any of the other hang detect settings.
4750 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004751#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004752
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004753struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004754 /* Flags; see EC_HANG_* */
4755 uint32_t flags;
4756
4757 /* Timeout in msec before generating host event, if enabled */
4758 uint16_t host_event_timeout_msec;
4759
4760 /* Timeout in msec before generating warm reboot, if enabled */
4761 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004762} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004763
4764/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004765/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004766
4767/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004768 * This is the single catch-all host command to exchange data regarding the
4769 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004770 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004771#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004772
4773/* Subcommands for this host command */
4774enum charge_state_command {
4775 CHARGE_STATE_CMD_GET_STATE,
4776 CHARGE_STATE_CMD_GET_PARAM,
4777 CHARGE_STATE_CMD_SET_PARAM,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004778 CHARGE_STATE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004779};
4780
4781/*
4782 * Known param numbers are defined here. Ranges are reserved for board-specific
4783 * params, which are handled by the particular implementations.
4784 */
4785enum charge_state_params {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004786 /* charger voltage limit */
4787 CS_PARAM_CHG_VOLTAGE,
4788
4789 /* charger current limit */
4790 CS_PARAM_CHG_CURRENT,
4791
4792 /* charger input current limit */
4793 CS_PARAM_CHG_INPUT_CURRENT,
4794
4795 /* charger-specific status */
4796 CS_PARAM_CHG_STATUS,
4797
4798 /* charger-specific options */
4799 CS_PARAM_CHG_OPTION,
4800
4801 /*
4802 * Check if power is limited due to low battery and / or a
4803 * weak external charger. READ ONLY.
4804 */
4805 CS_PARAM_LIMIT_POWER,
4806
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004807 /* How many so far? */
4808 CS_NUM_BASE_PARAMS,
4809
4810 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4811 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4812 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4813
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004814 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4815 CS_PARAM_DEBUG_MIN = 0x20000,
4816 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4817 CS_PARAM_DEBUG_MANUAL_MODE,
4818 CS_PARAM_DEBUG_SEEMS_DEAD,
4819 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4820 CS_PARAM_DEBUG_BATT_REMOVED,
4821 CS_PARAM_DEBUG_MANUAL_CURRENT,
4822 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4823 CS_PARAM_DEBUG_MAX = 0x2ffff,
4824
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004825 /* Other custom param ranges go here... */
4826};
4827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004828struct ec_params_charge_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004829 uint8_t cmd; /* enum charge_state_command */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004830 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004831 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004832
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004833 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004834 uint32_t param; /* enum charge_state_param */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004835 } get_param;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004836
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004837 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004838 uint32_t param; /* param to set */
4839 uint32_t value; /* value to set */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004840 } set_param;
4841 } __ec_todo_packed;
Caveh Jalali024ffe32023-01-30 14:35:19 -08004842 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004843} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004844
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004845struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004846 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004847 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004848 int ac;
4849 int chg_voltage;
4850 int chg_current;
4851 int chg_input_current;
4852 int batt_state_of_charge;
4853 } get_state;
4854
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004855 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004856 uint32_t value;
4857 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004858
4859 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004860 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004861} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004862
Duncan Laurie433432b2013-06-03 10:38:22 -07004863/*
4864 * Set maximum battery charging current.
4865 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004866#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Tim Van Pattencab60602023-02-24 12:27:04 -07004867#define EC_VER_CHARGE_CURRENT_LIMIT 1
Duncan Laurie433432b2013-06-03 10:38:22 -07004868
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004869struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004870 uint32_t limit; /* in mA */
Caveh Jalali839ada12022-10-31 23:16:48 -07004871} __ec_align4;
Tim Van Pattencab60602023-02-24 12:27:04 -07004872
Caveh Jalali839ada12022-10-31 23:16:48 -07004873struct ec_params_current_limit_v1 {
4874 uint32_t limit; /* in mA */
Tim Van Pattencab60602023-02-24 12:27:04 -07004875 /*
4876 * Battery state of charge is the minimum charge percentage at which
4877 * the battery charge current limit will apply.
4878 * When not set, the limit will apply regardless of state of charge.
4879 */
4880 uint8_t battery_soc; /* battery state of charge, 0-100 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004881} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004882
4883/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004884 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004885 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004886#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004887
Duncan Laurieeb316852015-12-01 18:51:18 -08004888/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004889struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004890 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4891 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004892} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004893
Duncan Laurieeb316852015-12-01 18:51:18 -08004894#define EC_POWER_LIMIT_NONE 0xffff
4895
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004896/*
4897 * Set maximum voltage & current of a dedicated charge port
4898 */
4899#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4900
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004901struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004902 uint16_t current_lim; /* in mA */
4903 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004904} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004905
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08004906/*
4907 * Get and set charging splashscreen variables
4908 */
4909#define EC_CMD_CHARGESPLASH 0x00A5
4910
4911enum ec_chargesplash_cmd {
4912 /* Get the current state variables */
4913 EC_CHARGESPLASH_GET_STATE = 0,
4914
4915 /* Indicate initialization of the display loop */
4916 EC_CHARGESPLASH_DISPLAY_READY,
4917
4918 /* Manually put the EC into the requested state */
4919 EC_CHARGESPLASH_REQUEST,
4920
4921 /* Reset all state variables */
4922 EC_CHARGESPLASH_RESET,
4923
4924 /* Manually trigger a lockout */
4925 EC_CHARGESPLASH_LOCKOUT,
4926};
4927
4928struct __ec_align1 ec_params_chargesplash {
4929 /* enum ec_chargesplash_cmd */
4930 uint8_t cmd;
4931};
4932
4933struct __ec_align1 ec_response_chargesplash {
4934 uint8_t requested;
4935 uint8_t display_initialized;
4936 uint8_t locked_out;
4937};
4938
Duncan Laurieeb316852015-12-01 18:51:18 -08004939/*****************************************************************************/
4940/* Hibernate/Deep Sleep Commands */
4941
4942/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004943#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004944
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004945struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004946 /*
4947 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4948 * current settings without changing them.
4949 */
4950 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004951} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004952
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004953struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004954 /*
4955 * The current time in seconds in which the system has been in the G3
4956 * state. This value is reset if the EC transitions out of G3.
4957 */
4958 uint32_t time_g3;
4959
4960 /*
4961 * The current time remaining in seconds until the EC should hibernate.
4962 * This value is also reset if the EC transitions out of G3.
4963 */
4964 uint32_t time_remaining;
4965
4966 /*
4967 * The current time in seconds that the EC should wait in G3 before
4968 * hibernating.
4969 */
4970 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004971} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004972
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004973/* Inform the EC when entering a sleep state */
4974#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4975
4976enum host_sleep_event {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004977 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4978 HOST_SLEEP_EVENT_S3_RESUME = 2,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004979 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Caveh Jalali024ffe32023-01-30 14:35:19 -08004980 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004981 /* S3 suspend with additional enabled wake sources */
4982 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004983};
4984
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004985struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004986 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004987} __ec_align1;
4988
4989/*
4990 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4991 * transition failures
4992 */
4993#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4994
4995/* Disable timeout detection for this sleep transition */
4996#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4997
4998struct ec_params_host_sleep_event_v1 {
4999 /* The type of sleep being entered or exited. */
5000 uint8_t sleep_event;
5001
5002 /* Padding */
5003 uint8_t reserved;
5004 union {
5005 /* Parameters that apply for suspend messages. */
5006 struct {
5007 /*
5008 * The timeout in milliseconds between when this message
5009 * is received and when the EC will declare sleep
5010 * transition failure if the sleep signal is not
5011 * asserted.
5012 */
5013 uint16_t sleep_timeout_ms;
5014 } suspend_params;
5015
5016 /* No parameters for non-suspend messages. */
5017 };
5018} __ec_align2;
5019
5020/* A timeout occurred when this bit is set */
5021#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
5022
5023/*
5024 * The mask defining which bits correspond to the number of sleep transitions,
5025 * as well as the maximum number of suspend line transitions that will be
5026 * reported back to the host.
5027 */
5028#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
5029
5030struct ec_response_host_sleep_event_v1 {
5031 union {
5032 /* Response fields that apply for resume messages. */
5033 struct {
5034 /*
5035 * The number of sleep power signal transitions that
5036 * occurred since the suspend message. The high bit
5037 * indicates a timeout occurred.
5038 */
5039 uint32_t sleep_transitions;
5040 } resume_response;
5041
5042 /* No response fields for non-resume messages. */
5043 };
5044} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005045
5046/*****************************************************************************/
5047/* Device events */
5048#define EC_CMD_DEVICE_EVENT 0x00AA
5049
5050enum ec_device_event {
5051 EC_DEVICE_EVENT_TRACKPAD,
5052 EC_DEVICE_EVENT_DSP,
5053 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005054 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005055};
5056
5057enum ec_device_event_param {
5058 /* Get and clear pending device events */
5059 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
5060 /* Get device event mask */
5061 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
5062 /* Set device event mask */
5063 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
5064};
5065
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005066#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005067
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005068struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005069 uint32_t event_mask;
5070 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005071} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005072
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005073struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005074 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005075} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005076
Duncan Laurie433432b2013-06-03 10:38:22 -07005077/*****************************************************************************/
Caveh Jalali839ada12022-10-31 23:16:48 -07005078/* Get s0ix counter */
5079#define EC_CMD_GET_S0IX_COUNTER 0x00AB
5080
5081/* Flag use to reset the counter */
5082#define EC_S0IX_COUNTER_RESET 0x1
5083
5084struct ec_params_s0ix_cnt {
5085 /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */
5086 uint32_t flags;
5087} __ec_align4;
5088
5089struct ec_response_s0ix_cnt {
5090 /* Value of the s0ix_counter */
5091 uint32_t s0ix_counter;
5092} __ec_align4;
5093
5094/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07005095/* Smart battery pass-through */
5096
Caveh Jalali839ada12022-10-31 23:16:48 -07005097/* Get / Set 16-bit smart battery registers - OBSOLETE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005098#define EC_CMD_SB_READ_WORD 0x00B0
5099#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07005100
5101/* Get / Set string smart battery parameters
Caveh Jalali839ada12022-10-31 23:16:48 -07005102 * formatted as SMBUS "block". - OBSOLETE
Duncan Laurie433432b2013-06-03 10:38:22 -07005103 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005104#define EC_CMD_SB_READ_BLOCK 0x00B2
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005105#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07005106
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005107/*****************************************************************************/
5108/* Battery vendor parameters
5109 *
5110 * Get or set vendor-specific parameters in the battery. Implementations may
5111 * differ between boards or batteries. On a set operation, the response
5112 * contains the actual value set, which may be rounded or clipped from the
5113 * requested value.
5114 */
5115
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005116#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005117
5118enum ec_battery_vendor_param_mode {
5119 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5120 BATTERY_VENDOR_PARAM_MODE_SET,
5121};
5122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005123struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005124 uint32_t param;
5125 uint32_t value;
5126 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005127} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005128
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005129struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005130 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005131} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005132
5133/*****************************************************************************/
5134/*
Caveh Jalali839ada12022-10-31 23:16:48 -07005135 * Smart Battery Firmware Update Command - OBSOLETE
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005136 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005137#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005138
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005139/*
5140 * Entering Verified Boot Mode Command
5141 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5142 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07005143 *
5144 * EC no longer needs to know what mode vboot has entered,
5145 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005146 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005147#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005148
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005149struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005150 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005151} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005152
Caveh Jalali024ffe32023-01-30 14:35:19 -08005153#define VBOOT_MODE_NORMAL 0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005154#define VBOOT_MODE_DEVELOPER 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08005155#define VBOOT_MODE_RECOVERY 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005156
Duncan Laurie433432b2013-06-03 10:38:22 -07005157/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07005158/*
5159 * I2C passthru protection command: Protects I2C tunnels against access on
5160 * certain addresses (board-specific).
5161 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005162#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07005163
5164enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005165 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5166 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5167 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005168};
5169
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005170struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005171 uint8_t subcmd;
Caveh Jalali024ffe32023-01-30 14:35:19 -08005172 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005173} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005174
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005175struct ec_response_i2c_passthru_protect {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005176 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005177} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005178
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005179/*****************************************************************************/
5180/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005181 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005182 *
5183 * These commands are for sending and receiving message via HDMI CEC
5184 */
5185
Simon Glassd3870a22023-11-09 08:43:30 -07005186#define EC_CEC_MAX_PORTS 16
5187
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005188#define MAX_CEC_MSG_LEN 16
5189
Simon Glassd3870a22023-11-09 08:43:30 -07005190/*
5191 * Helper macros for packing/unpacking cec_events.
5192 * bits[27:0] : bitmask of events from enum mkbp_cec_event
5193 * bits[31:28]: port number
5194 */
5195#define EC_MKBP_EVENT_CEC_PACK(events, port) \
5196 (((events)&GENMASK(27, 0)) | (((port)&0xf) << 28))
5197#define EC_MKBP_EVENT_CEC_GET_EVENTS(event) ((event)&GENMASK(27, 0))
5198#define EC_MKBP_EVENT_CEC_GET_PORT(event) (((event) >> 28) & 0xf)
5199
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005200/* CEC message from the AP to be written on the CEC bus */
5201#define EC_CMD_CEC_WRITE_MSG 0x00B8
5202
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005203/**
5204 * struct ec_params_cec_write - Message to write to the CEC bus
5205 * @msg: message content to write to the CEC bus
5206 */
5207struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005208 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005209} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005210
Simon Glassd3870a22023-11-09 08:43:30 -07005211/**
5212 * struct ec_params_cec_write_v1 - Message to write to the CEC bus
5213 * @port: CEC port to write the message on
5214 * @msg_len: length of msg in bytes
5215 * @msg: message content to write to the CEC bus
5216 */
5217struct ec_params_cec_write_v1 {
5218 uint8_t port;
5219 uint8_t msg_len;
5220 uint8_t msg[MAX_CEC_MSG_LEN];
5221} __ec_align1;
5222
5223/* CEC message read from a CEC bus reported back to the AP */
5224#define EC_CMD_CEC_READ_MSG 0x00B9
5225
5226/**
5227 * struct ec_params_cec_read - Read a message from the CEC bus
5228 * @port: CEC port to read a message on
5229 */
5230struct ec_params_cec_read {
5231 uint8_t port;
5232} __ec_align1;
5233
5234/**
5235 * struct ec_response_cec_read - Message read from the CEC bus
5236 * @msg_len: length of msg in bytes
5237 * @msg: message content read from the CEC bus
5238 */
5239struct ec_response_cec_read {
5240 uint8_t msg_len;
5241 uint8_t msg[MAX_CEC_MSG_LEN];
5242} __ec_align1;
5243
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005244/* Set various CEC parameters */
5245#define EC_CMD_CEC_SET 0x00BA
5246
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005247/**
5248 * struct ec_params_cec_set - CEC parameters set
5249 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
Simon Glassd3870a22023-11-09 08:43:30 -07005250 * @port: CEC port to set the parameter on
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005251 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5252 * or 1 to enable CEC functionality, in case cmd is
5253 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5254 * address between 0 and 15 or 0xff to unregister
5255 */
5256struct ec_params_cec_set {
Simon Glassd3870a22023-11-09 08:43:30 -07005257 uint8_t cmd : 4; /* enum cec_command */
5258 uint8_t port : 4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005259 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005260} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005261
5262/* Read various CEC parameters */
5263#define EC_CMD_CEC_GET 0x00BB
5264
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005265/**
5266 * struct ec_params_cec_get - CEC parameters get
5267 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
Simon Glassd3870a22023-11-09 08:43:30 -07005268 * @port: CEC port to get the parameter on
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005269 */
5270struct ec_params_cec_get {
Simon Glassd3870a22023-11-09 08:43:30 -07005271 uint8_t cmd : 4; /* enum cec_command */
5272 uint8_t port : 4;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005273} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005274
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005275/**
5276 * struct ec_response_cec_get - CEC parameters get response
5277 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5278 * disabled or 1 if CEC functionality is enabled,
5279 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5280 * configured logical address between 0 and 15 or 0xff if unregistered
5281 */
5282struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005283 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005284} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005285
Simon Glassd3870a22023-11-09 08:43:30 -07005286/* Get the number of CEC ports */
5287#define EC_CMD_CEC_PORT_COUNT 0x00C1
5288
5289/**
5290 * struct ec_response_cec_port_count - CEC port count response
5291 * @port_count: number of CEC ports
5292 */
5293struct ec_response_cec_port_count {
5294 uint8_t port_count;
5295} __ec_align1;
5296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005297/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005298enum cec_command {
5299 /* CEC reading, writing and events enable */
5300 CEC_CMD_ENABLE,
5301 /* CEC logical address */
5302 CEC_CMD_LOGICAL_ADDRESS,
5303};
5304
5305/* Events from CEC to AP */
5306enum mkbp_cec_event {
5307 /* Outgoing message was acknowledged by a follower */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005308 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005309 /* Outgoing message was not acknowledged */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005310 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Simon Glassd3870a22023-11-09 08:43:30 -07005311 /* Incoming message can be read out by AP */
5312 EC_MKBP_CEC_HAVE_DATA = BIT(2),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005313};
5314
Gwendal Grignou880b4582016-06-20 08:49:25 -07005315/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005316
Jett Rinkba2edaf2020-01-14 11:49:06 -07005317/* Commands for audio codec. */
5318#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005319
Jett Rinkba2edaf2020-01-14 11:49:06 -07005320enum ec_codec_subcmd {
5321 EC_CODEC_GET_CAPABILITIES = 0x0,
5322 EC_CODEC_GET_SHM_ADDR = 0x1,
5323 EC_CODEC_SET_SHM_ADDR = 0x2,
5324 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005325};
5326
Jett Rinkba2edaf2020-01-14 11:49:06 -07005327enum ec_codec_cap {
5328 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5329 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5330 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005331};
5332
Jett Rinkba2edaf2020-01-14 11:49:06 -07005333enum ec_codec_shm_id {
5334 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5335 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5336 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005337};
5338
Jett Rinkba2edaf2020-01-14 11:49:06 -07005339enum ec_codec_shm_type {
5340 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5341 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005342};
5343
Jett Rinkba2edaf2020-01-14 11:49:06 -07005344struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5345 uint8_t shm_id;
5346 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005347};
5348
Jett Rinkba2edaf2020-01-14 11:49:06 -07005349struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5350 uint64_t phys_addr;
5351 uint32_t len;
5352 uint8_t shm_id;
5353 uint8_t reserved[3];
5354};
5355
5356struct __ec_align4 ec_param_ec_codec {
5357 uint8_t cmd; /* enum ec_codec_subcmd */
5358 uint8_t reserved[3];
5359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005360 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005361 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5362 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005363 };
5364};
5365
Jett Rinkba2edaf2020-01-14 11:49:06 -07005366struct __ec_align4 ec_response_ec_codec_get_capabilities {
5367 uint32_t capabilities;
5368};
5369
5370struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5371 uint64_t phys_addr;
5372 uint32_t len;
5373 uint8_t type;
5374 uint8_t reserved[3];
5375};
5376
5377/*****************************************************************************/
5378
5379/* Commands for DMIC on audio codec. */
5380#define EC_CMD_EC_CODEC_DMIC 0x00BD
5381
5382enum ec_codec_dmic_subcmd {
5383 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5384 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5385 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5386 EC_CODEC_DMIC_SUBCMD_COUNT,
5387};
5388
5389enum ec_codec_dmic_channel {
5390 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5391 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5392 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5393 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5394 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5395 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5396 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5397 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5398 EC_CODEC_DMIC_CHANNEL_COUNT,
5399};
5400
5401struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5402 uint8_t channel; /* enum ec_codec_dmic_channel */
5403 uint8_t gain;
5404 uint8_t reserved[2];
5405};
5406
5407struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5408 uint8_t channel; /* enum ec_codec_dmic_channel */
5409 uint8_t reserved[3];
5410};
5411
5412struct __ec_align4 ec_param_ec_codec_dmic {
5413 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5414 uint8_t reserved[3];
5415
5416 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005417 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5418 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005419 };
5420};
5421
5422struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5423 uint8_t max_gain;
5424};
5425
5426struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5427 uint8_t gain;
5428};
5429
5430/*****************************************************************************/
5431
5432/* Commands for I2S RX on audio codec. */
5433
5434#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5435
5436enum ec_codec_i2s_rx_subcmd {
5437 EC_CODEC_I2S_RX_ENABLE = 0x0,
5438 EC_CODEC_I2S_RX_DISABLE = 0x1,
5439 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5440 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5441 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005442 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005443 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5444};
5445
5446enum ec_codec_i2s_rx_sample_depth {
5447 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5448 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5449 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5450};
5451
5452enum ec_codec_i2s_rx_daifmt {
5453 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5454 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5455 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5456 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5457};
5458
5459struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5460 uint8_t depth;
5461 uint8_t reserved[3];
5462};
5463
5464struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5465 uint8_t left;
5466 uint8_t right;
5467 uint8_t reserved[2];
5468};
5469
5470struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5471 uint8_t daifmt;
5472 uint8_t reserved[3];
5473};
5474
5475struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5476 uint32_t bclk;
5477};
5478
5479struct __ec_align4 ec_param_ec_codec_i2s_rx {
5480 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5481 uint8_t reserved[3];
5482
5483 union {
5484 struct ec_param_ec_codec_i2s_rx_set_sample_depth
Caveh Jalali024ffe32023-01-30 14:35:19 -08005485 set_sample_depth_param;
5486 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5487 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005488 };
5489};
5490
5491/*****************************************************************************/
5492/* Commands for WoV on audio codec. */
5493
5494#define EC_CMD_EC_CODEC_WOV 0x00BF
5495
5496enum ec_codec_wov_subcmd {
5497 EC_CODEC_WOV_SET_LANG = 0x0,
5498 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5499 EC_CODEC_WOV_GET_LANG = 0x2,
5500 EC_CODEC_WOV_ENABLE = 0x3,
5501 EC_CODEC_WOV_DISABLE = 0x4,
5502 EC_CODEC_WOV_READ_AUDIO = 0x5,
5503 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5504 EC_CODEC_WOV_SUBCMD_COUNT,
5505};
5506
5507/*
5508 * @hash is SHA256 of the whole language model.
5509 * @total_len indicates the length of whole language model.
5510 * @offset is the cursor from the beginning of the model.
5511 * @buf is the packet buffer.
5512 * @len denotes how many bytes in the buf.
5513 */
5514struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5515 uint8_t hash[32];
5516 uint32_t total_len;
5517 uint32_t offset;
5518 uint8_t buf[128];
5519 uint32_t len;
5520};
5521
5522struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5523 uint8_t hash[32];
5524 uint32_t total_len;
5525};
5526
5527struct __ec_align4 ec_param_ec_codec_wov {
5528 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5529 uint8_t reserved[3];
5530
5531 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005532 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5533 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005534 };
5535};
5536
5537struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5538 uint8_t hash[32];
5539};
5540
5541struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5542 uint8_t buf[128];
5543 uint32_t len;
5544};
5545
5546struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5547 uint32_t offset;
5548 uint32_t len;
5549};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005550
5551/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005552/* Commands for PoE PSE controller */
5553
5554#define EC_CMD_PSE 0x00C0
5555
5556enum ec_pse_subcmd {
5557 EC_PSE_STATUS = 0x0,
5558 EC_PSE_ENABLE = 0x1,
5559 EC_PSE_DISABLE = 0x2,
5560 EC_PSE_SUBCMD_COUNT,
5561};
5562
5563struct __ec_align1 ec_params_pse {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005564 uint8_t cmd; /* enum ec_pse_subcmd */
5565 uint8_t port; /* PSE port */
Yidi Lin42f79592020-09-21 18:04:10 +08005566};
5567
5568enum ec_pse_status {
5569 EC_PSE_STATUS_DISABLED = 0x0,
5570 EC_PSE_STATUS_ENABLED = 0x1,
5571 EC_PSE_STATUS_POWERED = 0x2,
5572};
5573
5574struct __ec_align1 ec_response_pse_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005575 uint8_t status; /* enum ec_pse_status */
Yidi Lin42f79592020-09-21 18:04:10 +08005576};
5577
5578/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005579/* System commands */
5580
5581/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005582 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5583 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005584 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005585#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005586
5587/* Command */
5588enum ec_reboot_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005589 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5590 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5591 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005592 /* (command 3 was jump to RW-B) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005593 EC_REBOOT_COLD = 4, /* Cold-reboot */
5594 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5595 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005596 /*
5597 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5598 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5599 */
5600 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005601 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5602 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005603};
5604
5605/* Flags for ec_params_reboot_ec.reboot_flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005606#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5607#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5608#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5609#define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005610
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005611struct ec_params_reboot_ec {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005612 uint8_t cmd; /* enum ec_reboot_cmd */
5613 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005614} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005615
Duncan Laurie433432b2013-06-03 10:38:22 -07005616/*
5617 * Get information on last EC panic.
5618 *
5619 * Returns variable-length platform-dependent panic information. See panic.h
5620 * for details.
5621 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005622#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005623
Simon Glassd3870a22023-11-09 08:43:30 -07005624struct ec_params_get_panic_info_v1 {
5625 /* Do not modify PANIC_DATA_FLAG_OLD_HOSTCMD when reading panic info */
5626 uint8_t preserve_old_hostcmd_flag;
5627} __ec_align1;
5628
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005629/*****************************************************************************/
5630/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005631 * Special commands
5632 *
5633 * These do not follow the normal rules for commands. See each command for
5634 * details.
5635 */
5636
5637/*
5638 * Reboot NOW
5639 *
5640 * This command will work even when the EC LPC interface is busy, because the
5641 * reboot command is processed at interrupt level. Note that when the EC
5642 * reboots, the host will reboot too, so there is no response to this command.
5643 *
5644 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5645 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005646#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005647
5648/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005649 * Resend last response (not supported on LPC).
5650 *
5651 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5652 * there was no previous command, or the previous command's response was too
5653 * big to save.
5654 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005655#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005656
5657/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005658 * This header byte on a command indicate version 0. Any header byte less
5659 * than this means that we are talking to an old EC which doesn't support
5660 * versioning. In that case, we assume version 0.
5661 *
5662 * Header bytes greater than this indicate a later version. For example,
5663 * EC_CMD_VERSION0 + 1 means we are using version 1.
5664 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005665 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005666 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005667#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005668
Caveh Jalali839ada12022-10-31 23:16:48 -07005669/*
5670 * Memory Dump Commands
5671 *
5672 * Since the HOSTCMD response size is limited, depending on the
5673 * protocol, retrieving a memory dump is split into 3 commands.
5674 *
5675 * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries,
5676 * and the total dump size.
5677 * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given
5678 * memory dump entry index.
5679 * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given
5680 * address. The address and size must be within the bounds of the given
5681 * memory dump entry index. Each response is limited to the max response size
5682 * of the host protocol, so this may need to be called repeatedly to retrieve
5683 * the entire memory dump entry.
5684 *
5685 * Memory entries may overlap and may be out of order.
5686 * The host should check for overlaps to optimize transfer rate.
5687 */
5688#define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD
5689struct ec_response_memory_dump_get_metadata {
5690 uint16_t memory_dump_entry_count;
5691 uint32_t memory_dump_total_size;
5692} __ec_align4;
5693
5694#define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE
5695struct ec_params_memory_dump_get_entry_info {
5696 uint16_t memory_dump_entry_index;
5697} __ec_align4;
5698
5699struct ec_response_memory_dump_get_entry_info {
5700 uint32_t address;
5701 uint32_t size;
5702} __ec_align4;
5703
5704#define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF
5705
5706struct ec_params_memory_dump_read_memory {
5707 uint16_t memory_dump_entry_index;
5708 uint32_t address;
5709 uint32_t size;
5710} __ec_align4;
5711
5712/*
5713 * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into
5714 * host_cmd_handler_args.response and host_cmd_handler_args.response_size.
5715 */
5716
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005717/*****************************************************************************/
5718/*
5719 * PD commands
5720 *
5721 * These commands are for PD MCU communication.
5722 */
5723
5724/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005725#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005726#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005727
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005728enum pd_charge_state {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005729 /* Don't change charge state */
5730 PD_CHARGE_NO_CHANGE = 0,
5731
5732 /* No charging allowed */
5733 PD_CHARGE_NONE,
5734
5735 /* 5V charging only */
5736 PD_CHARGE_5V,
5737
5738 /* Charge at max voltage */
5739 PD_CHARGE_MAX,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005740};
5741
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005742/* Status of EC being sent to PD */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005743#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005744
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005745struct ec_params_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005746 /* EC status */
5747 uint8_t status;
5748
5749 /* battery state of charge */
5750 int8_t batt_soc;
5751
5752 /* charging state (from enum pd_charge_state) */
5753 uint8_t charge_state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005754} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005755
5756/* Status of PD being sent back to EC */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005757#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5758#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005759#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005760#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5761#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5762#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5763#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
5764#define PD_STATUS_EC_INT_ACTIVE \
5765 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005766struct ec_response_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005767 /* input current limit */
5768 uint32_t curr_lim_ma;
5769
5770 /* PD MCU status */
5771 uint16_t status;
5772
5773 /* active charging port */
5774 int8_t active_charge_port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005775} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005776
5777/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005778#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005779
5780/* PD MCU host event status bits */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005781#define PD_EVENT_UPDATE_DEVICE BIT(0)
5782#define PD_EVENT_POWER_CHANGE BIT(1)
5783#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5784#define PD_EVENT_DATA_SWAP BIT(3)
5785#define PD_EVENT_TYPEC BIT(4)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005786
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005787struct ec_response_host_event_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005788 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005789} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005790
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005791/*
5792 * Set USB type-C port role and muxes
5793 *
5794 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5795 *
5796 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5797 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005798#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005799
5800enum usb_pd_control_role {
5801 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5802 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5803 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5804 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5805 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005806 USB_PD_CTRL_ROLE_FREEZE = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005807 USB_PD_CTRL_ROLE_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005808};
5809
5810enum usb_pd_control_mux {
5811 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5812 USB_PD_CTRL_MUX_NONE = 1,
5813 USB_PD_CTRL_MUX_USB = 2,
5814 USB_PD_CTRL_MUX_DP = 3,
5815 USB_PD_CTRL_MUX_DOCK = 4,
5816 USB_PD_CTRL_MUX_AUTO = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005817 USB_PD_CTRL_MUX_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005818};
5819
Duncan Laurieeb316852015-12-01 18:51:18 -08005820enum usb_pd_control_swap {
5821 USB_PD_CTRL_SWAP_NONE = 0,
5822 USB_PD_CTRL_SWAP_DATA = 1,
5823 USB_PD_CTRL_SWAP_POWER = 2,
5824 USB_PD_CTRL_SWAP_VCONN = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005825 USB_PD_CTRL_SWAP_COUNT,
Duncan Laurieeb316852015-12-01 18:51:18 -08005826};
5827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005828struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005829 uint8_t port;
5830 uint8_t role;
5831 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005832 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005833} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005834
Caveh Jalali024ffe32023-01-30 14:35:19 -08005835#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5836#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005837#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005838
Caveh Jalali024ffe32023-01-30 14:35:19 -08005839#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5840#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5841#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5842#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5843#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5844#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005845/* Partner unconstrained power */
5846#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
Duncan Laurieeb316852015-12-01 18:51:18 -08005847
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005848struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005849 uint8_t enabled;
5850 uint8_t role;
5851 uint8_t polarity;
5852 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005853} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005854
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005855struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005856 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005857 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005858 uint8_t polarity;
5859 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005860} __ec_align1;
5861
Jett Rinkba2edaf2020-01-14 11:49:06 -07005862/* Possible port partner connections based on CC line states */
5863enum pd_cc_states {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005864 PD_CC_NONE = 0, /* No port partner attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005865
5866 /* From DFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005867 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
5868 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5869 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5870 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005871
5872 /* From UFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005873 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
5874 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005875};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005876
Jett Rinkba2edaf2020-01-14 11:49:06 -07005877/* Active/Passive Cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005878#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005879/* Optical/Non-optical cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005880#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005881/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005882#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005883/* Active Link Uni-Direction */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005884#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Caveh Jalali839ada12022-10-31 23:16:48 -07005885/* Retimer/Redriver cable */
5886#define USB_PD_CTRL_RETIMER_CABLE BIT(4)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005887
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005888struct ec_response_usb_pd_control_v2 {
5889 uint8_t enabled;
5890 uint8_t role;
5891 uint8_t polarity;
5892 char state[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08005893 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5894 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
5895 uint8_t reserved; /* Reserved for future use */
5896 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5897 uint8_t cable_speed; /* TBT_SS_* cable speed */
5898 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005899} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005900
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005901#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005902
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005903/* Maximum number of PD ports on a device, num_ports will be <= this */
5904#define EC_USB_PD_MAX_PORTS 8
5905
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005906struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005907 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005908} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005909
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005910#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005911
5912#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005913struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005914 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005915} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005916
5917enum usb_chg_type {
5918 USB_CHG_TYPE_NONE,
5919 USB_CHG_TYPE_PD,
5920 USB_CHG_TYPE_C,
5921 USB_CHG_TYPE_PROPRIETARY,
5922 USB_CHG_TYPE_BC12_DCP,
5923 USB_CHG_TYPE_BC12_CDP,
5924 USB_CHG_TYPE_BC12_SDP,
5925 USB_CHG_TYPE_OTHER,
5926 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005927 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005928 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005929};
5930enum usb_power_roles {
5931 USB_PD_PORT_POWER_DISCONNECTED,
5932 USB_PD_PORT_POWER_SOURCE,
5933 USB_PD_PORT_POWER_SINK,
5934 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5935};
5936
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005937struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005938 uint16_t voltage_max;
5939 uint16_t voltage_now;
5940 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005941 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005942} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005943
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005944struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005945 uint8_t role;
5946 uint8_t type;
5947 uint8_t dualrole;
5948 uint8_t reserved1;
5949 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005950 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005951} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005952
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005953/*
5954 * This command will return the number of USB PD charge port + the number
5955 * of dedicated port present.
5956 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5957 */
5958#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005959struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005960 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005961} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005962
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08005963/*
5964 * This command enable/disable dynamic PDO selection.
5965 */
5966#define EC_CMD_USB_PD_DPS_CONTROL 0x0106
5967
5968struct ec_params_usb_pd_dps_control {
5969 uint8_t enable;
5970} __ec_align1;
5971
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005972/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005973#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005974
5975enum usb_pd_fw_update_cmds {
5976 USB_PD_FW_REBOOT,
5977 USB_PD_FW_FLASH_ERASE,
5978 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005979 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005980};
5981
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005982struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005983 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005984 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005985 uint8_t port;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005986
5987 /* Size to write in bytes */
5988 uint32_t size;
5989
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005990 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005991} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005992
5993/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005994#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005995/* RW hash is first 20 bytes of SHA-256 of RW section */
5996#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005997struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005998 uint16_t dev_id;
5999 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006000
6001 /*
6002 * Reserved for alignment of current_image
6003 * TODO(rspangler) but it's not aligned!
6004 * Should have been reserved[2].
6005 */
6006 uint8_t reserved;
6007
6008 /* One of ec_image */
6009 uint32_t current_image;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006010} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006011
6012/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006013#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006014
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006015struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006016 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006017} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006018
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006019/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006020#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006021struct ec_params_usb_pd_discovery_entry {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006022 uint16_t vid; /* USB-IF VID */
6023 uint16_t pid; /* USB-IF PID */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006024 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006025} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006026
6027/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006028#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006029
6030/* Negative port parameters have special meaning */
6031enum usb_pd_override_ports {
Simon Glassd3870a22023-11-09 08:43:30 -07006032 /*
6033 * DONT_CHARGE is for all ports. Thus it's persistent across plug-in
6034 * or plug-out.
6035 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006036 OVERRIDE_DONT_CHARGE = -2,
6037 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07006038 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006039};
6040
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006041struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006042 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006043} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006044
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006045/*
6046 * Read (and delete) one entry of PD event log.
6047 * TODO(crbug.com/751742): Make this host command more generic to accommodate
6048 * future non-PD logs that use the same internal EC event_log.
6049 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006050#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006051
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006052struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006053 uint32_t timestamp; /* relative timestamp in milliseconds */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006054 uint8_t type; /* event type : see PD_EVENT_xx below */
6055 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
6056 uint16_t data; /* type-defined data payload */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006057 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006058} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006059
6060/* The timestamp is the microsecond counter shifted to get about a ms. */
6061#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
6062
Caveh Jalali024ffe32023-01-30 14:35:19 -08006063#define PD_LOG_SIZE_MASK 0x1f
6064#define PD_LOG_PORT_MASK 0xe0
6065#define PD_LOG_PORT_SHIFT 5
6066#define PD_LOG_PORT_SIZE(port, size) \
6067 (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK))
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006068#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006069#define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006070
6071/* PD event log : entry types */
6072/* PD MCU events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006073#define PD_EVENT_MCU_BASE 0x00
6074#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
6075#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006076/* Reserved for custom board event */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006077#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006078/* PD generic accessory events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006079#define PD_EVENT_ACC_BASE 0x20
6080#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
6081#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006082/* PD power supply events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006083#define PD_EVENT_PS_BASE 0x40
6084#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006085/* PD video dongles events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006086#define PD_EVENT_VIDEO_BASE 0x60
6087#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
6088#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006089/* Returned in the "type" field, when there is no entry available */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006090#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006091
6092/*
6093 * PD_EVENT_MCU_CHARGE event definition :
6094 * the payload is "struct usb_chg_measures"
6095 * the data field contains the port state flags as defined below :
6096 */
6097/* Port partner is a dual role device */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006098#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006099/* Port is the pending override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006100#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006101/* Port is the override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006102#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006103/* Charger type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006104#define CHARGE_FLAGS_TYPE_SHIFT 3
6105#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006106/* Power delivery role */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006107#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006108
6109/*
6110 * PD_EVENT_PS_FAULT data field flags definition :
6111 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006112#define PS_FAULT_OCP 1
6113#define PS_FAULT_FAST_OCP 2
6114#define PS_FAULT_OVP 3
6115#define PS_FAULT_DISCH 4
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006116
6117/*
6118 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
6119 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006120struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006121 uint8_t major;
6122 uint8_t minor;
6123 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006124} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006126struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006127 uint8_t family[2];
6128 uint8_t chipid[2];
6129 struct mcdp_version irom;
6130 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006131} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006132
6133/* struct mcdp_info field decoding */
6134#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
6135#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
6136
6137/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006138#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006139struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006140 uint16_t svid_idx; /* SVID index to get */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006141 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006142} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006143
Caveh Jalali839ada12022-10-31 23:16:48 -07006144#define VDO_MAX_SIZE 7
6145/* Max number of VDM data objects without VDM header */
6146#define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1)
6147
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006148struct ec_params_usb_pd_get_mode_response {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006149 uint16_t svid; /* SVID */
6150 uint16_t opos; /* Object Position */
Caveh Jalali839ada12022-10-31 23:16:48 -07006151 uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006152} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006153
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006154#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006155
6156enum pd_mode_cmd {
6157 PD_EXIT_MODE = 0,
6158 PD_ENTER_MODE = 1,
6159 /* Not a command. Do NOT remove. */
6160 PD_MODE_CMD_COUNT,
6161};
6162
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006163struct ec_params_usb_pd_set_mode_request {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006164 uint32_t cmd; /* enum pd_mode_cmd */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006165 uint16_t svid; /* SVID to set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006166 uint8_t opos; /* Object Position */
6167 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006168} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006169
6170/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006171#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006172
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006173struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006174 uint8_t type; /* event type : see PD_EVENT_xx above */
6175 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006176} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006177
Gwendal Grignou880b4582016-06-20 08:49:25 -07006178/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006179#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07006180
6181enum ec_pd_control_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006182 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6183 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6184 PD_RESET, /* Force reset the PD chip */
6185 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6186 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006187};
6188
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006189struct ec_params_pd_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006190 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006191 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006192} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07006193
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006194/* Get info about USB-C SS muxes */
6195#define EC_CMD_USB_PD_MUX_INFO 0x011A
6196
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006197struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006198 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006199} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006200
6201/* Flags representing mux state */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006202#define USB_PD_MUX_NONE 0 /* Open switch */
6203#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6204#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6205#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6206#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6207#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6208#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6209#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6210#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006211#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006212#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006213
6214/* USB-C Dock connected */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006215#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006217struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006218 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006219} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006220
Caveh Jalali024ffe32023-01-30 14:35:19 -08006221#define EC_CMD_PD_CHIP_INFO 0x011B
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006222
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006223struct ec_params_pd_chip_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006224 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006225 /*
6226 * Fetch the live chip info or hard-coded + cached chip info
6227 * 0: hardcoded value for VID/PID, cached value for FW version
6228 * 1: live chip value for VID/PID/FW Version
6229 */
6230 uint8_t live;
6231} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006232
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006233struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006234 uint16_t vendor_id;
6235 uint16_t product_id;
6236 uint16_t device_id;
6237 union {
6238 uint8_t fw_version_string[8];
6239 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006240 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006241} __ec_align2;
6242
6243struct ec_response_pd_chip_info_v1 {
6244 uint16_t vendor_id;
6245 uint16_t product_id;
6246 uint16_t device_id;
6247 union {
6248 uint8_t fw_version_string[8];
6249 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006250 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006251 union {
6252 uint8_t min_req_fw_version_string[8];
6253 uint64_t min_req_fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006254 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006255} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006256
6257/* Run RW signature verification and get status */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006258#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006259
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006260struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006261 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006262} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006263
6264/* For controlling RWSIG task */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006265#define EC_CMD_RWSIG_ACTION 0x011D
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006266
6267enum rwsig_action {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006268 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6269 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006270};
6271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006272struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006273 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006274} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006275
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006276/* Run verification on a slot */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006277#define EC_CMD_EFS_VERIFY 0x011E
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006278
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006279struct ec_params_efs_verify {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006280 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006281} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006282
6283/*
6284 * Retrieve info from Cros Board Info store. Response is based on the data
6285 * type. Integers return a uint32. Strings return a string, using the response
6286 * size to determine how big it is.
6287 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006288#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006289/*
6290 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6291 * hardware write-protect enabled.
6292 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006293#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006294
Daisuke Nojirif984a052018-02-15 12:38:15 -08006295enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006296 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006297 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6298 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06006299 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006300 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6301 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6302 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6303 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08006304 /* Second Source Factory Cache */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006305 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6306 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006307 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */
Simon Glassd3870a22023-11-09 08:43:30 -07006308
6309 /*
6310 * A uint32_t field reserved for controlling common features at runtime.
6311 * It shouldn't be used at board-level. See union ec_common_control for
6312 * the bit definitions.
6313 */
6314 CBI_TAG_COMMON_CONTROL = 11,
6315
6316 /* struct board_batt_params */
6317 CBI_TAG_BATTERY_CONFIG = 12,
6318 /* CBI_TAG_BATTERY_CONFIG_1 ~ 15 will use 13 ~ 27. */
6319
6320 /* Last entry */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006321 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006322};
6323
Simon Glassd3870a22023-11-09 08:43:30 -07006324union ec_common_control {
6325 struct {
6326 uint32_t bcic_enabled : 1;
6327 };
6328 uint32_t raw_value;
6329};
6330
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006331/*
6332 * Flags to control read operation
6333 *
6334 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6335 * write was successful without reboot.
6336 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006337#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006338
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006339struct ec_params_get_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006340 uint32_t tag; /* enum cbi_data_tag */
6341 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006342} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006343
6344/*
6345 * Flags to control write behavior.
6346 *
6347 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6348 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006349 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006350 * will be initialized to zero first.
6351 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006352#define CBI_SET_NO_SYNC BIT(0)
6353#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006354
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006355struct ec_params_set_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006356 uint32_t tag; /* enum cbi_data_tag */
6357 uint32_t flag; /* CBI_SET_* */
6358 uint32_t size; /* Data size */
6359 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006360} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006361
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006362/*
6363 * Information about resets of the AP by the EC and the EC's own uptime.
6364 */
6365#define EC_CMD_GET_UPTIME_INFO 0x0121
6366
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006367/* EC reset causes */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006368#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6369#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6370#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6371#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6372#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6373#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6374#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6375#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6376#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6377#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6378#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6379#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6380#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006381/* Some reset flags preserved from previous boot */
6382#define EC_RESET_FLAG_PRESERVED BIT(13)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006383#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6384#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6385#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6386#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006387/* AP experienced a watchdog reset */
6388#define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6389/* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6390#define EC_RESET_FLAG_STAY_IN_RO BIT(19)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006391#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6392#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6393#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006394
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006395/*
6396 * Reason codes used by the AP after a shutdown to figure out why it was reset
6397 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6398 * compatibility:
6399 * - New entries must be inserted prior to the _COUNT field
6400 * - If an existing entry is no longer in service, it must be replaced with a
6401 * RESERVED entry instead.
6402 * - The semantic meaning of an entry should not change.
6403 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6404 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006405enum chipset_shutdown_reason {
6406 /*
6407 * Beginning of reset reasons.
6408 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006409 CHIPSET_RESET_BEGIN = 0,
6410 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6411 /* Custom reason defined by a board.c or baseboard.c file */
6412 CHIPSET_RESET_BOARD_CUSTOM,
6413 /* Believe that the AP has hung */
6414 CHIPSET_RESET_HANG_REBOOT,
6415 /* Reset by EC console command */
6416 CHIPSET_RESET_CONSOLE_CMD,
6417 /* Reset by EC host command */
6418 CHIPSET_RESET_HOST_CMD,
6419 /* Keyboard module reset key combination */
6420 CHIPSET_RESET_KB_SYSRESET,
6421 /* Keyboard module warm reboot */
6422 CHIPSET_RESET_KB_WARM_REBOOT,
6423 /* Debug module warm reboot */
6424 CHIPSET_RESET_DBG_WARM_REBOOT,
6425 /* I cannot self-terminate. You must lower me into the steel. */
6426 CHIPSET_RESET_AP_REQ,
6427 /* Reset as side-effect of startup sequence */
6428 CHIPSET_RESET_INIT,
6429 /* EC detected an AP watchdog event. */
6430 CHIPSET_RESET_AP_WATCHDOG,
6431
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006432 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006433
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006434 /*
6435 * Beginning of shutdown reasons.
6436 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006437 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6438 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6439 /* Forcing a shutdown as part of EC initialization */
6440 CHIPSET_SHUTDOWN_INIT,
6441 /* Custom reason on a per-board basis. */
6442 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6443 /* This is a reason to inhibit startup, not cause shut down. */
6444 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6445 /* A power_wait_signal is being asserted */
6446 CHIPSET_SHUTDOWN_WAIT,
6447 /* Critical battery level. */
6448 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6449 /* Because you told me to. */
6450 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6451 /* Forcing a shutdown to effect entry to G3. */
6452 CHIPSET_SHUTDOWN_G3,
6453 /* Force shutdown due to over-temperature. */
6454 CHIPSET_SHUTDOWN_THERMAL,
6455 /* Force a chipset shutdown from the power button through EC */
6456 CHIPSET_SHUTDOWN_BUTTON,
6457
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006458 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006459};
6460
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006461struct ec_response_uptime_info {
6462 /*
6463 * Number of milliseconds since the last EC boot. Sysjump resets
6464 * typically do not restart the EC's time_since_boot epoch.
6465 *
6466 * WARNING: The EC's sense of time is much less accurate than the AP's
6467 * sense of time, in both phase and frequency. This timebase is similar
6468 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6469 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006470 uint32_t time_since_ec_boot_ms;
6471
6472 /*
6473 * Number of times the AP was reset by the EC since the last EC boot.
6474 * Note that the AP may be held in reset by the EC during the initial
6475 * boot sequence, such that the very first AP boot may count as more
6476 * than one here.
6477 */
6478 uint32_t ap_resets_since_ec_boot;
6479
6480 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006481 * The set of flags which describe the EC's most recent reset.
6482 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006483 */
6484 uint32_t ec_reset_flags;
6485
6486 /* Empty log entries have both the cause and timestamp set to zero. */
6487 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006488 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006489 uint16_t reset_cause;
6490
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006491 /* Reserved for protocol growth. */
6492 uint16_t reserved;
6493
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006494 /*
6495 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006496 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6497 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006498 */
6499 uint32_t reset_time_ms;
6500 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006501} __ec_align4;
6502
6503/*
6504 * Add entropy to the device secret (stored in the rollback region).
6505 *
6506 * Depending on the chip, the operation may take a long time (e.g. to erase
6507 * flash), so the commands are asynchronous.
6508 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006509#define EC_CMD_ADD_ENTROPY 0x0122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006510
6511enum add_entropy_action {
6512 /* Add entropy to the current secret. */
6513 ADD_ENTROPY_ASYNC = 0,
6514 /*
6515 * Add entropy, and also make sure that the previous secret is erased.
6516 * (this can be implemented by adding entropy multiple times until
6517 * all rolback blocks have been overwritten).
6518 */
6519 ADD_ENTROPY_RESET_ASYNC = 1,
6520 /* Read back result from the previous operation. */
6521 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006522};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006523
6524struct ec_params_rollback_add_entropy {
6525 uint8_t action;
6526} __ec_align1;
6527
6528/*
6529 * Perform a single read of a given ADC channel.
6530 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006531#define EC_CMD_ADC_READ 0x0123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006532
6533struct ec_params_adc_read {
6534 uint8_t adc_channel;
6535} __ec_align1;
6536
6537struct ec_response_adc_read {
6538 int32_t adc_value;
6539} __ec_align4;
6540
6541/*
6542 * Read back rollback info
6543 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006544#define EC_CMD_ROLLBACK_INFO 0x0124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006545
6546struct ec_response_rollback_info {
6547 int32_t id; /* Incrementing number to indicate which region to use. */
6548 int32_t rollback_min_version;
6549 int32_t rw_rollback_version;
6550} __ec_align4;
6551
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006552/* Issue AP reset */
6553#define EC_CMD_AP_RESET 0x0125
6554
6555/*****************************************************************************/
6556/* Locate peripheral chips
6557 *
6558 * Return values:
6559 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6560 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6561 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6562 */
6563#define EC_CMD_LOCATE_CHIP 0x0126
6564
6565enum ec_chip_type {
6566 EC_CHIP_TYPE_CBI_EEPROM = 0,
6567 EC_CHIP_TYPE_TCPC = 1,
6568 EC_CHIP_TYPE_COUNT,
6569 EC_CHIP_TYPE_MAX = 0xFF,
6570};
6571
6572enum ec_bus_type {
6573 EC_BUS_TYPE_I2C = 0,
6574 EC_BUS_TYPE_EMBEDDED = 1,
6575 EC_BUS_TYPE_COUNT,
6576 EC_BUS_TYPE_MAX = 0xFF,
6577};
6578
6579struct ec_i2c_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006580 uint16_t port; /* Physical port for device */
6581 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006582};
6583
6584struct ec_params_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006585 uint8_t type; /* enum ec_chip_type */
6586 uint8_t index; /* Specifies one instance of chip type */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006587 /* Used for type specific parameters in future */
6588 union {
6589 uint16_t reserved;
6590 };
6591} __ec_align2;
6592
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006593struct ec_response_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006594 uint8_t bus_type; /* enum ec_bus_type */
6595 uint8_t reserved; /* Aligning the following union to 2 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006596 union {
6597 struct ec_i2c_info i2c_info;
6598 };
6599} __ec_align2;
6600
Jett Rinkba2edaf2020-01-14 11:49:06 -07006601/*
6602 * Reboot AP on G3
6603 *
6604 * This command is used for validation purpose, where the AP needs to be
6605 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006606 * wake events.
6607 * - With command version 0:
6608 * AP reboots immediately from G3
6609 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6610 * - With command version 1:
6611 * AP reboots after the user specified delay
6612 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006613 */
6614#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6615
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006616struct ec_params_reboot_ap_on_g3_v1 {
6617 /* configurable delay in seconds in G3 state */
6618 uint32_t reboot_ap_at_g3_delay;
6619} __ec_align4;
6620
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006621/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006622/* Get PD port capabilities
6623 *
6624 * Returns the following static *capabilities* of the given port:
6625 * 1) Power role: source, sink, or dual. It is not anticipated that
6626 * future CrOS devices would ever be only a source, so the options are
6627 * sink or dual.
6628 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6629 * believe any CrOS device would support Try.SNK, so this would be source
6630 * or none).
6631 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6632 * for CrOS devices.
6633 */
6634#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6635
6636enum ec_pd_power_role_caps {
6637 EC_PD_POWER_ROLE_SOURCE = 0,
6638 EC_PD_POWER_ROLE_SINK = 1,
6639 EC_PD_POWER_ROLE_DUAL = 2,
6640};
6641
6642enum ec_pd_try_power_role_caps {
6643 EC_PD_TRY_POWER_ROLE_NONE = 0,
6644 EC_PD_TRY_POWER_ROLE_SINK = 1,
6645 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6646};
6647
6648enum ec_pd_data_role_caps {
6649 EC_PD_DATA_ROLE_DFP = 0,
6650 EC_PD_DATA_ROLE_UFP = 1,
6651 EC_PD_DATA_ROLE_DUAL = 2,
6652};
6653
6654/* From: power_manager/power_supply_properties.proto */
6655enum ec_pd_port_location {
6656 /* The location of the port is unknown, or there's only one port. */
6657 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6658
6659 /*
6660 * Various positions on the device. The first word describes the side of
6661 * the device where the port is located while the second clarifies the
6662 * position. For example, LEFT_BACK means the farthest-back port on the
6663 * left side, while BACK_LEFT means the leftmost port on the back of the
6664 * device.
6665 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006666 EC_PD_PORT_LOCATION_LEFT = 1,
6667 EC_PD_PORT_LOCATION_RIGHT = 2,
6668 EC_PD_PORT_LOCATION_BACK = 3,
6669 EC_PD_PORT_LOCATION_FRONT = 4,
6670 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6671 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006672 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006673 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6674 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6675 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006676};
6677
6678struct ec_params_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006679 uint8_t port; /* Which port to interrogate */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006680} __ec_align1;
6681
6682struct ec_response_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006683 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6684 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6685 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6686 uint8_t pd_port_location; /* enum ec_pd_port_location */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006687} __ec_align1;
6688
6689/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006690/*
6691 * Button press simulation
6692 *
6693 * This command is used to simulate a button press.
6694 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6695 * Time duration for which button needs to be pressed is an optional parameter.
6696 *
6697 * NOTE: This is only available on unlocked devices for testing purposes only.
6698 */
6699#define EC_CMD_BUTTON 0x0129
6700
6701struct ec_params_button {
6702 /* Button mask aligned to enum keyboard_button_type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006703 uint32_t btn_mask;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006704
6705 /* Duration in milliseconds button needs to be pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006706 uint32_t press_ms;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006707} __ec_align1;
6708
6709enum keyboard_button_type {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006710 KEYBOARD_BUTTON_POWER = 0,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006711 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006712 KEYBOARD_BUTTON_VOLUME_UP = 2,
6713 KEYBOARD_BUTTON_RECOVERY = 3,
6714 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6715 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6716 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6717 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6718 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6719 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6720 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6721 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006722
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006723 KEYBOARD_BUTTON_COUNT,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006724};
Yidi Lin42f79592020-09-21 18:04:10 +08006725
Rajat Jainc0495722020-04-02 23:58:35 -07006726/*****************************************************************************/
6727/*
6728 * "Get the Keyboard Config". An EC implementing this command is expected to be
6729 * vivaldi capable, i.e. can send action codes for the top row keys.
6730 * Additionally, capability to send function codes for the same keys is
6731 * optional and acceptable.
6732 *
6733 * Note: If the top row can generate both function and action codes by
6734 * using a dedicated Fn key, it does not matter whether the key sends
6735 * "function" or "action" codes by default. In both cases, the response
6736 * for this command will look the same.
6737 */
6738#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6739
6740/* Possible values for the top row keys */
6741enum action_key {
6742 TK_ABSENT = 0,
6743 TK_BACK = 1,
6744 TK_FORWARD = 2,
6745 TK_REFRESH = 3,
6746 TK_FULLSCREEN = 4,
6747 TK_OVERVIEW = 5,
6748 TK_BRIGHTNESS_DOWN = 6,
6749 TK_BRIGHTNESS_UP = 7,
6750 TK_VOL_MUTE = 8,
6751 TK_VOL_DOWN = 9,
6752 TK_VOL_UP = 10,
6753 TK_SNAPSHOT = 11,
6754 TK_PRIVACY_SCRN_TOGGLE = 12,
6755 TK_KBD_BKLIGHT_DOWN = 13,
6756 TK_KBD_BKLIGHT_UP = 14,
6757 TK_PLAY_PAUSE = 15,
6758 TK_NEXT_TRACK = 16,
6759 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006760 TK_KBD_BKLIGHT_TOGGLE = 18,
6761 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006762 TK_MENU = 20,
Rajat Jainc0495722020-04-02 23:58:35 -07006763};
6764
6765/*
6766 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6767 * If this needs to change, please create a new version of the command.
6768 */
6769#define MAX_TOP_ROW_KEYS 15
6770#define MIN_TOP_ROW_KEYS 10
6771
6772/*
6773 * Is the keyboard capable of sending function keys *in addition to*
6774 * action keys. This is possible for e.g. if the keyboard has a
6775 * dedicated Fn key.
6776 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006777#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
Rajat Jainc0495722020-04-02 23:58:35 -07006778/*
6779 * Whether the keyboard has a dedicated numeric keyboard.
6780 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006781#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
Rajat Jainc0495722020-04-02 23:58:35 -07006782/*
6783 * Whether the keyboard has a screenlock key.
6784 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006785#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
Rajat Jainc0495722020-04-02 23:58:35 -07006786
6787struct ec_response_keybd_config {
6788 /*
6789 * Number of top row keys, excluding Esc and Screenlock.
6790 * If this is 0, all Vivaldi keyboard code is disabled.
6791 * (i.e. does not expose any tables to the kernel).
6792 */
6793 uint8_t num_top_row_keys;
6794
6795 /*
6796 * The action keys in the top row, in order from left to right.
6797 * The values are filled from enum action_key. Esc and Screenlock
6798 * keys are not considered part of top row keys.
6799 */
6800 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6801
6802 /* Capability flags */
6803 uint8_t capabilities;
6804
6805} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006806
Yidi Lin42f79592020-09-21 18:04:10 +08006807/*
6808 * Configure smart discharge
6809 */
6810#define EC_CMD_SMART_DISCHARGE 0x012B
6811
Caveh Jalali024ffe32023-01-30 14:35:19 -08006812#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
Yidi Lin42f79592020-09-21 18:04:10 +08006813
6814/* Discharge rates when the system is in cutoff or hibernation. */
6815struct discharge_rate {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006816 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6817 uint16_t hibern; /* Discharge rate (uA) in hibernation */
Yidi Lin42f79592020-09-21 18:04:10 +08006818};
6819
6820struct smart_discharge_zone {
6821 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6822 int cutoff;
6823 /* When the capacity (mAh) is below this, EC stays up. */
6824 int stayup;
6825};
6826
6827struct ec_params_smart_discharge {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006828 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
Yidi Lin42f79592020-09-21 18:04:10 +08006829 /*
6830 * Desired hours for the battery to survive before reaching 0%. Set to
6831 * zero to disable smart discharging. That is, the system hibernates as
6832 * soon as the G3 idle timer expires.
6833 */
6834 uint16_t hours_to_zero;
6835 /* Set both to zero to keep the current rates. */
6836 struct discharge_rate drate;
6837};
6838
6839struct ec_response_smart_discharge {
6840 uint16_t hours_to_zero;
6841 struct discharge_rate drate;
6842 struct smart_discharge_zone dzone;
6843};
6844
6845/*****************************************************************************/
6846/* Voltage regulator controls */
6847
6848/*
6849 * Get basic info of voltage regulator for given index.
6850 *
6851 * Returns the regulator name and supported voltage list in mV.
6852 */
6853#define EC_CMD_REGULATOR_GET_INFO 0x012C
6854
6855/* Maximum length of regulator name */
6856#define EC_REGULATOR_NAME_MAX_LEN 16
6857
6858/* Maximum length of the supported voltage list. */
6859#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6860
6861struct ec_params_regulator_get_info {
6862 uint32_t index;
6863} __ec_align4;
6864
6865struct ec_response_regulator_get_info {
6866 char name[EC_REGULATOR_NAME_MAX_LEN];
6867 uint16_t num_voltages;
6868 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6869} __ec_align2;
6870
6871/*
6872 * Configure the regulator as enabled / disabled.
6873 */
6874#define EC_CMD_REGULATOR_ENABLE 0x012D
6875
6876struct ec_params_regulator_enable {
6877 uint32_t index;
6878 uint8_t enable;
6879} __ec_align4;
6880
6881/*
6882 * Query if the regulator is enabled.
6883 *
6884 * Returns 1 if the regulator is enabled, 0 if not.
6885 */
6886#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6887
6888struct ec_params_regulator_is_enabled {
6889 uint32_t index;
6890} __ec_align4;
6891
6892struct ec_response_regulator_is_enabled {
6893 uint8_t enabled;
6894} __ec_align1;
6895
6896/*
6897 * Set voltage for the voltage regulator within the range specified.
6898 *
6899 * The driver should select the voltage in range closest to min_mv.
6900 *
6901 * Also note that this might be called before the regulator is enabled, and the
6902 * setting should be in effect after the regulator is enabled.
6903 */
6904#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6905
6906struct ec_params_regulator_set_voltage {
6907 uint32_t index;
6908 uint32_t min_mv;
6909 uint32_t max_mv;
6910} __ec_align4;
6911
6912/*
6913 * Get the currently configured voltage for the voltage regulator.
6914 *
6915 * Note that this might be called before the regulator is enabled, and this
6916 * should return the configured output voltage if the regulator is enabled.
6917 */
6918#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6919
6920struct ec_params_regulator_get_voltage {
6921 uint32_t index;
6922} __ec_align4;
6923
6924struct ec_response_regulator_get_voltage {
6925 uint32_t voltage_mv;
6926} __ec_align4;
6927
6928/*
6929 * Gather all discovery information for the given port and partner type.
6930 *
6931 * Note that if discovery has not yet completed, only the currently completed
6932 * responses will be filled in. If the discovery data structures are changed
6933 * in the process of the command running, BUSY will be returned.
6934 *
6935 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6936 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6937 * maximum parameter size.
6938 */
6939#define EC_CMD_TYPEC_DISCOVERY 0x0131
6940
6941enum typec_partner_type {
6942 TYPEC_PARTNER_SOP = 0,
6943 TYPEC_PARTNER_SOP_PRIME = 1,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006944 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
Yidi Lin42f79592020-09-21 18:04:10 +08006945};
6946
6947struct ec_params_typec_discovery {
6948 uint8_t port;
6949 uint8_t partner_type; /* enum typec_partner_type */
6950} __ec_align1;
6951
6952struct svid_mode_info {
6953 uint16_t svid;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006954 uint16_t mode_count; /* Number of modes partner sent */
Caveh Jalali839ada12022-10-31 23:16:48 -07006955 uint32_t mode_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08006956};
6957
6958struct ec_response_typec_discovery {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006959 uint8_t identity_count; /* Number of identity VDOs partner sent */
6960 uint8_t svid_count; /* Number of SVIDs partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08006961 uint16_t reserved;
Caveh Jalali839ada12022-10-31 23:16:48 -07006962 uint32_t discovery_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08006963 struct svid_mode_info svids[0];
6964} __ec_align1;
6965
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006966/* USB Type-C commands for AP-controlled device policy. */
6967#define EC_CMD_TYPEC_CONTROL 0x0132
6968
6969enum typec_control_command {
6970 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6971 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006972 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006973 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006974 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006975 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
6976 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006977};
6978
6979/* Modes (USB or alternate) that a type-C port may enter. */
6980enum typec_mode {
6981 TYPEC_MODE_DP,
6982 TYPEC_MODE_TBT,
6983 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006984};
6985
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006986/* Replies the AP may specify to the TBT EnterMode command as a UFP */
6987enum typec_tbt_ufp_reply {
6988 TYPEC_TBT_UFP_REPLY_NAK,
6989 TYPEC_TBT_UFP_REPLY_ACK,
6990};
6991
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006992#define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
6993
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006994struct typec_usb_mux_set {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006995 /* Index of the mux to set in the chain */
6996 uint8_t mux_index;
6997
6998 /* USB_PD_MUX_*-encoded USB mux state to set */
6999 uint8_t mux_flags;
7000} __ec_align1;
7001
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007002struct typec_vdm_req {
7003 /* VDM data, including VDM header */
7004 uint32_t vdm_data[VDO_MAX_SIZE];
7005 /* Number of 32-bit fields filled in */
7006 uint8_t vdm_data_objects;
7007 /* Partner to address - see enum typec_partner_type */
7008 uint8_t partner_type;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007009} __ec_align1;
7010
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007011struct ec_params_typec_control {
7012 uint8_t port;
Caveh Jalali024ffe32023-01-30 14:35:19 -08007013 uint8_t command; /* enum typec_control_command */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007014 uint16_t reserved;
7015
7016 /*
7017 * This section will be interpreted based on |command|. Define a
7018 * placeholder structure to avoid having to increase the size and bump
7019 * the command version when adding new sub-commands.
7020 */
7021 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007022 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007023 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007024 /* Used for ENTER_MODE - enum typec_mode */
7025 uint8_t mode_to_enter;
7026 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
7027 uint8_t tbt_ufp_reply;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007028 /* Used for USB_MUX_SET */
7029 struct typec_usb_mux_set mux_params;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007030 /* Used for BIST_SHARE_MODE */
7031 uint8_t bist_share_mode;
7032 /* Used for VMD_REQ */
7033 struct typec_vdm_req vdm_req_params;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007034 uint8_t placeholder[128];
7035 };
7036} __ec_align1;
7037
7038/*
7039 * Gather all status information for a port.
7040 *
7041 * Note: this covers many of the return fields from the deprecated
7042 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
7043 * discovery data. The "enum pd_cc_states" is defined with the deprecated
7044 * EC_CMD_USB_PD_CONTROL command.
7045 *
7046 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007047 */
7048#define EC_CMD_TYPEC_STATUS 0x0133
7049
7050/*
7051 * Power role.
7052 *
7053 * Note this is also used for PD header creation, and values align to those in
7054 * the Power Delivery Specification Revision 3.0 (See
7055 * 6.2.1.1.4 Port Power Role).
7056 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007057enum pd_power_role {
7058 PD_ROLE_SINK = 0,
7059 PD_ROLE_SOURCE = 1,
7060};
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007061
7062/*
7063 * Data role.
7064 *
7065 * Note this is also used for PD header creation, and the first two values
7066 * align to those in the Power Delivery Specification Revision 3.0 (See
7067 * 6.2.1.1.6 Port Data Role).
7068 */
7069enum pd_data_role {
7070 PD_ROLE_UFP = 0,
7071 PD_ROLE_DFP = 1,
7072 PD_ROLE_DISCONNECTED = 2,
7073};
7074
7075enum pd_vconn_role {
7076 PD_ROLE_VCONN_OFF = 0,
7077 PD_ROLE_VCONN_SRC = 1,
7078};
7079
7080/*
7081 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
7082 * regardless of whether a debug accessory is connected.
7083 */
7084enum tcpc_cc_polarity {
7085 /*
7086 * _CCx: is used to indicate the polarity while not connected to
7087 * a Debug Accessory. Only one CC line will assert a resistor and
7088 * the other will be open.
7089 */
7090 POLARITY_CC1 = 0,
7091 POLARITY_CC2 = 1,
7092
7093 /*
7094 * _CCx_DTS is used to indicate the polarity while connected to a
7095 * SRC Debug Accessory. Assert resistors on both lines.
7096 */
7097 POLARITY_CC1_DTS = 2,
7098 POLARITY_CC2_DTS = 3,
7099
7100 /*
7101 * The current TCPC code relies on these specific POLARITY values.
7102 * Adding in a check to verify if the list grows for any reason
7103 * that this will give a hint that other places need to be
7104 * adjusted.
7105 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007106 POLARITY_COUNT,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007107};
7108
Caveh Jalali024ffe32023-01-30 14:35:19 -08007109#define MODE_DP_PIN_A BIT(0)
7110#define MODE_DP_PIN_B BIT(1)
7111#define MODE_DP_PIN_C BIT(2)
7112#define MODE_DP_PIN_D BIT(3)
7113#define MODE_DP_PIN_E BIT(4)
7114#define MODE_DP_PIN_F BIT(5)
7115#define MODE_DP_PIN_ALL GENMASK(5, 0)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007116
Caveh Jalali024ffe32023-01-30 14:35:19 -08007117#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
7118#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
7119#define PD_STATUS_EVENT_HARD_RESET BIT(2)
7120#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
7121#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
7122#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007123#define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
7124#define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
7125#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007126
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007127/*
7128 * Encode and decode for BCD revision response
7129 *
7130 * Note: the major revision set is written assuming that the value given is the
7131 * Specification Revision from the PD header, which currently only maps to PD
7132 * 1.0-3.0 with the major revision being one greater than the binary value.
7133 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007134#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
7135#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
7136#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007137
7138/*
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007139 * Encode revision from partner RMDO
7140 *
7141 * Unlike the specification revision given in the PD header, specification and
7142 * version information returned in the revision message data object (RMDO) is
7143 * not offset.
7144 */
7145#define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
7146#define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
7147#define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
7148#define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
7149
7150/*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007151 * Decode helpers for Source and Sink Capability PDOs
7152 *
7153 * Note: The Power Delivery Specification should be considered the ultimate
7154 * source of truth on the decoding of these PDOs
7155 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007156#define PDO_TYPE_FIXED (0 << 30)
7157#define PDO_TYPE_BATTERY (1 << 30)
7158#define PDO_TYPE_VARIABLE (2 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007159#define PDO_TYPE_AUGMENTED (3 << 30)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007160#define PDO_TYPE_MASK (3 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007161
7162/*
7163 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
7164 *
7165 * <31:30> : Fixed Supply
7166 * <29> : Dual-Role Power
7167 * <28> : SNK/SRC dependent
7168 * <27> : Unconstrained Power
7169 * <26> : USB Communications Capable
7170 * <25> : Dual-Role Data
7171 * <24:20> : SNK/SRC dependent
7172 * <19:10> : Voltage in 50mV Units
7173 * <9:0> : Maximum Current in 10mA units
7174 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007175#define PDO_FIXED_DUAL_ROLE BIT(29)
7176#define PDO_FIXED_UNCONSTRAINED BIT(27)
7177#define PDO_FIXED_COMM_CAP BIT(26)
7178#define PDO_FIXED_DATA_SWAP BIT(25)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007179#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007180#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7181#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007182
7183/*
7184 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
7185 *
7186 * <31:30> : Battery
7187 * <29:20> : Maximum Voltage in 50mV units
7188 * <19:10> : Minimum Voltage in 50mV units
7189 * <9:0> : Maximum Allowable Power in 250mW units
7190 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007191#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7192#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7193#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007194
7195/*
7196 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7197 *
7198 * <31:30> : Variable Supply (non-Battery)
7199 * <29:20> : Maximum Voltage in 50mV units
7200 * <19:10> : Minimum Voltage in 50mV units
7201 * <9:0> : Operational Current in 10mA units
7202 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007203#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7204#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7205#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007206
7207/*
7208 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7209 *
7210 * Note this type is reserved in PD 2.0, and only one type of APDO is
7211 * supported as of the cited version.
7212 *
7213 * <31:30> : Augmented Power Data Object
7214 * <29:28> : Programmable Power Supply
7215 * <27> : PPS Power Limited
7216 * <26:25> : Reserved
7217 * <24:17> : Maximum Voltage in 100mV increments
7218 * <16> : Reserved
7219 * <15:8> : Minimum Voltage in 100mV increments
7220 * <7> : Reserved
7221 * <6:0> : Maximum Current in 50mA increments
7222 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007223#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7224#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7225#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007226
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007227struct ec_params_typec_status {
7228 uint8_t port;
7229} __ec_align1;
7230
Caveh Jalali839ada12022-10-31 23:16:48 -07007231/*
7232 * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1.
7233 * If you need to support old ECs who speak only v0, use
7234 * ec_response_typec_status_v0 instead. They're binary-compatible.
7235 */
7236struct ec_response_typec_status /* DEPRECATED */ {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007237 uint8_t pd_enabled; /* PD communication enabled - bool */
7238 uint8_t dev_connected; /* Device connected - bool */
7239 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7240 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007241
Caveh Jalali024ffe32023-01-30 14:35:19 -08007242 uint8_t power_role; /* enum pd_power_role */
7243 uint8_t data_role; /* enum pd_data_role */
7244 uint8_t vconn_role; /* enum pd_vconn_role */
7245 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007246
Caveh Jalali024ffe32023-01-30 14:35:19 -08007247 uint8_t polarity; /* enum tcpc_cc_polarity */
7248 uint8_t cc_state; /* enum pd_cc_states */
7249 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7250 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007251
Caveh Jalali024ffe32023-01-30 14:35:19 -08007252 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007253
Caveh Jalali024ffe32023-01-30 14:35:19 -08007254 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007255
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007256 /*
7257 * BCD PD revisions for partners
7258 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007259 * The format has the PD major revision in the upper nibble, and the PD
7260 * minor revision in the next nibble. The following two nibbles hold the
7261 * major and minor specification version. If a partner does not support
7262 * the Revision message, only the major revision will be given.
7263 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007264 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007265 * PD revision/version will be 0 if no PD device is connected.
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007266 */
7267 uint16_t sop_revision;
7268 uint16_t sop_prime_revision;
7269
Caveh Jalali024ffe32023-01-30 14:35:19 -08007270 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007271
Caveh Jalali024ffe32023-01-30 14:35:19 -08007272 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007273} __ec_align1;
7274
Caveh Jalali839ada12022-10-31 23:16:48 -07007275struct cros_ec_typec_status {
7276 uint8_t pd_enabled; /* PD communication enabled - bool */
7277 uint8_t dev_connected; /* Device connected - bool */
7278 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7279 uint8_t source_cap_count; /* Number of Source Cap PDOs */
7280
7281 uint8_t power_role; /* enum pd_power_role */
7282 uint8_t data_role; /* enum pd_data_role */
7283 uint8_t vconn_role; /* enum pd_vconn_role */
7284 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
7285
7286 uint8_t polarity; /* enum tcpc_cc_polarity */
7287 uint8_t cc_state; /* enum pd_cc_states */
7288 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7289 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
7290
7291 char tc_state[32]; /* TC state name */
7292
7293 uint32_t events; /* PD_STATUS_EVENT bitmask */
7294
7295 /*
7296 * BCD PD revisions for partners
7297 *
7298 * The format has the PD major revision in the upper nibble, and the PD
7299 * minor revision in the next nibble. The following two nibbles hold the
7300 * major and minor specification version. If a partner does not support
7301 * the Revision message, only the major revision will be given.
7302 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
7303 *
7304 * PD revision/version will be 0 if no PD device is connected.
7305 */
7306 uint16_t sop_revision;
7307 uint16_t sop_prime_revision;
7308} __ec_align1;
7309
7310struct ec_response_typec_status_v0 {
7311 struct cros_ec_typec_status typec_status;
7312 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
7313 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
7314} __ec_align1;
7315
7316struct ec_response_typec_status_v1 {
7317 struct cros_ec_typec_status typec_status;
7318 uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */
7319 uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */
7320} __ec_align1;
7321
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007322/**
7323 * Get the number of peripheral charge ports
7324 */
7325#define EC_CMD_PCHG_COUNT 0x0134
7326
7327#define EC_PCHG_MAX_PORTS 8
7328
7329struct ec_response_pchg_count {
7330 uint8_t port_count;
7331} __ec_align1;
7332
7333/**
7334 * Get the status of a peripheral charge port
7335 */
7336#define EC_CMD_PCHG 0x0135
7337
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007338/* For v1 and v2 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007339struct ec_params_pchg {
7340 uint8_t port;
7341} __ec_align1;
7342
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007343struct ec_params_pchg_v3 {
7344 uint8_t port;
7345 /* Below are new in v3. */
7346 uint8_t reserved1;
7347 uint8_t reserved2;
7348 uint8_t reserved3;
7349 /* Errors acked by the host (thus to be cleared) */
7350 uint32_t error;
7351} __ec_align1;
7352
7353/* For v1 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007354struct ec_response_pchg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007355 uint32_t error; /* enum pchg_error */
7356 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007357 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007358 uint8_t unused0;
7359 uint8_t unused1;
7360 /* Fields added in version 1 */
7361 uint32_t fw_version;
7362 uint32_t dropped_event_count;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007363} __ec_align4;
7364
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007365/* For v2 and v3 */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007366struct ec_response_pchg_v2 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007367 uint32_t error; /* enum pchg_error */
7368 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007369 uint8_t battery_percentage;
7370 uint8_t unused0;
7371 uint8_t unused1;
7372 /* Fields added in version 1 */
7373 uint32_t fw_version;
7374 uint32_t dropped_event_count;
7375 /* Fields added in version 2 */
7376 uint32_t dropped_host_event_count;
7377} __ec_align4;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007378
7379enum pchg_state {
7380 /* Charger is reset and not initialized. */
7381 PCHG_STATE_RESET = 0,
7382 /* Charger is initialized or disabled. */
7383 PCHG_STATE_INITIALIZED,
7384 /* Charger is enabled and ready to detect a device. */
7385 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007386 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007387 PCHG_STATE_DETECTED,
7388 /* Device is being charged. */
7389 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007390 /* Device is fully charged. It implies DETECTED (& not charging). */
7391 PCHG_STATE_FULL,
7392 /* In download (a.k.a. firmware update) mode */
7393 PCHG_STATE_DOWNLOAD,
7394 /* In download mode. Ready for receiving data. */
7395 PCHG_STATE_DOWNLOADING,
7396 /* Device is ready for data communication. */
7397 PCHG_STATE_CONNECTED,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007398 /* Charger is in Built-In Self Test mode. */
7399 PCHG_STATE_BIST,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007400 /* Put no more entry below */
7401 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007402};
7403
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007404/* clang-format off */
7405#define EC_PCHG_STATE_TEXT \
7406 { \
7407 [PCHG_STATE_RESET] = "RESET", \
7408 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7409 [PCHG_STATE_ENABLED] = "ENABLED", \
7410 [PCHG_STATE_DETECTED] = "DETECTED", \
7411 [PCHG_STATE_CHARGING] = "CHARGING", \
7412 [PCHG_STATE_FULL] = "FULL", \
7413 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7414 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7415 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7416 [PCHG_STATE_BIST] = "BIST", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007417 }
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007418/* clang-format on */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007419
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007420/**
7421 * Update firmware of peripheral chip
7422 */
7423#define EC_CMD_PCHG_UPDATE 0x0136
7424
7425/* Port number is encoded in bit[28:31]. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007426#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007427/* Utility macros for converting MKBP event <-> port number. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007428#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7429#define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007430/* Utility macro for extracting event bits. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007431#define EC_MKBP_PCHG_EVENT_MASK(e) ((e)&GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007432
Caveh Jalali024ffe32023-01-30 14:35:19 -08007433#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7434#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7435#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7436#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7437#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007438
7439enum ec_pchg_update_cmd {
7440 /* Reset chip to normal mode. */
7441 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7442 /* Reset and put a chip in update (a.k.a. download) mode. */
7443 EC_PCHG_UPDATE_CMD_OPEN,
7444 /* Write a block of data containing FW image. */
7445 EC_PCHG_UPDATE_CMD_WRITE,
7446 /* Close update session. */
7447 EC_PCHG_UPDATE_CMD_CLOSE,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007448 /* Reset chip (without mode change). */
7449 EC_PCHG_UPDATE_CMD_RESET,
7450 /* Enable pass-through mode. */
7451 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007452 /* End of commands */
7453 EC_PCHG_UPDATE_CMD_COUNT,
7454};
7455
7456struct ec_params_pchg_update {
7457 /* PCHG port number */
7458 uint8_t port;
7459 /* enum ec_pchg_update_cmd */
7460 uint8_t cmd;
7461 /* Padding */
7462 uint8_t reserved0;
7463 uint8_t reserved1;
7464 /* Version of new firmware */
7465 uint32_t version;
7466 /* CRC32 of new firmware */
7467 uint32_t crc32;
7468 /* Address in chip memory where <data> is written to */
7469 uint32_t addr;
7470 /* Size of <data> */
7471 uint32_t size;
7472 /* Partial data of new firmware */
7473 uint8_t data[];
7474} __ec_align4;
7475
Caveh Jalali024ffe32023-01-30 14:35:19 -08007476BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7477 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007478
7479struct ec_response_pchg_update {
7480 /* Block size */
7481 uint32_t block_size;
7482} __ec_align4;
7483
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007484#define EC_CMD_DISPLAY_SOC 0x0137
7485
7486struct ec_response_display_soc {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007487 /* Display charge in 10ths of a % (1000=100.0%) */
7488 int16_t display_soc;
7489 /* Full factor in 10ths of a % (1000=100.0%) */
7490 int16_t full_factor;
7491 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7492 int16_t shutdown_soc;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007493} __ec_align2;
7494
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007495#define EC_CMD_SET_BASE_STATE 0x0138
7496
7497struct ec_params_set_base_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007498 uint8_t cmd; /* enum ec_set_base_state_cmd */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007499} __ec_align1;
7500
7501enum ec_set_base_state_cmd {
7502 EC_SET_BASE_STATE_DETACH = 0,
7503 EC_SET_BASE_STATE_ATTACH,
7504 EC_SET_BASE_STATE_RESET,
7505};
7506
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007507#define EC_CMD_I2C_CONTROL 0x0139
7508
7509/* Subcommands for I2C control */
7510
7511enum ec_i2c_control_command {
7512 EC_I2C_CONTROL_GET_SPEED,
7513 EC_I2C_CONTROL_SET_SPEED,
7514};
7515
7516#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7517
7518struct ec_params_i2c_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007519 uint8_t port; /* I2C port number */
7520 uint8_t cmd; /* enum ec_i2c_control_command */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007521 union {
7522 uint16_t speed_khz;
7523 } cmd_params;
7524} __ec_align_size1;
7525
7526struct ec_response_i2c_control {
7527 union {
7528 uint16_t speed_khz;
7529 } cmd_response;
7530} __ec_align_size1;
7531
Caveh Jalali024ffe32023-01-30 14:35:19 -08007532#define EC_CMD_RGBKBD_SET_COLOR 0x013A
7533#define EC_CMD_RGBKBD 0x013B
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007534
Caveh Jalali024ffe32023-01-30 14:35:19 -08007535#define EC_RGBKBD_MAX_KEY_COUNT 128
7536#define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7537#define EC_RGBKBD_MAX_SCALE 0xFF
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007538
7539enum rgbkbd_state {
7540 /* RGB keyboard is reset and not initialized. */
7541 RGBKBD_STATE_RESET = 0,
7542 /* RGB keyboard is initialized but not enabled. */
7543 RGBKBD_STATE_INITIALIZED,
7544 /* RGB keyboard is disabled. */
7545 RGBKBD_STATE_DISABLED,
7546 /* RGB keyboard is enabled and ready to receive a command. */
7547 RGBKBD_STATE_ENABLED,
7548
7549 /* Put no more entry below */
7550 RGBKBD_STATE_COUNT,
7551};
7552
7553enum ec_rgbkbd_subcmd {
7554 EC_RGBKBD_SUBCMD_CLEAR = 1,
7555 EC_RGBKBD_SUBCMD_DEMO = 2,
7556 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007557 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007558 EC_RGBKBD_SUBCMD_COUNT
7559};
7560
7561enum ec_rgbkbd_demo {
7562 EC_RGBKBD_DEMO_OFF = 0,
7563 EC_RGBKBD_DEMO_FLOW = 1,
7564 EC_RGBKBD_DEMO_DOT = 2,
7565 EC_RGBKBD_DEMO_COUNT,
7566};
7567
7568BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7569
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007570enum ec_rgbkbd_type {
7571 EC_RGBKBD_TYPE_UNKNOWN = 0,
7572 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7573 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7574 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7575 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7576 EC_RGBKBD_TYPE_COUNT,
7577};
7578
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007579struct ec_rgbkbd_set_scale {
7580 uint8_t key;
7581 struct rgb_s scale;
7582};
7583
7584struct ec_params_rgbkbd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007585 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007586 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007587 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7588 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007589 struct ec_rgbkbd_set_scale set_scale;
7590 };
7591} __ec_align1;
7592
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007593struct ec_response_rgbkbd {
7594 /*
7595 * RGBKBD type supported by the device.
7596 */
7597
7598 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7599} __ec_align1;
7600
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007601struct ec_params_rgbkbd_set_color {
7602 /* Specifies the starting key ID whose color is being changed. */
7603 uint8_t start_key;
7604 /* Specifies # of elements in <color>. */
7605 uint8_t length;
7606 /* RGB color data array of length up to MAX_KEY_COUNT. */
7607 struct rgb_s color[];
7608} __ec_align1;
7609
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007610/*
7611 * Gather the response to the most recent VDM REQ from the AP, as well
7612 * as popping the oldest VDM:Attention from the DPM queue
7613 */
7614#define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7615
7616struct ec_params_typec_vdm_response {
7617 uint8_t port;
7618} __ec_align1;
7619
7620struct ec_response_typec_vdm_response {
7621 /* Number of 32-bit fields filled in */
7622 uint8_t vdm_data_objects;
7623 /* Partner to address - see enum typec_partner_type */
7624 uint8_t partner_type;
7625 /* enum ec_status describing VDM response */
7626 uint16_t vdm_response_err;
7627 /* VDM data, including VDM header */
7628 uint32_t vdm_response[VDO_MAX_SIZE];
7629 /* Number of 32-bit Attention fields filled in */
7630 uint8_t vdm_attention_objects;
7631 /* Number of remaining messages to consume */
7632 uint8_t vdm_attention_left;
7633 /* Reserved */
7634 uint16_t reserved1;
7635 /* VDM:Attention contents */
7636 uint32_t vdm_attention[2];
7637} __ec_align1;
7638
Simon Glassd3870a22023-11-09 08:43:30 -07007639/*
7640 * Get an active battery config from the EC.
7641 */
7642#define EC_CMD_BATTERY_CONFIG 0x013D
7643
7644/* Version of struct batt_conf_header and its internals. */
7645#define EC_BATTERY_CONFIG_STRUCT_VERSION 0x00
7646
7647/* Number of writes needed to invoke battery cutoff command */
7648#define SHIP_MODE_WRITES 2
7649
7650struct ship_mode_info {
7651 uint8_t reg_addr;
7652 uint8_t reserved;
7653 uint16_t reg_data[SHIP_MODE_WRITES];
7654} __packed __aligned(2);
7655
7656struct sleep_mode_info {
7657 uint8_t reg_addr;
7658 uint8_t reserved;
7659 uint16_t reg_data;
7660} __packed __aligned(2);
7661
7662struct fet_info {
7663 uint8_t reg_addr;
7664 uint8_t reserved;
7665 uint16_t reg_mask;
7666 uint16_t disconnect_val;
7667 uint16_t cfet_mask; /* CHG FET status mask */
7668 uint16_t cfet_off_val;
7669} __packed __aligned(2);
7670
7671enum fuel_gauge_flags {
7672 /*
7673 * Write Block Support. If enabled, we use a i2c write block command
7674 * instead of a 16-bit write. The effective difference is the i2c
7675 * transaction will prefix the length (2).
7676 */
7677 FUEL_GAUGE_FLAG_WRITE_BLOCK = BIT(0),
7678 /* Sleep command support. fuel_gauge_info.sleep_mode must be defined. */
7679 FUEL_GAUGE_FLAG_SLEEP_MODE = BIT(1),
7680 /*
7681 * Manufacturer access command support. If enabled, FET status is read
7682 * from the OperationStatus (0x54) register using the
7683 * ManufacturerBlockAccess (0x44).
7684 */
7685 FUEL_GAUGE_FLAG_MFGACC = BIT(2),
7686 /*
7687 * SMB block protocol support in manufacturer access command. If
7688 * enabled, FET status is read from the OperationStatus (0x54) register
7689 * using the ManufacturerBlockAccess (0x44).
7690 */
7691 FUEL_GAUGE_FLAG_MFGACC_SMB_BLOCK = BIT(3),
7692};
7693
7694struct fuel_gauge_info {
7695 uint32_t flags;
7696 uint32_t board_flags;
7697 struct ship_mode_info ship_mode;
7698 struct sleep_mode_info sleep_mode;
7699 struct fet_info fet;
7700} __packed __aligned(4);
7701
7702/* Battery constants */
7703struct battery_info {
7704 /* Operation voltage in mV */
7705 uint16_t voltage_max;
7706 uint16_t voltage_normal;
7707 uint16_t voltage_min;
7708 /* (TODO(chromium:756700): add desired_charging_current */
7709 /**
7710 * Pre-charge to fast charge threshold in mV,
7711 * default to voltage_min if not specified.
7712 * This option is only available on isl923x and rt946x.
7713 */
7714 uint16_t precharge_voltage;
7715 /* Pre-charge current in mA */
7716 uint16_t precharge_current;
7717 /* Working temperature ranges in degrees C */
7718 int8_t start_charging_min_c;
7719 int8_t start_charging_max_c;
7720 int8_t charging_min_c;
7721 int8_t charging_max_c;
7722 int8_t discharging_min_c;
7723 int8_t discharging_max_c;
7724 /* Used only if CONFIG_BATTERY_VENDOR_PARAM is defined. */
7725 uint8_t vendor_param_start;
7726 uint8_t reserved;
7727} __packed __aligned(2);
7728
7729/**
7730 * The 'config' of a battery.
7731 */
7732struct board_batt_params {
7733 struct fuel_gauge_info fuel_gauge;
7734 struct battery_info batt_info;
7735} __packed __aligned(4);
7736
7737#define SBS_MAX_STRING_SIZE 32
7738
7739/**
7740 * Header describing a battery config stored in CBI. Only struct_version has
7741 * size and position independent of struct_version. The rest varies as
7742 * struct_version changes.
7743 *
7744 * Version 0
7745 * Layout:
7746 * +-------------+
7747 * | header |
7748 * +-------------+
7749 * | | ^
7750 * | manuf_name | | manuf_name_size
7751 * | | v
7752 * +-------------+
7753 * | device_name | ^
7754 * | | | device_name_size
7755 * | | v
7756 * +-------------+
7757 * | config | ^
7758 * | | |
7759 * | | | cbi data size
7760 * | | | - (header_size+manuf_name_size+device_name_size)
7761 * | | |
7762 * | | v
7763 * +-------------+
7764 * Note:
7765 * - manuf_name and device_name are not null-terminated.
7766 * - The config isn't aligned. It should be copied to struct board_batt_params
7767 * before its contents are accessed.
7768 */
7769struct batt_conf_header {
7770 /* Version independent field. It's always here as a uint8_t. */
7771 uint8_t struct_version;
7772 /* Version 0 members */
7773 uint8_t manuf_name_size;
7774 uint8_t device_name_size;
7775 uint8_t reserved;
7776 /* manuf_name, device_name, board_batt_params follow after this. */
7777} __packed;
7778
7779#define BATT_CONF_MAX_SIZE \
7780 (sizeof(struct batt_conf_header) + SBS_MAX_STRING_SIZE * 2 + \
7781 sizeof(struct board_batt_params))
7782
7783/*
7784 * Record the current AP firmware state. This is used to help testing, such as
7785 * with FAFT (Fully-Automated Firmware Test), which likes to know which firmware
7786 * screen is currently displayed.
7787 */
7788
7789#define EC_CMD_AP_FW_STATE 0x013E
7790
7791struct ec_params_ap_fw_state {
7792 /*
7793 * Value which indicates the state. This is not decoded by the EC, so
7794 * its meaning is entirely outside this code base.
7795 */
7796 uint32_t state;
7797} __ec_align1;
7798
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007799/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007800/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007801
7802/*****************************************************************************/
7803/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007804 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007805 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007806#define EC_CMD_CR51_BASE 0x0300
7807#define EC_CMD_CR51_LAST 0x03FF
7808
7809/*****************************************************************************/
7810/* Fingerprint MCU commands: range 0x0400-0x040x */
7811
Simon Glassd3870a22023-11-09 08:43:30 -07007812/*
7813 * Fingerprint SPI sensor passthru command
7814 *
7815 * This command was used for prototyping and it's now deprecated.
7816 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007817#define EC_CMD_FP_PASSTHRU 0x0400
7818
7819#define EC_FP_FLAG_NOT_COMPLETE 0x1
7820
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007821struct ec_params_fp_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007822 uint16_t len; /* Number of bytes to write then read */
7823 uint16_t flags; /* EC_FP_FLAG_xxx */
7824 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007825} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007826
7827/* Configure the Fingerprint MCU behavior */
7828#define EC_CMD_FP_MODE 0x0402
7829
7830/* Put the sensor in its lowest power mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007831#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007832/* Wait to see a finger on the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007833#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007834/* Poll until the finger has left the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007835#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007836/* Capture the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007837#define FP_MODE_CAPTURE BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007838/* Finger enrollment session on-going */
7839#define FP_MODE_ENROLL_SESSION BIT(4)
7840/* Enroll the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007841#define FP_MODE_ENROLL_IMAGE BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007842/* Try to match the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007843#define FP_MODE_MATCH BIT(6)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007844/* Reset and re-initialize the sensor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007845#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007846/* Sensor maintenance for dead pixels. */
7847#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007848/* special value: don't change anything just read back current mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007849#define FP_MODE_DONT_CHANGE BIT(31)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007850
Caveh Jalali024ffe32023-01-30 14:35:19 -08007851#define FP_VALID_MODES \
7852 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
7853 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
7854 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
7855 FP_MODE_DONT_CHANGE)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007856
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007857/* Capture types defined in bits [30..28] */
7858#define FP_MODE_CAPTURE_TYPE_SHIFT 28
Caveh Jalali024ffe32023-01-30 14:35:19 -08007859#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007860/**
7861 * enum fp_capture_type - Specifies the "mode" when capturing images.
7862 *
7863 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
7864 * image (produces 'frame_size' bytes)
7865 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
7866 * bpp bits)
7867 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
7868 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
7869 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
7870 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
7871 * @FP_CAPTURE_TYPE_MAX: End of enum
7872 *
7873 * @note This enum must remain ordered, if you add new values you must ensure
7874 * that FP_CAPTURE_TYPE_MAX is still the last one.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007875 */
7876enum fp_capture_type {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007877 FP_CAPTURE_VENDOR_FORMAT = 0,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007878 FP_CAPTURE_SIMPLE_IMAGE = 1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007879 FP_CAPTURE_PATTERN0 = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007880 FP_CAPTURE_PATTERN1 = 3,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007881 FP_CAPTURE_QUALITY_TEST = 4,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007882 FP_CAPTURE_RESET_TEST = 5,
7883 FP_CAPTURE_TYPE_MAX,
7884};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007885/* Extracts the capture type from the sensor 'mode' word */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007886#define FP_CAPTURE_TYPE(mode) \
7887 (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007888
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007889struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007890 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007891} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007892
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007893struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007894 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007895} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007896
7897/* Retrieve Fingerprint sensor information */
7898#define EC_CMD_FP_INFO 0x0403
7899
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007900/* Number of dead pixels detected on the last maintenance */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007901#define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007902/* Unknown number of dead pixels detected on the last maintenance */
7903#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007904/* No interrupt from the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007905#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007906/* SPI communication error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007907#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007908/* Invalid sensor Hardware ID */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007909#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007910/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007911#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007912
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007913struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007914 /* Sensor identification */
7915 uint32_t vendor_id;
7916 uint32_t product_id;
7917 uint32_t model_id;
7918 uint32_t version;
7919 /* Image frame characteristics */
7920 uint32_t frame_size;
7921 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7922 uint16_t width;
7923 uint16_t height;
7924 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007925 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007926} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007927
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007928struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007929 /* Sensor identification */
7930 uint32_t vendor_id;
7931 uint32_t product_id;
7932 uint32_t model_id;
7933 uint32_t version;
7934 /* Image frame characteristics */
7935 uint32_t frame_size;
7936 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7937 uint16_t width;
7938 uint16_t height;
7939 uint16_t bpp;
7940 uint16_t errors; /* see FP_ERROR_ flags above */
7941 /* Template/finger current information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007942 uint32_t template_size; /* max template size in bytes */
7943 uint16_t template_max; /* maximum number of fingers/templates */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007944 uint16_t template_valid; /* number of valid fingers/templates */
7945 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007946 uint32_t template_version; /* version of the template format */
7947} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007948
7949/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007950#define EC_CMD_FP_FRAME 0x0404
7951
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007952/* constants defining the 'offset' field which also contains the frame index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007953#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007954/* Frame buffer where the captured image is stored */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007955#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007956/* First frame buffer holding a template */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007957#define FP_FRAME_INDEX_TEMPLATE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007958#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007959#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007960
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007961/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007962#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007963
7964/* Constants for encryption parameters */
7965#define FP_CONTEXT_NONCE_BYTES 12
7966#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7967#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007968#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007969#define FP_CONTEXT_TPM_BYTES 32
7970
Jett Rinkba2edaf2020-01-14 11:49:06 -07007971/* Constants for positive match parameters. */
7972#define FP_POSITIVE_MATCH_SALT_BYTES 16
7973
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007974struct ec_fp_template_encryption_metadata {
7975 /*
7976 * Version of the structure format (N=3).
7977 */
7978 uint16_t struct_version;
7979 /* Reserved bytes, set to 0. */
7980 uint16_t reserved;
7981 /*
7982 * The salt is *only* ever used for key derivation. The nonce is unique,
7983 * a different one is used for every message.
7984 */
7985 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007986 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007987 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7988};
7989
7990struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007991 /*
7992 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7993 * in the high nibble, and the real offset within the frame in
7994 * FP_FRAME_OFFSET_MASK.
7995 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007996 uint32_t offset;
7997 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007998} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007999
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008000/* Load a template into the MCU */
8001#define EC_CMD_FP_TEMPLATE 0x0405
8002
8003/* Flag in the 'size' field indicating that the full template has been sent */
8004#define FP_TEMPLATE_COMMIT 0x80000000
8005
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008006struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008007 uint32_t offset;
8008 uint32_t size;
8009 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008010} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008011
8012/* Clear the current fingerprint user context and set a new one */
8013#define EC_CMD_FP_CONTEXT 0x0406
8014
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008015struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008016 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008017} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008018
Jett Rinkba2edaf2020-01-14 11:49:06 -07008019enum fp_context_action {
8020 FP_CONTEXT_ASYNC = 0,
8021 FP_CONTEXT_GET_RESULT = 1,
8022};
8023
8024/* Version 1 of the command is "asynchronous". */
8025struct ec_params_fp_context_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08008026 uint8_t action; /**< enum fp_context_action */
8027 uint8_t reserved[3]; /**< padding for alignment */
Jett Rinkba2edaf2020-01-14 11:49:06 -07008028 uint32_t userid[FP_CONTEXT_USERID_WORDS];
8029} __ec_align4;
8030
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008031#define EC_CMD_FP_STATS 0x0407
8032
Caveh Jalali024ffe32023-01-30 14:35:19 -08008033#define FPSTATS_CAPTURE_INV BIT(0)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008034#define FPSTATS_MATCHING_INV BIT(1)
8035
8036struct ec_response_fp_stats {
8037 uint32_t capture_time_us;
8038 uint32_t matching_time_us;
8039 uint32_t overall_time_us;
8040 struct {
8041 uint32_t lo;
8042 uint32_t hi;
8043 } overall_t0;
8044 uint8_t timestamps_invalid;
8045 int8_t template_matched;
8046} __ec_align2;
8047
8048#define EC_CMD_FP_SEED 0x0408
8049struct ec_params_fp_seed {
8050 /*
8051 * Version of the structure format (N=3).
8052 */
8053 uint16_t struct_version;
8054 /* Reserved bytes, set to 0. */
8055 uint16_t reserved;
8056 /* Seed from the TPM. */
8057 uint8_t seed[FP_CONTEXT_TPM_BYTES];
8058} __ec_align4;
8059
8060#define EC_CMD_FP_ENC_STATUS 0x0409
8061
8062/* FP TPM seed has been set or not */
8063#define FP_ENC_STATUS_SEED_SET BIT(0)
Simon Glassd3870a22023-11-09 08:43:30 -07008064/* FP using nonce context or not */
8065#define FP_CONTEXT_STATUS_NONCE_CONTEXT_SET BIT(1)
8066/* FP match had been processed or not */
8067#define FP_CONTEXT_STATUS_MATCH_PROCESSED_SET BIT(2)
8068/* FP auth_nonce had been set or not*/
8069#define FP_CONTEXT_AUTH_NONCE_SET BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008070
8071struct ec_response_fp_encryption_status {
8072 /* Used bits in encryption engine status */
8073 uint32_t valid_flags;
8074 /* Encryption engine status */
8075 uint32_t status;
8076} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008077
Jett Rinkba2edaf2020-01-14 11:49:06 -07008078#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
8079struct ec_params_fp_read_match_secret {
8080 uint16_t fgr;
8081} __ec_align4;
8082
8083/* The positive match secret has the length of the SHA256 digest. */
8084#define FP_POSITIVE_MATCH_SECRET_BYTES 32
8085struct ec_response_fp_read_match_secret {
8086 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8087} __ec_align4;
8088
Simon Glassd3870a22023-11-09 08:43:30 -07008089#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN 32
8090
8091struct fp_elliptic_curve_public_key {
8092 uint8_t x[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8093 uint8_t y[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8094} __ec_align4;
8095
8096#define FP_AES_KEY_ENC_METADATA_VERSION 1
8097#define FP_AES_KEY_NONCE_BYTES 12
8098#define FP_AES_KEY_ENCRYPTION_SALT_BYTES 16
8099#define FP_AES_KEY_TAG_BYTES 16
8100
8101struct fp_auth_command_encryption_metadata {
8102 /* Version of the structure format */
8103 uint16_t struct_version;
8104 /* Reserved bytes, set to 0. */
8105 uint16_t reserved;
8106 /*
8107 * The salt is *only* ever used for key derivation. The nonce is unique,
8108 * a different one is used for every message.
8109 */
8110 uint8_t nonce[FP_AES_KEY_NONCE_BYTES];
8111 uint8_t encryption_salt[FP_AES_KEY_ENCRYPTION_SALT_BYTES];
8112 uint8_t tag[FP_AES_KEY_TAG_BYTES];
8113} __ec_align4;
8114
8115#define FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN 32
8116#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8117
8118struct fp_encrypted_private_key {
8119 struct fp_auth_command_encryption_metadata info;
8120 uint8_t data[FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN];
8121} __ec_align4;
8122
8123#define EC_CMD_FP_ESTABLISH_PAIRING_KEY_KEYGEN 0x0410
8124
8125struct ec_response_fp_establish_pairing_key_keygen {
8126 struct fp_elliptic_curve_public_key pubkey;
8127 struct fp_encrypted_private_key encrypted_private_key;
8128} __ec_align4;
8129
8130#define FP_PAIRING_KEY_LEN 32
8131
8132struct ec_fp_encrypted_pairing_key {
8133 struct fp_auth_command_encryption_metadata info;
8134 uint8_t data[FP_PAIRING_KEY_LEN];
8135} __ec_align4;
8136
8137#define EC_CMD_FP_ESTABLISH_PAIRING_KEY_WRAP 0x0411
8138
8139struct ec_params_fp_establish_pairing_key_wrap {
8140 struct fp_elliptic_curve_public_key peers_pubkey;
8141 struct fp_encrypted_private_key encrypted_private_key;
8142} __ec_align4;
8143
8144struct ec_response_fp_establish_pairing_key_wrap {
8145 struct ec_fp_encrypted_pairing_key encrypted_pairing_key;
8146} __ec_align4;
8147
8148#define EC_CMD_FP_LOAD_PAIRING_KEY 0x0412
8149
8150typedef struct ec_response_fp_establish_pairing_key_wrap
8151 ec_params_fp_load_pairing_key;
8152
8153#define FP_CK_AUTH_NONCE_LEN 32
8154
8155#define EC_CMD_FP_GENERATE_NONCE 0x0413
8156struct ec_response_fp_generate_nonce {
8157 uint8_t nonce[FP_CK_AUTH_NONCE_LEN];
8158} __ec_align4;
8159
8160#define FP_CONTEXT_USERID_LEN 32
8161#define FP_CONTEXT_USERID_IV_LEN 16
8162#define FP_CONTEXT_KEY_LEN 32
8163
8164#define EC_CMD_FP_NONCE_CONTEXT 0x0414
8165struct ec_params_fp_nonce_context {
8166 uint8_t gsc_nonce[FP_CK_AUTH_NONCE_LEN];
8167 uint8_t enc_user_id[FP_CONTEXT_USERID_LEN];
8168 uint8_t enc_user_id_iv[FP_CONTEXT_USERID_IV_LEN];
8169} __ec_align4;
8170
8171#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8172
8173#define EC_CMD_FP_READ_MATCH_SECRET_WITH_PUBKEY 0x0415
8174
8175struct ec_params_fp_read_match_secret_with_pubkey {
8176 uint16_t fgr;
8177 uint16_t reserved;
8178 struct fp_elliptic_curve_public_key pubkey;
8179} __ec_align4;
8180
8181struct ec_response_fp_read_match_secret_with_pubkey {
8182 struct fp_elliptic_curve_public_key pubkey;
8183 uint8_t iv[FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN];
8184 uint8_t enc_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8185} __ec_align4;
8186
8187/* Preload encrypted template into the MCU buffer */
8188#define EC_CMD_FP_PRELOAD_TEMPLATE 0x0416
8189
8190struct ec_params_fp_preload_template {
8191 uint32_t offset;
8192 uint32_t size;
8193 uint16_t fgr;
8194 uint8_t reserved[2];
8195 uint8_t data[];
8196} __ec_align4;
8197
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008198/*****************************************************************************/
8199/* Touchpad MCU commands: range 0x0500-0x05FF */
8200
8201/* Perform touchpad self test */
8202#define EC_CMD_TP_SELF_TEST 0x0500
8203
8204/* Get number of frame types, and the size of each type */
8205#define EC_CMD_TP_FRAME_INFO 0x0501
8206
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008207struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008208 uint32_t n_frames;
8209 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008210} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008211
8212/* Create a snapshot of current frame readings */
8213#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
8214
8215/* Read the frame */
8216#define EC_CMD_TP_FRAME_GET 0x0503
8217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008218struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008219 uint32_t frame_index;
8220 uint32_t offset;
8221 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008222} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08008223
8224/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008225/* EC-EC communication commands: range 0x0600-0x06FF */
8226
8227#define EC_COMM_TEXT_MAX 8
8228
8229/*
8230 * Get battery static information, i.e. information that never changes, or
8231 * very infrequently.
8232 */
8233#define EC_CMD_BATTERY_GET_STATIC 0x0600
8234
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008235/**
8236 * struct ec_params_battery_static_info - Battery static info parameters
8237 * @index: Battery index.
8238 */
8239struct ec_params_battery_static_info {
8240 uint8_t index;
8241} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008242
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008243/**
8244 * struct ec_response_battery_static_info - Battery static info response
8245 * @design_capacity: Battery Design Capacity (mAh)
8246 * @design_voltage: Battery Design Voltage (mV)
8247 * @manufacturer: Battery Manufacturer String
8248 * @model: Battery Model Number String
8249 * @serial: Battery Serial Number String
8250 * @type: Battery Type String
8251 * @cycle_count: Battery Cycle Count
8252 */
8253struct ec_response_battery_static_info {
8254 uint16_t design_capacity;
8255 uint16_t design_voltage;
8256 char manufacturer[EC_COMM_TEXT_MAX];
8257 char model[EC_COMM_TEXT_MAX];
8258 char serial[EC_COMM_TEXT_MAX];
8259 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008260 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008261 uint32_t cycle_count;
8262} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008263
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08008264/**
8265 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
8266 * Equivalent to struct ec_response_battery_static_info, but with longer
8267 * strings.
8268 * @design_capacity: battery design capacity (in mAh)
8269 * @design_voltage: battery design voltage (in mV)
8270 * @cycle_count: battery cycle count
8271 * @manufacturer_ext: battery manufacturer string
8272 * @model_ext: battery model string
8273 * @serial_ext: battery serial number string
8274 * @type_ext: battery type string
8275 */
8276struct ec_response_battery_static_info_v1 {
8277 uint16_t design_capacity;
8278 uint16_t design_voltage;
8279 uint32_t cycle_count;
8280 char manufacturer_ext[12];
8281 char model_ext[12];
8282 char serial_ext[12];
8283 char type_ext[12];
8284} __ec_align4;
8285
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008286/**
8287 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
8288 *
8289 * Equivalent to struct ec_response_battery_static_info, but with strings
8290 * further lengthened (relative to v1) to accommodate the maximum string length
8291 * permitted by the Smart Battery Data Specification revision 1.1 and fields
8292 * renamed to better match that specification.
8293 *
8294 * @design_capacity: battery design capacity (in mAh)
8295 * @design_voltage: battery design voltage (in mV)
8296 * @cycle_count: battery cycle count
8297 * @manufacturer: battery manufacturer string
8298 * @device_name: battery model string
8299 * @serial: battery serial number string
8300 * @chemistry: battery type string
8301 */
8302struct ec_response_battery_static_info_v2 {
8303 uint16_t design_capacity;
8304 uint16_t design_voltage;
8305 uint32_t cycle_count;
8306 char manufacturer[32];
8307 char device_name[32];
8308 char serial[32];
8309 char chemistry[32];
8310} __ec_align4;
8311
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008312/*
8313 * Get battery dynamic information, i.e. information that is likely to change
8314 * every time it is read.
8315 */
8316#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
8317
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008318/**
8319 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
8320 * @index: Battery index.
8321 */
8322struct ec_params_battery_dynamic_info {
8323 uint8_t index;
8324} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008325
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008326/**
8327 * struct ec_response_battery_dynamic_info - Battery dynamic info response
8328 * @actual_voltage: Battery voltage (mV)
8329 * @actual_current: Battery current (mA); negative=discharging
8330 * @remaining_capacity: Remaining capacity (mAh)
8331 * @full_capacity: Capacity (mAh, might change occasionally)
8332 * @flags: Flags, see EC_BATT_FLAG_*
8333 * @desired_voltage: Charging voltage desired by battery (mV)
8334 * @desired_current: Charging current desired by battery (mA)
8335 */
8336struct ec_response_battery_dynamic_info {
8337 int16_t actual_voltage;
8338 int16_t actual_current;
8339 int16_t remaining_capacity;
8340 int16_t full_capacity;
8341 int16_t flags;
8342 int16_t desired_voltage;
8343 int16_t desired_current;
8344} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008345
8346/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06008347 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008348 */
8349#define EC_CMD_CHARGER_CONTROL 0x0602
8350
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008351/**
8352 * struct ec_params_charger_control - Charger control parameters
8353 * @max_current: Charger current (mA). Positive to allow base to draw up to
8354 * max_current and (possibly) charge battery, negative to request current
8355 * from base (OTG).
8356 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
8357 * >= 0.
8358 * @allow_charging: Allow base battery charging (only makes sense if
8359 * max_current > 0).
8360 */
8361struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008362 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008363 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008364 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008365} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008366
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08008367/* Get ACK from the USB-C SS muxes */
8368#define EC_CMD_USB_PD_MUX_ACK 0x0603
8369
8370struct ec_params_usb_pd_mux_ack {
8371 uint8_t port; /* USB-C port number */
8372} __ec_align1;
8373
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008374/* Get boot time */
8375#define EC_CMD_GET_BOOT_TIME 0x0604
8376
8377enum boot_time_param {
8378 ARAIL = 0,
8379 RSMRST,
8380 ESPIRST,
8381 PLTRST_LOW,
8382 PLTRST_HIGH,
8383 EC_CUR_TIME,
8384 RESET_CNT,
8385};
8386
8387struct ec_response_get_boot_time {
8388 uint64_t timestamp[RESET_CNT];
8389 uint16_t cnt;
8390} __ec_align4;
8391
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008392/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08008393/*
8394 * Reserve a range of host commands for board-specific, experimental, or
8395 * special purpose features. These can be (re)used without updating this file.
8396 *
8397 * CAUTION: Don't go nuts with this. Shipping products should document ALL
8398 * their EC commands for easier development, testing, debugging, and support.
8399 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008400 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
8401 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
8402 *
Duncan Laurieeb316852015-12-01 18:51:18 -08008403 * In your experimental code, you may want to do something like this:
8404 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008405 * #define EC_CMD_MAGIC_FOO 0x0000
8406 * #define EC_CMD_MAGIC_BAR 0x0001
8407 * #define EC_CMD_MAGIC_HEY 0x0002
8408 *
8409 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
8410 * EC_VER_MASK(0);
8411 *
8412 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
8413 * EC_VER_MASK(0);
8414 *
8415 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
8416 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08008417 */
8418#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
8419#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
8420
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008421/*
8422 * Given the private host command offset, calculate the true private host
8423 * command value.
8424 */
8425#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
8426 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
8427
Duncan Laurie93e24442014-01-06 12:30:52 -08008428/*****************************************************************************/
8429/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07008430 * Passthru commands
8431 *
8432 * Some platforms have sub-processors chained to each other. For example.
8433 *
8434 * AP <--> EC <--> PD MCU
8435 *
8436 * The top 2 bits of the command number are used to indicate which device the
8437 * command is intended for. Device 0 is always the device receiving the
8438 * command; other device mapping is board-specific.
8439 *
8440 * When a device receives a command to be passed to a sub-processor, it passes
8441 * it on with the device number set back to 0. This allows the sub-processor
8442 * to remain blissfully unaware of whether the command originated on the next
8443 * device up the chain, or was passed through from the AP.
8444 *
8445 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
8446 * AP sends command 0x4002 to the EC
8447 * EC sends command 0x0002 to the PD MCU
8448 * EC forwards PD MCU response back to the AP
8449 */
8450
8451/* Offset and max command number for sub-device n */
8452#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
8453#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
8454
8455/*****************************************************************************/
8456/*
Duncan Laurie93e24442014-01-06 12:30:52 -08008457 * Deprecated constants. These constants have been renamed for clarity. The
8458 * meaning and size has not changed. Programs that use the old names should
8459 * switch to the new names soon, as the old names may not be carried forward
8460 * forever.
8461 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008462#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
8463#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
8464#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
Duncan Laurie93e24442014-01-06 12:30:52 -08008465
Caveh Jalali024ffe32023-01-30 14:35:19 -08008466#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008467
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008468#ifdef __cplusplus
8469}
8470#endif
8471
Caveh Jalali024ffe32023-01-30 14:35:19 -08008472#endif /* __CROS_EC_EC_COMMANDS_H */