blob: 0d474cb7938d886ae6905f6fea399e75450efbd5 [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
Aseda Aboagyeabc38122024-04-15 15:39:55 -0500525#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) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -0500527 (((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
Aseda Aboagyeabc38122024-04-15 15:39:55 -0500693 EC_RES_COUNT,
694
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800695 EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700696} __packed;
697BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Simon Glassd3870a22023-11-09 08:43:30 -0700698#ifdef CONFIG_EC_HOST_CMD
699/*
700 * Make sure Zephyre uses the same status codes.
701 */
702#include <zephyr/mgmt/ec_host_cmd/ec_host_cmd.h>
703
704BUILD_ASSERT((uint16_t)EC_RES_SUCCESS == (uint16_t)EC_HOST_CMD_SUCCESS);
705BUILD_ASSERT((uint16_t)EC_RES_INVALID_COMMAND ==
706 (uint16_t)EC_HOST_CMD_INVALID_COMMAND);
707BUILD_ASSERT((uint16_t)EC_RES_ERROR == (uint16_t)EC_HOST_CMD_ERROR);
708BUILD_ASSERT((uint16_t)EC_RES_INVALID_PARAM ==
709 (uint16_t)EC_HOST_CMD_INVALID_PARAM);
710BUILD_ASSERT((uint16_t)EC_RES_ACCESS_DENIED ==
711 (uint16_t)EC_HOST_CMD_ACCESS_DENIED);
712BUILD_ASSERT((uint16_t)EC_RES_INVALID_RESPONSE ==
713 (uint16_t)EC_HOST_CMD_INVALID_RESPONSE);
714BUILD_ASSERT((uint16_t)EC_RES_INVALID_VERSION ==
715 (uint16_t)EC_HOST_CMD_INVALID_VERSION);
716BUILD_ASSERT((uint16_t)EC_RES_INVALID_CHECKSUM ==
717 (uint16_t)EC_HOST_CMD_INVALID_CHECKSUM);
718BUILD_ASSERT((uint16_t)EC_RES_IN_PROGRESS == (uint16_t)EC_HOST_CMD_IN_PROGRESS);
719BUILD_ASSERT((uint16_t)EC_RES_UNAVAILABLE == (uint16_t)EC_HOST_CMD_UNAVAILABLE);
720BUILD_ASSERT((uint16_t)EC_RES_TIMEOUT == (uint16_t)EC_HOST_CMD_TIMEOUT);
721BUILD_ASSERT((uint16_t)EC_RES_OVERFLOW == (uint16_t)EC_HOST_CMD_OVERFLOW);
722BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER ==
723 (uint16_t)EC_HOST_CMD_INVALID_HEADER);
724BUILD_ASSERT((uint16_t)EC_RES_REQUEST_TRUNCATED ==
725 (uint16_t)EC_HOST_CMD_REQUEST_TRUNCATED);
726BUILD_ASSERT((uint16_t)EC_RES_RESPONSE_TOO_BIG ==
727 (uint16_t)EC_HOST_CMD_RESPONSE_TOO_BIG);
728BUILD_ASSERT((uint16_t)EC_RES_BUS_ERROR == (uint16_t)EC_HOST_CMD_BUS_ERROR);
729BUILD_ASSERT((uint16_t)EC_RES_BUSY == (uint16_t)EC_HOST_CMD_BUSY);
730BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_VERSION ==
731 (uint16_t)EC_HOST_CMD_INVALID_HEADER_VERSION);
732BUILD_ASSERT((uint16_t)EC_RES_INVALID_HEADER_CRC ==
733 (uint16_t)EC_HOST_CMD_INVALID_HEADER_CRC);
734BUILD_ASSERT((uint16_t)EC_RES_INVALID_DATA_CRC ==
735 (uint16_t)EC_HOST_CMD_INVALID_DATA_CRC);
736BUILD_ASSERT((uint16_t)EC_RES_DUP_UNAVAILABLE ==
737 (uint16_t)EC_HOST_CMD_DUP_UNAVAILABLE);
738BUILD_ASSERT((uint16_t)EC_RES_MAX == (uint16_t)EC_HOST_CMD_MAX);
739
740#endif
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800741
Aseda Aboagyeabc38122024-04-15 15:39:55 -0500742/* clang-format off */
743#define EC_STATUS_TEXT \
744 { \
745 EC_MAP_ITEM(EC_RES_SUCCESS, SUCCESS), \
746 EC_MAP_ITEM(EC_RES_INVALID_COMMAND, INVALID_COMMAND), \
747 EC_MAP_ITEM(EC_RES_ERROR, ERROR), \
748 EC_MAP_ITEM(EC_RES_INVALID_PARAM, INVALID_PARAM), \
749 EC_MAP_ITEM(EC_RES_ACCESS_DENIED, ACCESS_DENIED), \
750 EC_MAP_ITEM(EC_RES_INVALID_RESPONSE, INVALID_RESPONSE), \
751 EC_MAP_ITEM(EC_RES_INVALID_VERSION, INVALID_VERSION), \
752 EC_MAP_ITEM(EC_RES_INVALID_CHECKSUM, INVALID_CHECKSUM), \
753 EC_MAP_ITEM(EC_RES_IN_PROGRESS, IN_PROGRESS), \
754 EC_MAP_ITEM(EC_RES_UNAVAILABLE, UNAVAILABLE), \
755 EC_MAP_ITEM(EC_RES_TIMEOUT, TIMEOUT), \
756 EC_MAP_ITEM(EC_RES_OVERFLOW, OVERFLOW), \
757 EC_MAP_ITEM(EC_RES_INVALID_HEADER, INVALID_HEADER), \
758 EC_MAP_ITEM(EC_RES_REQUEST_TRUNCATED, REQUEST_TRUNCATED), \
759 EC_MAP_ITEM(EC_RES_RESPONSE_TOO_BIG, RESPONSE_TOO_BIG), \
760 EC_MAP_ITEM(EC_RES_BUS_ERROR, BUS_ERROR), \
761 EC_MAP_ITEM(EC_RES_BUSY, BUSY), \
762 EC_MAP_ITEM(EC_RES_INVALID_HEADER_VERSION, INVALID_HEADER_VERSION), \
763 EC_MAP_ITEM(EC_RES_INVALID_HEADER_CRC, INVALID_HEADER_CRC), \
764 EC_MAP_ITEM(EC_RES_INVALID_DATA_CRC, INVALID_DATA_CRC), \
765 EC_MAP_ITEM(EC_RES_DUP_UNAVAILABLE, DUP_UNAVAILABLE), \
766 }
767/* clang-format on */
768
769#ifndef __cplusplus
770#define EC_MAP_ITEM(k, v) [k] = #v
771BUILD_ASSERT(ARRAY_SIZE(((const char *[])EC_STATUS_TEXT)) == EC_RES_COUNT);
772#undef EC_MAP_ITEM
773#endif
774
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800775/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600776 * Host event codes. ACPI query EC command uses code 0 to mean "no event
777 * pending". We explicitly specify each value in the enum listing so they won't
778 * change if we delete/insert an item or rearrange the list (it needs to be
779 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800780 */
781enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600782 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800783 EC_HOST_EVENT_LID_CLOSED = 1,
784 EC_HOST_EVENT_LID_OPEN = 2,
785 EC_HOST_EVENT_POWER_BUTTON = 3,
786 EC_HOST_EVENT_AC_CONNECTED = 4,
787 EC_HOST_EVENT_AC_DISCONNECTED = 5,
788 EC_HOST_EVENT_BATTERY_LOW = 6,
789 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
790 EC_HOST_EVENT_BATTERY = 8,
791 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700792 /* Event generated by a device attached to the EC */
793 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800794 EC_HOST_EVENT_THERMAL = 11,
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800795 /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */
796 EC_HOST_EVENT_GPU = 12,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800797 EC_HOST_EVENT_KEY_PRESSED = 13,
798 /*
799 * EC has finished initializing the host interface. The host can check
800 * for this event following sending a EC_CMD_REBOOT_EC command to
801 * determine when the EC is ready to accept subsequent commands.
802 */
803 EC_HOST_EVENT_INTERFACE_READY = 14,
804 /* Keyboard recovery combo has been pressed */
805 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
806
807 /* Shutdown due to thermal overload */
808 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
809 /* Shutdown due to battery level too low */
810 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
811
Duncan Laurie93e24442014-01-06 12:30:52 -0800812 /* Suggest that the AP throttle itself */
813 EC_HOST_EVENT_THROTTLE_START = 18,
814 /* Suggest that the AP resume normal speed */
815 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700816
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800817 /* Hang detect logic detected a hang and host event timeout expired */
818 EC_HOST_EVENT_HANG_DETECT = 20,
819 /* Hang detect logic detected a hang and warm rebooted the AP */
820 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700821
822 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700823 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800824
Duncan Lauried8401182014-09-29 08:32:19 -0700825 /* Battery Status flags have changed */
826 EC_HOST_EVENT_BATTERY_STATUS = 23,
827
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700828 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800829 EC_HOST_EVENT_PANIC = 24,
830
Furquan Shaikh066cc852015-06-20 15:53:03 -0700831 /* Keyboard fastboot combo has been pressed */
832 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
833
Gwendal Grignou880b4582016-06-20 08:49:25 -0700834 /* EC RTC event occurred */
835 EC_HOST_EVENT_RTC = 26,
836
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700837 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700838 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700839
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700840 /* EC desires to change state of host-controlled USB mux */
841 EC_HOST_EVENT_USB_MUX = 28,
842
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800843 /*
844 * The device has changed "modes". This can be one of the following:
845 *
846 * - TABLET/LAPTOP mode
847 * - detachable base attach/detach event
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800848 * - on body/off body transition event
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800849 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400850 EC_HOST_EVENT_MODE_CHANGE = 29,
851
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700852 /* Keyboard recovery combo with hardware reinitialization */
853 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
854
Jett Rinkba2edaf2020-01-14 11:49:06 -0700855 /* WoV */
856 EC_HOST_EVENT_WOV = 31,
857
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700858 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800859 * The high bit of the event mask is not used as a host event code. If
860 * it reads back as set, then the entire event mask should be
861 * considered invalid by the host. This can happen when reading the
862 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
863 * not initialized on the EC, or improperly configured on the host.
864 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800865 EC_HOST_EVENT_INVALID = 32,
Tim Van Pattencab60602023-02-24 12:27:04 -0700866
867 /* Body detect (lap/desk) change event */
868 EC_HOST_EVENT_BODY_DETECT_CHANGE = 33,
869
870 /*
871 * Only 64 host events are supported. This enum uses 1-based counting so
872 * it can skip 0 (NONE), so the last legal host event number is 64.
873 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800874};
Tim Van Pattencab60602023-02-24 12:27:04 -0700875
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800876/* Host event mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800877#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800878
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800879/* clang-format off */
880#define HOST_EVENT_TEXT \
881 { \
882 [EC_HOST_EVENT_NONE] = "NONE", \
883 [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \
884 [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \
885 [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \
886 [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \
887 [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \
888 [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \
889 [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \
890 [EC_HOST_EVENT_BATTERY] = "BATTERY", \
891 [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \
892 [EC_HOST_EVENT_DEVICE] = "DEVICE", \
893 [EC_HOST_EVENT_THERMAL] = "THERMAL", \
894 [EC_HOST_EVENT_GPU] = "GPU", \
895 [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \
896 [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \
897 [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \
898 [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \
899 [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \
900 [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \
901 [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \
902 [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \
903 [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \
904 [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \
905 [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \
906 [EC_HOST_EVENT_PANIC] = "PANIC", \
907 [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \
908 [EC_HOST_EVENT_RTC] = "RTC", \
909 [EC_HOST_EVENT_MKBP] = "MKBP", \
910 [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \
911 [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \
912 [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \
913 "KEYBOARD_RECOVERY_HW_REINIT", \
914 [EC_HOST_EVENT_WOV] = "WOV", \
915 [EC_HOST_EVENT_INVALID] = "INVALID", \
Tim Van Pattencab60602023-02-24 12:27:04 -0700916 [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800917 }
918/* clang-format on */
919
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800920/**
921 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
922 * @flags: The host argument flags.
923 * @command_version: Command version.
924 * @data_size: The length of data.
925 * @checksum: Checksum; sum of command + flags + command_version + data_size +
926 * all params/response data bytes.
927 */
928struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800929 uint8_t flags;
930 uint8_t command_version;
931 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800932 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800933} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800934
935/* Flags for ec_lpc_host_args.flags */
936/*
937 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
938 * params.
939 *
940 * If EC gets a command and this flag is not set, this is an old-style command.
941 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
942 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700943 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800944 */
945#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
946/*
947 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
948 *
949 * If EC responds to a command and this flag is not set, this is an old-style
950 * response. Command version is 0 and response data from EC is at
951 * EC_LPC_ADDR_OLD_PARAM with unknown length.
952 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800953#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800954
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800955/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800956/*
957 * Byte codes returned by EC over SPI interface.
958 *
959 * These can be used by the AP to debug the EC interface, and to determine
960 * when the EC is not in a state where it will ever get around to responding
961 * to the AP.
962 *
963 * Example of sequence of bytes read from EC for a current good transfer:
964 * 1. - - AP asserts chip select (CS#)
965 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
966 * 3. - - EC starts handling CS# interrupt
967 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
968 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
969 * bytes looking for EC_SPI_FRAME_START
970 * 6. - - EC finishes processing and sets up response
971 * 7. EC_SPI_FRAME_START - AP reads frame byte
972 * 8. (response packet) - AP reads response packet
973 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
974 * 10 - - AP deasserts chip select
975 * 11 - - EC processes CS# interrupt and sets up DMA for
976 * next request
977 *
978 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
979 * the following byte values:
980 * EC_SPI_OLD_READY
981 * EC_SPI_RX_READY
982 * EC_SPI_RECEIVING
983 * EC_SPI_PROCESSING
984 *
985 * Then the EC found an error in the request, or was not ready for the request
986 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
987 * because the EC is unable to tell when the AP is done sending its request.
988 */
989
990/*
991 * Framing byte which precedes a response packet from the EC. After sending a
992 * request, the AP will clock in bytes until it sees the framing byte, then
993 * clock in the response packet.
994 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800995#define EC_SPI_FRAME_START 0xec
Duncan Laurie93e24442014-01-06 12:30:52 -0800996
997/*
998 * Padding bytes which are clocked out after the end of a response packet.
999 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001000#define EC_SPI_PAST_END 0xed
Duncan Laurie93e24442014-01-06 12:30:52 -08001001
1002/*
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001003 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
Duncan Laurie93e24442014-01-06 12:30:52 -08001004 * that the AP will send a valid packet header (starting with
1005 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001006 *
1007 * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
1008 * CS goes low. This macro has the Most Significant Bit set to zero,
1009 * so SDO will not be driven high when CS goes low.
Duncan Laurie93e24442014-01-06 12:30:52 -08001010 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001011#define EC_SPI_RX_READY 0x78
Duncan Laurie93e24442014-01-06 12:30:52 -08001012
1013/*
1014 * EC has started receiving the request from the AP, but hasn't started
1015 * processing it yet.
1016 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001017#define EC_SPI_RECEIVING 0xf9
Duncan Laurie93e24442014-01-06 12:30:52 -08001018
1019/* EC has received the entire request from the AP and is processing it. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001020#define EC_SPI_PROCESSING 0xfa
Duncan Laurie93e24442014-01-06 12:30:52 -08001021
1022/*
1023 * EC received bad data from the AP, such as a packet header with an invalid
1024 * length. EC will ignore all data until chip select deasserts.
1025 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001026#define EC_SPI_RX_BAD_DATA 0xfb
Duncan Laurie93e24442014-01-06 12:30:52 -08001027
1028/*
1029 * EC received data from the AP before it was ready. That is, the AP asserted
1030 * chip select and started clocking data before the EC was ready to receive it.
1031 * EC will ignore all data until chip select deasserts.
1032 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001033#define EC_SPI_NOT_READY 0xfc
Duncan Laurie93e24442014-01-06 12:30:52 -08001034
1035/*
1036 * EC was ready to receive a request from the AP. EC has treated the byte sent
1037 * by the AP as part of a request packet, or (for old-style ECs) is processing
1038 * a fully received packet but is not ready to respond yet.
1039 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001040#define EC_SPI_OLD_READY 0xfd
Duncan Laurie93e24442014-01-06 12:30:52 -08001041
1042/*****************************************************************************/
1043
1044/*
1045 * Protocol version 2 for I2C and SPI send a request this way:
1046 *
1047 * 0 EC_CMD_VERSION0 + (command version)
1048 * 1 Command number
1049 * 2 Length of params = N
1050 * 3..N+2 Params, if any
1051 * N+3 8-bit checksum of bytes 0..N+2
1052 *
1053 * The corresponding response is:
1054 *
1055 * 0 Result code (EC_RES_*)
1056 * 1 Length of params = M
1057 * 2..M+1 Params, if any
1058 * M+2 8-bit checksum of bytes 0..M+1
1059 */
1060#define EC_PROTO2_REQUEST_HEADER_BYTES 3
1061#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08001062#define EC_PROTO2_REQUEST_OVERHEAD \
1063 (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -08001064
1065#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
1066#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08001067#define EC_PROTO2_RESPONSE_OVERHEAD \
1068 (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -08001069
1070/* Parameter length was limited by the LPC interface */
1071#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
1072
1073/* Maximum request and response packet sizes for protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001074#define EC_PROTO2_MAX_REQUEST_SIZE \
1075 (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
1076#define EC_PROTO2_MAX_RESPONSE_SIZE \
1077 (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
Duncan Laurie93e24442014-01-06 12:30:52 -08001078
1079/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001080
1081/*
1082 * Value written to legacy command port / prefix byte to indicate protocol
1083 * 3+ structs are being used. Usage is bus-dependent.
1084 */
1085#define EC_COMMAND_PROTOCOL_3 0xda
1086
1087#define EC_HOST_REQUEST_VERSION 3
1088
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001089/**
1090 * struct ec_host_request - Version 3 request from host.
1091 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
1092 * receives a header with a version it doesn't know how to
1093 * parse.
1094 * @checksum: Checksum of request and data; sum of all bytes including checksum
1095 * should total to 0.
1096 * @command: Command to send (EC_CMD_...)
1097 * @command_version: Command version.
1098 * @reserved: Unused byte in current protocol version; set to 0.
1099 * @data_len: Length of data which follows this header.
1100 */
1101struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001102 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001103 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001104 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001105 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001106 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001107 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001108} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001109
1110#define EC_HOST_RESPONSE_VERSION 3
1111
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001112/**
1113 * struct ec_host_response - Version 3 response from EC.
1114 * @struct_version: Struct version (=3).
1115 * @checksum: Checksum of response and data; sum of all bytes including
1116 * checksum should total to 0.
1117 * @result: EC's response to the command (separate from communication failure)
1118 * @data_len: Length of data which follows this header.
1119 * @reserved: Unused bytes in current protocol version; set to 0.
1120 */
1121struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001122 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001123 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001124 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001125 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001126 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001127} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001128
1129/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001130
1131/*
1132 * Host command protocol V4.
1133 *
1134 * Packets always start with a request or response header. They are followed
1135 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +01001136 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001137 * polynomial.
1138 *
1139 * Host algorithm when sending a request q:
1140 *
1141 * 101) tries_left=(some value, e.g. 3);
1142 * 102) q.seq_num++
1143 * 103) q.seq_dup=0
1144 * 104) Calculate q.header_crc.
1145 * 105) Send request q to EC.
1146 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
1147 *
1148 * 201) If r.struct_version != 4, go to 301.
1149 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
1150 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
1151 * 204) If r.seq_num != q.seq_num, go to 301.
1152 * 205) If r.seq_dup == q.seq_dup, return success.
1153 * 207) If r.seq_dup == 1, go to 301.
1154 * 208) Return error.
1155 *
1156 * 301) If --tries_left <= 0, return error.
1157 * 302) If q.seq_dup == 1, go to 105.
1158 * 303) q.seq_dup = 1
1159 * 304) Go to 104.
1160 *
1161 * EC algorithm when receiving a request q.
1162 * EC has response buffer r, error buffer e.
1163 *
1164 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
1165 * and go to 301
1166 * 102) If q.header_crc mismatches calculated CRC, set e.result =
1167 * EC_RES_INVALID_HEADER_CRC and go to 301
1168 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
1169 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
1170 * and go to 301.
1171 * 104) If q.seq_dup == 0, go to 201.
1172 * 105) If q.seq_num != r.seq_num, go to 201.
1173 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
1174 *
1175 * 201) Process request q into response r.
1176 * 202) r.seq_num = q.seq_num
1177 * 203) r.seq_dup = q.seq_dup
1178 * 204) Calculate r.header_crc
1179 * 205) If r.data_len > 0 and data is no longer available, set e.result =
1180 * EC_RES_DUP_UNAVAILABLE and go to 301.
1181 * 206) Send response r.
1182 *
1183 * 301) e.seq_num = q.seq_num
1184 * 302) e.seq_dup = q.seq_dup
1185 * 303) Calculate e.header_crc.
1186 * 304) Send error response e.
1187 */
1188
1189/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001190struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001191 /*
1192 * bits 0-3: struct_version: Structure version (=4)
1193 * bit 4: is_response: Is response (=0)
1194 * bits 5-6: seq_num: Sequence number
1195 * bit 7: seq_dup: Sequence duplicate flag
1196 */
1197 uint8_t fields0;
1198
1199 /*
1200 * bits 0-4: command_version: Command version
1201 * bits 5-6: Reserved (set 0, ignore on read)
1202 * bit 7: data_crc_present: Is data CRC present after data
1203 */
1204 uint8_t fields1;
1205
1206 /* Command code (EC_CMD_*) */
1207 uint16_t command;
1208
1209 /* Length of data which follows this header (not including data CRC) */
1210 uint16_t data_len;
1211
1212 /* Reserved (set 0, ignore on read) */
1213 uint8_t reserved;
1214
1215 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1216 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001217} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001218
1219/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001220struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001221 /*
1222 * bits 0-3: struct_version: Structure version (=4)
1223 * bit 4: is_response: Is response (=1)
1224 * bits 5-6: seq_num: Sequence number
1225 * bit 7: seq_dup: Sequence duplicate flag
1226 */
1227 uint8_t fields0;
1228
1229 /*
1230 * bits 0-6: Reserved (set 0, ignore on read)
1231 * bit 7: data_crc_present: Is data CRC present after data
1232 */
1233 uint8_t fields1;
1234
1235 /* Result code (EC_RES_*) */
1236 uint16_t result;
1237
1238 /* Length of data which follows this header (not including data CRC) */
1239 uint16_t data_len;
1240
1241 /* Reserved (set 0, ignore on read) */
1242 uint8_t reserved;
1243
1244 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1245 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001246} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001247
1248/* Fields in fields0 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001249#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1250#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1251#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1252#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1253#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001254
1255/* Fields in fields1 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001256#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1257#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001258
1259/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001260/*
1261 * Notes on commands:
1262 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001263 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001264 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001265 * specified, the command does not input or output data, respectively.
1266 * Parameter/response length is implicit in the structs. Some underlying
1267 * communication protocols (I2C, SPI) may add length or checksum headers, but
1268 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001269 *
1270 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1271 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001272 */
1273
1274/*****************************************************************************/
1275/* General / test commands */
1276
1277/*
1278 * Get protocol version, used to deal with non-backward compatible protocol
1279 * changes.
1280 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001281#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001282
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001283/**
1284 * struct ec_response_proto_version - Response to the proto version command.
1285 * @version: The protocol version.
1286 */
1287struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001288 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001289} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001290
1291/*
1292 * Hello. This is a simple command to test the EC is responsive to
1293 * commands.
1294 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001295#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001297/**
1298 * struct ec_params_hello - Parameters to the hello command.
1299 * @in_data: Pass anything here.
1300 */
1301struct ec_params_hello {
1302 uint32_t in_data;
1303} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001304
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001305/**
1306 * struct ec_response_hello - Response to the hello command.
1307 * @out_data: Output will be in_data + 0x01020304.
1308 */
1309struct ec_response_hello {
1310 uint32_t out_data;
1311} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001312
1313/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001314#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001315
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001316enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001317 EC_IMAGE_UNKNOWN = 0,
1318 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001319 EC_IMAGE_RW,
1320 EC_IMAGE_RW_A = EC_IMAGE_RW,
1321 EC_IMAGE_RO_B,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001322 EC_IMAGE_RW_B,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001323};
1324
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001325/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001326 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001327 * @version_string_ro: Null-terminated RO firmware version string.
1328 * @version_string_rw: Null-terminated RW firmware version string.
1329 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001330 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001331 */
1332struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001333 char version_string_ro[32];
1334 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001335 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001336 uint32_t current_image;
1337} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001338
Rob Barnes5ab14662021-09-17 10:24:45 -06001339/**
1340 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1341 *
1342 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1343 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1344 * and adds one additional field (cros_fwid_rw).
1345 *
1346 * @version_string_ro: Null-terminated RO firmware version string.
1347 * @version_string_rw: Null-terminated RW firmware version string.
1348 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1349 * @current_image: One of ec_image.
1350 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1351 */
1352struct ec_response_get_version_v1 {
1353 char version_string_ro[32];
1354 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001355 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
Rob Barnes5ab14662021-09-17 10:24:45 -06001356 uint32_t current_image;
Caveh Jalali024ffe32023-01-30 14:35:19 -08001357 char cros_fwid_rw[32]; /* Added in version 1 */
Rob Barnes5ab14662021-09-17 10:24:45 -06001358} __ec_align4;
1359
Caveh Jalali839ada12022-10-31 23:16:48 -07001360/* Read test - OBSOLETE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001361#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001362
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001363/*
1364 * Get build information
1365 *
1366 * Response is null-terminated string.
1367 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001368#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001369
1370/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001371#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001372
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001373/**
1374 * struct ec_response_get_chip_info - Response to the get chip info command.
1375 * @vendor: Null-terminated string for chip vendor.
1376 * @name: Null-terminated string for chip name.
1377 * @revision: Null-terminated string for chip mask version.
1378 */
1379struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001380 char vendor[32];
1381 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001382 char revision[32];
1383} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001384
1385/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001386#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001387
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001388/**
1389 * struct ec_response_board_version - Response to the board version command.
1390 * @board_version: A monotonously incrementing number.
1391 */
1392struct ec_response_board_version {
1393 uint16_t board_version;
1394} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001395
1396/*
1397 * Read memory-mapped data.
1398 *
1399 * This is an alternate interface to memory-mapped data for bus protocols
1400 * which don't support direct-mapped memory - I2C, SPI, etc.
1401 *
1402 * Response is params.size bytes of data.
1403 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001404#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001405
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001406/**
1407 * struct ec_params_read_memmap - Parameters for the read memory map command.
1408 * @offset: Offset in memmap (EC_MEMMAP_*).
1409 * @size: Size to read in bytes.
1410 */
1411struct ec_params_read_memmap {
1412 uint8_t offset;
1413 uint8_t size;
1414} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001415
1416/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001417#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001418
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001419/**
1420 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1421 * @cmd: Command to check.
1422 */
1423struct ec_params_get_cmd_versions {
1424 uint8_t cmd;
1425} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001426
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001427/**
1428 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1429 * versions (v1)
1430 * @cmd: Command to check.
1431 */
1432struct ec_params_get_cmd_versions_v1 {
1433 uint16_t cmd;
1434} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001435
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001436/**
1437 * struct ec_response_get_cmd_version - Response to the get command versions.
1438 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1439 * a desired version.
1440 */
1441struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001442 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001443} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001444
Duncan Laurie433432b2013-06-03 10:38:22 -07001445/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001446 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001447 * on lpc since it has its own out-of-band busy indicator.
1448 *
1449 * lpc must read the status from the command register. Attempting this on
1450 * lpc will overwrite the args/parameter space and corrupt its data.
1451 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001452#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001453
1454/* Avoid using ec_status which is for return values */
1455enum ec_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001456 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001457};
1458
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001459/**
1460 * struct ec_response_get_comms_status - Response to the get comms status
1461 * command.
1462 * @flags: Mask of enum ec_comms_status.
1463 */
1464struct ec_response_get_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001465 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001466} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001467
Duncan Laurie93e24442014-01-06 12:30:52 -08001468/* Fake a variety of responses, purely for testing purposes. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001469#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001470
1471/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001472struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001473 uint32_t ec_result;
1474 uint32_t ret_len;
1475 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001476} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001477
1478/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001479struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001480 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001481} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001482
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001483/* Get protocol information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001484#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001485
1486/* Flags for ec_response_get_protocol_info.flags */
1487/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001488#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001489
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001490/**
1491 * struct ec_response_get_protocol_info - Response to the get protocol info.
1492 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1493 * version n).
1494 * @max_request_packet_size: Maximum request packet size in bytes.
1495 * @max_response_packet_size: Maximum response packet size in bytes.
1496 * @flags: see EC_PROTOCOL_INFO_*
1497 */
1498struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001499 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001500 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001501 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001502 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001503 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001504} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001505
Duncan Laurie93e24442014-01-06 12:30:52 -08001506/*****************************************************************************/
1507/* Get/Set miscellaneous values */
1508
1509/* The upper byte of .flags tells what to do (nothing means "get") */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001510#define EC_GSV_SET 0x80000000
Duncan Laurie93e24442014-01-06 12:30:52 -08001511
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001512/*
1513 * The lower three bytes of .flags identifies the parameter, if that has
1514 * meaning for an individual command.
1515 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001516#define EC_GSV_PARAM_MASK 0x00ffffff
1517
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001518struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001519 uint32_t flags;
1520 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001521} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001522
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001523struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001524 uint32_t flags;
1525 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001526} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001527
Duncan Laurieeb316852015-12-01 18:51:18 -08001528/* More than one command can use these structs to get/set parameters. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001529#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001530
Duncan Laurieeb316852015-12-01 18:51:18 -08001531/*****************************************************************************/
1532/* List the features supported by the firmware */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001533#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001534
1535/* Supported features */
1536enum ec_feature_code {
1537 /*
1538 * This image contains a limited set of features. Another image
1539 * in RW partition may support more features.
1540 */
1541 EC_FEATURE_LIMITED = 0,
1542 /*
1543 * Commands for probing/reading/writing/erasing the flash in the
1544 * EC are present.
1545 */
1546 EC_FEATURE_FLASH = 1,
1547 /*
1548 * Can control the fan speed directly.
1549 */
1550 EC_FEATURE_PWM_FAN = 2,
1551 /*
1552 * Can control the intensity of the keyboard backlight.
1553 */
1554 EC_FEATURE_PWM_KEYB = 3,
1555 /*
1556 * Support Google lightbar, introduced on Pixel.
1557 */
1558 EC_FEATURE_LIGHTBAR = 4,
1559 /* Control of LEDs */
1560 EC_FEATURE_LED = 5,
1561 /* Exposes an interface to control gyro and sensors.
1562 * The host goes through the EC to access these sensors.
1563 * In addition, the EC may provide composite sensors, like lid angle.
1564 */
1565 EC_FEATURE_MOTION_SENSE = 6,
1566 /* The keyboard is controlled by the EC */
1567 EC_FEATURE_KEYB = 7,
1568 /* The AP can use part of the EC flash as persistent storage. */
1569 EC_FEATURE_PSTORE = 8,
1570 /* The EC monitors BIOS port 80h, and can return POST codes. */
1571 EC_FEATURE_PORT80 = 9,
1572 /*
1573 * Thermal management: include TMP specific commands.
1574 * Higher level than direct fan control.
1575 */
1576 EC_FEATURE_THERMAL = 10,
1577 /* Can switch the screen backlight on/off */
1578 EC_FEATURE_BKLIGHT_SWITCH = 11,
1579 /* Can switch the wifi module on/off */
1580 EC_FEATURE_WIFI_SWITCH = 12,
1581 /* Monitor host events, through for example SMI or SCI */
1582 EC_FEATURE_HOST_EVENTS = 13,
1583 /* The EC exposes GPIO commands to control/monitor connected devices. */
1584 EC_FEATURE_GPIO = 14,
1585 /* The EC can send i2c messages to downstream devices. */
1586 EC_FEATURE_I2C = 15,
1587 /* Command to control charger are included */
1588 EC_FEATURE_CHARGER = 16,
1589 /* Simple battery support. */
1590 EC_FEATURE_BATTERY = 17,
1591 /*
1592 * Support Smart battery protocol
1593 * (Common Smart Battery System Interface Specification)
1594 */
1595 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001596 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001597 EC_FEATURE_HANG_DETECT = 19,
1598 /* Report power information, for pit only */
1599 EC_FEATURE_PMU = 20,
1600 /* Another Cros EC device is present downstream of this one */
1601 EC_FEATURE_SUB_MCU = 21,
1602 /* Support USB Power delivery (PD) commands */
1603 EC_FEATURE_USB_PD = 22,
1604 /* Control USB multiplexer, for audio through USB port for instance. */
1605 EC_FEATURE_USB_MUX = 23,
1606 /* Motion Sensor code has an internal software FIFO */
1607 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1608 /* Support temporary secure vstore */
1609 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001610 /* EC decides on USB-C SS mux state, muxes configured by host */
1611 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1612 /* EC has RTC feature that can be controlled by host commands */
1613 EC_FEATURE_RTC = 27,
1614 /* The MCU exposes a Fingerprint sensor */
1615 EC_FEATURE_FINGERPRINT = 28,
1616 /* The MCU exposes a Touchpad */
1617 EC_FEATURE_TOUCHPAD = 29,
1618 /* The MCU has RWSIG task enabled */
1619 EC_FEATURE_RWSIG = 30,
1620 /* EC has device events support */
1621 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001622 /* EC supports the unified wake masks for LPC/eSPI systems */
1623 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001624 /* EC supports 64-bit host events */
1625 EC_FEATURE_HOST_EVENT64 = 33,
1626 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1627 EC_FEATURE_EXEC_IN_RAM = 34,
1628 /* EC supports CEC commands */
1629 EC_FEATURE_CEC = 35,
1630 /* EC supports tight sensor timestamping. */
1631 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001632 /*
1633 * EC supports tablet mode detection aligned to Chrome and allows
1634 * setting of threshold by host command using
1635 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1636 */
1637 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001638 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001639 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001640 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1641 * be sent to RO to be precise.
1642 */
1643 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001644 /* The MCU is a System Companion Processor (SCP). */
1645 EC_FEATURE_SCP = 39,
1646 /* The MCU is an Integrated Sensor Hub */
1647 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001648 /* New TCPMv2 TYPEC_ prefaced commands supported */
1649 EC_FEATURE_TYPEC_CMD = 41,
1650 /*
1651 * The EC will wait for direction from the AP to enter Type-C alternate
1652 * modes or USB4.
1653 */
1654 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1655 /*
1656 * The EC will wait for an acknowledge from the AP after setting the
1657 * mux.
1658 */
1659 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001660 /*
1661 * The EC supports entering and residing in S4.
1662 */
1663 EC_FEATURE_S4_RESIDENCY = 44,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001664 /*
1665 * The EC supports the AP directing mux sets for the board.
1666 */
1667 EC_FEATURE_TYPEC_AP_MUX_SET = 45,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001668 /*
1669 * The EC supports the AP composing VDMs for us to send.
1670 */
1671 EC_FEATURE_TYPEC_AP_VDM_SEND = 46,
Simon Glassd3870a22023-11-09 08:43:30 -07001672 /*
1673 * The EC supports system safe mode panic recovery.
1674 */
1675 EC_FEATURE_SYSTEM_SAFE_MODE = 47,
1676 /*
1677 * The EC will reboot on runtime assertion failures.
1678 */
1679 EC_FEATURE_ASSERT_REBOOTS = 48,
1680 /*
1681 * The EC image is built with tokenized logging enabled.
1682 */
1683 EC_FEATURE_TOKENIZED_LOGGING = 49,
1684 /*
1685 * The EC supports triggering an STB dump.
1686 */
1687 EC_FEATURE_AMD_STB_DUMP = 50,
1688 /*
1689 * The EC supports memory dump commands.
1690 */
1691 EC_FEATURE_MEMORY_DUMP = 51,
1692 /*
1693 * The EC supports DP2.1 capability
1694 */
1695 EC_FEATURE_TYPEC_DP2_1 = 52,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05001696 /*
1697 * The MCU is System Companion Processor Core 1
1698 */
1699 EC_FEATURE_SCP_C1 = 53,
Duncan Laurieeb316852015-12-01 18:51:18 -08001700};
1701
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001702#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1703#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1704
1705struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001706 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001707} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001708
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001709/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001710/* Get the board's SKU ID from EC */
1711#define EC_CMD_GET_SKU_ID 0x000E
1712
Kevin Chiue2bb0592017-09-12 09:13:41 +08001713/* Set SKU ID from AP */
1714#define EC_CMD_SET_SKU_ID 0x000F
1715
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001716struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001717 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001718} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001719
1720/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001721/* Flash commands */
1722
1723/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001724#define EC_CMD_FLASH_INFO 0x0010
1725#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001726
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001727/**
1728 * struct ec_response_flash_info - Response to the flash info command.
1729 * @flash_size: Usable flash size in bytes.
1730 * @write_block_size: Write block size. Write offset and size must be a
1731 * multiple of this.
1732 * @erase_block_size: Erase block size. Erase offset and size must be a
1733 * multiple of this.
1734 * @protect_block_size: Protection block size. Protection offset and size
1735 * must be a multiple of this.
1736 *
1737 * Version 0 returns these fields.
1738 */
1739struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001740 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001741 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001742 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001743 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001744} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001745
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001746/*
1747 * Flags for version 1+ flash info command
1748 * EC flash erases bits to 0 instead of 1.
1749 */
1750#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001751
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001752/*
1753 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001754 * be necessary on a chip where write/erase can be corrupted by other board
1755 * activity, or where the chip needs to enable some sort of programming voltage,
1756 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001757 * chip functionality.
1758 */
1759#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001760
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001761/**
1762 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1763 * @flash_size: Usable flash size in bytes.
1764 * @write_block_size: Write block size. Write offset and size must be a
1765 * multiple of this.
1766 * @erase_block_size: Erase block size. Erase offset and size must be a
1767 * multiple of this.
1768 * @protect_block_size: Protection block size. Protection offset and size
1769 * must be a multiple of this.
1770 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1771 * size is exactly this and offset is a multiple of this.
1772 * For example, an EC may have a write buffer which can do
1773 * half-page operations if data is aligned, and a slower
1774 * word-at-a-time write mode.
1775 * @flags: Flags; see EC_FLASH_INFO_*
1776 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001777 * Version 1 returns the same initial fields as version 0, with additional
1778 * fields following.
1779 *
1780 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001781 * if they did we'd define the version 0 structure as a sub-structure of this
1782 * one.
1783 *
1784 * Version 2 supports flash banks of different sizes:
1785 * The caller specified the number of banks it has preallocated
1786 * (num_banks_desc)
1787 * The EC returns the number of banks describing the flash memory.
1788 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001789 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001790struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001791 /* Version 0 fields; see above for description */
1792 uint32_t flash_size;
1793 uint32_t write_block_size;
1794 uint32_t erase_block_size;
1795 uint32_t protect_block_size;
1796
1797 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001798 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001799 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001800} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001801
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001802struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001803 /* Number of banks to describe */
1804 uint16_t num_banks_desc;
1805 /* Reserved; set 0; ignore on read */
1806 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001807} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001808
1809struct ec_flash_bank {
1810 /* Number of sector is in this bank. */
1811 uint16_t count;
1812 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1813 uint8_t size_exp;
1814 /* Minimal write size for the sectors in this bank */
1815 uint8_t write_size_exp;
1816 /* Erase size for the sectors in this bank */
1817 uint8_t erase_size_exp;
1818 /* Size for write protection, usually identical to erase size. */
1819 uint8_t protect_size_exp;
1820 /* Reserved; set 0; ignore on read */
1821 uint8_t reserved[2];
1822};
1823
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001824struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001825 /* Total flash in the EC. */
1826 uint32_t flash_size;
1827 /* Flags; see EC_FLASH_INFO_* */
1828 uint32_t flags;
1829 /* Maximum size to use to send data to write to the EC. */
1830 uint32_t write_ideal_size;
1831 /* Number of banks present in the EC. */
1832 uint16_t num_banks_total;
1833 /* Number of banks described in banks array. */
1834 uint16_t num_banks_desc;
1835 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001836} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001837
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001838/*
1839 * Read flash
1840 *
1841 * Response is params.size bytes of data.
1842 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001843#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001844
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001845/**
1846 * struct ec_params_flash_read - Parameters for the flash read command.
1847 * @offset: Byte offset to read.
1848 * @size: Size to read in bytes.
1849 */
1850struct ec_params_flash_read {
1851 uint32_t offset;
1852 uint32_t size;
1853} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001854
1855/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001856#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001857#define EC_VER_FLASH_WRITE 1
1858
1859/* Version 0 of the flash command supported only 64 bytes of data */
1860#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001861
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001862/**
1863 * struct ec_params_flash_write - Parameters for the flash write command.
1864 * @offset: Byte offset to write.
1865 * @size: Size to write in bytes.
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001866 * @data: Data to write.
1867 * @data.words32: uint32_t data to write.
1868 * @data.bytes: uint8_t data to write.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001869 */
1870struct ec_params_flash_write {
1871 uint32_t offset;
1872 uint32_t size;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001873 /* Followed by data to write. This union allows accessing an
1874 * underlying buffer as uint32s or uint8s for convenience.
1875 */
1876 union {
1877 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1878 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1879 } data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001880} __ec_align4;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001881BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001882
1883/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001884#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001885
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001886/**
1887 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1888 * @offset: Byte offset to erase.
1889 * @size: Size to erase in bytes.
1890 */
1891struct ec_params_flash_erase {
1892 uint32_t offset;
1893 uint32_t size;
1894} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001895
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001896/*
1897 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001898 * subcommands can returns:
1899 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1900 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1901 * EC_RES_ERROR : other errors.
1902 * EC_RES_BUSY : an existing erase operation is in progress.
1903 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1904 *
1905 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1906 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1907 * the proper result.
1908 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1909 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1910 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1911 * permitted while erasing. (For instance, STM32F4).
1912 */
1913enum ec_flash_erase_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001914 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1915 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1916 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001917};
1918
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001919/**
1920 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1921 * @cmd: One of ec_flash_erase_cmd.
1922 * @reserved: Pad byte; currently always contains 0.
1923 * @flag: No flags defined yet; set to 0.
1924 * @params: Same as v0 parameters.
1925 */
1926struct ec_params_flash_erase_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001927 uint8_t cmd;
1928 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001929 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001930 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001931} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001932
1933/*
1934 * Get/set flash protection.
1935 *
1936 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1937 * firmware write protect GPIO, not all flags will take effect immediately;
1938 * some flags require a subsequent hard reset to take effect. Check the
1939 * returned flags bits to see what actually happened.
1940 *
1941 * If mask=0, simply returns the current flags state.
1942 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001943#define EC_CMD_FLASH_PROTECT 0x0015
Caveh Jalali024ffe32023-01-30 14:35:19 -08001944#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001945
1946/* Flags for flash protection */
1947/* RO flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001948#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001949/*
1950 * RO flash code protected now. If this bit is set, at-boot status cannot
1951 * be changed.
1952 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001953#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001954/* Entire flash code protected now, until reboot. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001955#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001956/* Flash write protect GPIO is asserted now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001957#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001958/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001959#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001960/*
1961 * Error - flash protection is in inconsistent state. At least one bank of
1962 * flash which should be protected is not protected. Usually fixed by
1963 * re-requesting the desired flags, or by a hard reset if that fails.
1964 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001965#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001966/* Entire flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001967#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001968/* RW flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001969#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001970/* RW flash code protected now. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001971#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001972/* Rollback information flash region protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001973#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001974/* Rollback information flash region protected now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001975#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001976/* Error - Unknown error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001977#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001978
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001979/**
1980 * struct ec_params_flash_protect - Parameters for the flash protect command.
1981 * @mask: Bits in flags to apply.
1982 * @flags: New flags to apply.
1983 */
1984struct ec_params_flash_protect {
1985 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001986 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001987} __ec_align4;
1988
Simon Glassd3870a22023-11-09 08:43:30 -07001989enum flash_protect_action {
1990 FLASH_PROTECT_ASYNC = 0,
1991 FLASH_PROTECT_GET_RESULT = 1,
1992};
1993
1994/* Version 2 of the command is "asynchronous". */
1995struct ec_params_flash_protect_v2 {
1996 uint8_t action; /**< enum flash_protect_action */
1997 uint8_t reserved[3]; /**< padding for alignment */
1998 uint32_t mask;
1999 uint32_t flags;
2000} __ec_align4;
2001
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002002/**
2003 * struct ec_response_flash_protect - Response to the flash protect command.
2004 * @flags: Current value of flash protect flags.
2005 * @valid_flags: Flags which are valid on this platform. This allows the
2006 * caller to distinguish between flags which aren't set vs. flags
2007 * which can't be set on this platform.
2008 * @writable_flags: Flags which can be changed given the current protection
2009 * state.
2010 */
2011struct ec_response_flash_protect {
2012 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002013 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002014 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002015} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002016
2017/*
2018 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
2019 * write protect. These commands may be reused with version > 0.
2020 */
2021
2022/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002023#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002024#define EC_VER_FLASH_REGION_INFO 1
2025
2026enum ec_flash_region {
2027 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08002028 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002029 /*
2030 * Region which holds active RW image. 'Active' is different from
2031 * 'running'. Active means 'scheduled-to-run'. Since RO image always
2032 * scheduled to run, active/non-active applies only to RW images (for
2033 * the same reason 'update' applies only to RW images. It's a state of
2034 * an image on a flash. Running image can be RO, RW_A, RW_B but active
2035 * image can only be RW_A or RW_B. In recovery mode, an active RW image
2036 * doesn't enter 'running' state but it's still active on a flash.
2037 */
2038 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002039 /*
2040 * Region which should be write-protected in the factory (a superset of
2041 * EC_FLASH_REGION_RO)
2042 */
2043 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002044 /* Region which holds updatable (non-active) RW image */
2045 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08002046 /* Number of regions */
2047 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002048};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002049/*
2050 * 'RW' is vague if there are multiple RW images; we mean the active one,
2051 * so the old constant is deprecated.
2052 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002053#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002054
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002055/**
2056 * struct ec_params_flash_region_info - Parameters for the flash region info
2057 * command.
2058 * @region: Flash region; see EC_FLASH_REGION_*
2059 */
2060struct ec_params_flash_region_info {
2061 uint32_t region;
2062} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002063
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002064struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002065 uint32_t offset;
2066 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002067} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002068
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002069/* Get SPI flash information */
2070#define EC_CMD_FLASH_SPI_INFO 0x0018
2071
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002072struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002073 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
2074 uint8_t jedec[3];
2075
2076 /* Pad byte; currently always contains 0 */
2077 uint8_t reserved0;
2078
2079 /* Manufacturer / device ID from command 0x90 */
2080 uint8_t mfr_dev_id[2];
2081
2082 /* Status registers from command 0x05 and 0x35 */
2083 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002084} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002085
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002086/* Select flash during flash operations */
2087#define EC_CMD_FLASH_SELECT 0x0019
2088
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002089/**
2090 * struct ec_params_flash_select - Parameters for the flash select command.
2091 * @select: 1 to select flash, 0 to deselect flash
2092 */
2093struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002094 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002095} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002097/**
2098 * Request random numbers to be generated and returned.
2099 * Can be used to test the random number generator is truly random.
2100 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
2101 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
2102 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002103#define EC_CMD_RAND_NUM 0x001A
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002104#define EC_VER_RAND_NUM 0
2105
2106struct ec_params_rand_num {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002107 uint16_t num_rand_bytes; /**< num random bytes to generate */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002108} __ec_align4;
2109
2110struct ec_response_rand_num {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002111 /**
2112 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
2113 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
2114 */
2115 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
2116} __ec_align1;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002117BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
2118
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002119/**
2120 * Get information about the key used to sign the RW firmware.
2121 * For more details on the fields, see "struct vb21_packed_key".
2122 */
2123#define EC_CMD_RWSIG_INFO 0x001B
2124#define EC_VER_RWSIG_INFO 0
2125
2126#define VBOOT2_KEY_ID_BYTES 20
2127
2128#ifdef CHROMIUM_EC
2129/* Don't force external projects to depend on the vboot headers. */
2130#include "vb21_struct.h"
2131BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
2132#endif
2133
2134struct ec_response_rwsig_info {
2135 /**
2136 * Signature algorithm used by the key
2137 * (enum vb2_signature_algorithm).
2138 */
2139 uint16_t sig_alg;
2140
2141 /**
2142 * Hash digest algorithm used with the key
2143 * (enum vb2_hash_algorithm).
2144 */
2145 uint16_t hash_alg;
2146
2147 /** Key version. */
2148 uint32_t key_version;
2149
2150 /** Key ID (struct vb2_id). */
2151 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2152
2153 uint8_t key_is_valid;
2154
2155 /** Alignment padding. */
2156 uint8_t reserved[3];
2157} __ec_align4;
2158
2159BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2160
2161/**
2162 * Get information about the system, such as reset flags, locked state, etc.
2163 */
2164#define EC_CMD_SYSINFO 0x001C
2165#define EC_VER_SYSINFO 0
2166
2167enum sysinfo_flags {
2168 SYSTEM_IS_LOCKED = BIT(0),
2169 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2170 SYSTEM_JUMP_ENABLED = BIT(2),
2171 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08002172 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2173 /*
2174 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2175 * set and cleared when the system shuts down (not when the host event
2176 * flag is cleared).
2177 */
2178 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002179};
2180
2181struct ec_response_sysinfo {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002182 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002183 uint32_t current_image; /**< enum ec_image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002184 uint32_t flags; /**< enum sysinfo_flags */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002185} __ec_align4;
2186
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002187/*****************************************************************************/
2188/* PWM commands */
2189
2190/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002191#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002193struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002194 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002195} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002196
2197/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002198#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002199
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002200/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002201struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002202 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002203} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002204
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002205/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002206struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002207 uint32_t rpm;
2208 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002209} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002210
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002211/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002212/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002213#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002214
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002215struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002216 uint8_t percent;
2217 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002218} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002219
2220/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002221/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002222#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002223
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002224struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002225 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002226} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002227
2228/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002229#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002230
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002231/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002232struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002233 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002234} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002235
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002236/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002237struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002238 uint32_t percent;
2239 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002240} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002241
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002242#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002243/* 16 bit duty cycle, 0xffff = 100% */
2244#define EC_PWM_MAX_DUTY 0xffff
2245
2246enum ec_pwm_type {
2247 /* All types, indexed by board-specific enum pwm_channel */
2248 EC_PWM_TYPE_GENERIC = 0,
2249 /* Keyboard backlight */
2250 EC_PWM_TYPE_KB_LIGHT,
2251 /* Display backlight */
2252 EC_PWM_TYPE_DISPLAY_LIGHT,
2253 EC_PWM_TYPE_COUNT,
2254};
2255
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002256struct ec_params_pwm_set_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002257 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2258 uint8_t pwm_type; /* ec_pwm_type */
2259 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002260} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002261
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002262#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002263
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002264struct ec_params_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002265 uint8_t pwm_type; /* ec_pwm_type */
2266 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002267} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002268
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002269struct ec_response_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002270 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002271} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002272
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002273/*****************************************************************************/
2274/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002275 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002276 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2277 * into a subcommand. We'll make separate structs for subcommands with
2278 * different input args, so that we know how much to expect.
2279 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002280#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002281
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002282struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002283 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002284} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002285
Duncan Laurie433432b2013-06-03 10:38:22 -07002286#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002287
2288/*
2289 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002290 * host command, but the alignment is the same regardless. Keep it that way.
2291 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002292struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002293 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002294 int32_t google_ramp_up;
2295 int32_t google_ramp_down;
2296 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002297 int32_t s0_tick_delay[2]; /* AC=0/1 */
2298 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie93e24442014-01-06 12:30:52 -08002299 int32_t s0s3_ramp_down;
2300 int32_t s3_sleep_for;
2301 int32_t s3_ramp_up;
2302 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002303
2304 /* Oscillation */
2305 uint8_t new_s0;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002306 uint8_t osc_min[2]; /* AC=0/1 */
2307 uint8_t osc_max[2]; /* AC=0/1 */
2308 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002309
2310 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002311 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2312 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2313 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002314
2315 /* Battery level thresholds */
2316 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2317
2318 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002319 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2320 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie433432b2013-06-03 10:38:22 -07002321
2322 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002323 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002324} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002325
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002326struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002327 /* Timing */
2328 int32_t google_ramp_up;
2329 int32_t google_ramp_down;
2330 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002331 int32_t s0_tick_delay[2]; /* AC=0/1 */
2332 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002333 int32_t s0s3_ramp_down;
2334 int32_t s3_sleep_for;
2335 int32_t s3_ramp_up;
2336 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002337 int32_t s5_ramp_up;
2338 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002339 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002340 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002341 int32_t tap_display_time;
2342
2343 /* Tap-for-battery params */
2344 uint8_t tap_pct_red;
2345 uint8_t tap_pct_green;
2346 uint8_t tap_seg_min_on;
2347 uint8_t tap_seg_max_on;
2348 uint8_t tap_seg_osc;
2349 uint8_t tap_idx[3];
2350
2351 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002352 uint8_t osc_min[2]; /* AC=0/1 */
2353 uint8_t osc_max[2]; /* AC=0/1 */
2354 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002355
2356 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002357 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2358 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2359 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002360
2361 /* Battery level thresholds */
2362 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2363
2364 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002365 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2366 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002367
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002368 /* s5: single color pulse on inhibited power-up */
2369 uint8_t s5_idx;
2370
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002371 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002372 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002373} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002374
Duncan Laurieeb316852015-12-01 18:51:18 -08002375/* Lightbar command params v2
2376 * crbug.com/467716
2377 *
2378 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2379 * logical groups to make it more manageable ( < 120 bytes).
2380 *
2381 * NOTE: Each of these groups must be less than 120 bytes.
2382 */
2383
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002384struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002385 /* Timing */
2386 int32_t google_ramp_up;
2387 int32_t google_ramp_down;
2388 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002389 int32_t s0_tick_delay[2]; /* AC=0/1 */
2390 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002391 int32_t s0s3_ramp_down;
2392 int32_t s3_sleep_for;
2393 int32_t s3_ramp_up;
2394 int32_t s3_ramp_down;
2395 int32_t s5_ramp_up;
2396 int32_t s5_ramp_down;
2397 int32_t tap_tick_delay;
2398 int32_t tap_gate_delay;
2399 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002400} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002401
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002402struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002403 /* Tap-for-battery params */
2404 uint8_t tap_pct_red;
2405 uint8_t tap_pct_green;
2406 uint8_t tap_seg_min_on;
2407 uint8_t tap_seg_max_on;
2408 uint8_t tap_seg_osc;
2409 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002410} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002411
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002412struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002413 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002414 uint8_t osc_min[2]; /* AC=0/1 */
2415 uint8_t osc_max[2]; /* AC=0/1 */
2416 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002417} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002418
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002419struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002420 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002421 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2422 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2423 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002424} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002425
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002426struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002427 /* Battery level thresholds */
2428 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002429} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002430
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002431struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002432 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002433 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2434 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurieeb316852015-12-01 18:51:18 -08002435
2436 /* s5: single color pulse on inhibited power-up */
2437 uint8_t s5_idx;
2438
2439 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002440 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002441} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002442
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002443/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002444#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002445struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002446 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002447 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002448} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002449
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002450struct ec_params_lightbar {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002451 uint8_t cmd; /* Command (see enum lightbar_command) */
Duncan Laurie433432b2013-06-03 10:38:22 -07002452 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002453 /*
2454 * The following commands have no args:
2455 *
2456 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2457 * version, get_brightness, get_demo, suspend, resume,
2458 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2459 * get_params_v2_bright, get_params_v2_thlds,
2460 * get_params_v2_colors
2461 *
2462 * Don't use an empty struct, because C++ hates that.
2463 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002464
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002465 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002466 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002467 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002468
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002469 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002470 uint8_t ctrl, reg, value;
2471 } reg;
2472
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002473 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002474 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002475 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002476
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002477 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002478 uint8_t led;
2479 } get_rgb;
2480
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002481 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002482 uint8_t enable;
2483 } manual_suspend_ctrl;
2484
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002485 struct lightbar_params_v0 set_params_v0;
2486 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002487
2488 struct lightbar_params_v2_timing set_v2par_timing;
2489 struct lightbar_params_v2_tap set_v2par_tap;
2490 struct lightbar_params_v2_oscillation set_v2par_osc;
2491 struct lightbar_params_v2_brightness set_v2par_bright;
2492 struct lightbar_params_v2_thresholds set_v2par_thlds;
2493 struct lightbar_params_v2_colors set_v2par_colors;
2494
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002495 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002496 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002497} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002498
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002499struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002500 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002501 struct __ec_todo_unpacked {
2502 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002503 uint8_t reg;
2504 uint8_t ic0;
2505 uint8_t ic1;
2506 } vals[23];
2507 } dump;
2508
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002509 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002510 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002511 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002512
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002513 struct lightbar_params_v0 get_params_v0;
2514 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002515
Duncan Laurieeb316852015-12-01 18:51:18 -08002516 struct lightbar_params_v2_timing get_params_v2_timing;
2517 struct lightbar_params_v2_tap get_params_v2_tap;
2518 struct lightbar_params_v2_oscillation get_params_v2_osc;
2519 struct lightbar_params_v2_brightness get_params_v2_bright;
2520 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2521 struct lightbar_params_v2_colors get_params_v2_colors;
2522
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002523 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002524 uint32_t num;
2525 uint32_t flags;
2526 } version;
2527
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002528 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002529 uint8_t red, green, blue;
2530 } get_rgb;
2531
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002532 /*
2533 * The following commands have no response:
2534 *
2535 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2536 * set_params_v0, set_params_v1, set_program,
2537 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2538 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2539 * set_v2par_thlds, set_v2par_colors
2540 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002541 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002542} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002543
2544/* Lightbar commands */
2545enum lightbar_command {
2546 LIGHTBAR_CMD_DUMP = 0,
2547 LIGHTBAR_CMD_OFF = 1,
2548 LIGHTBAR_CMD_ON = 2,
2549 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002550 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002551 LIGHTBAR_CMD_SEQ = 5,
2552 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002553 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002554 LIGHTBAR_CMD_GET_SEQ = 8,
2555 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002556 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2557 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002558 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002559 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2560 LIGHTBAR_CMD_GET_RGB = 14,
2561 LIGHTBAR_CMD_GET_DEMO = 15,
2562 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2563 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002564 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002565 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2566 LIGHTBAR_CMD_SUSPEND = 20,
2567 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002568 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2569 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2570 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2571 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2572 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2573 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2574 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2575 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2576 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2577 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2578 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2579 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002580 LIGHTBAR_NUM_CMDS,
Duncan Laurie433432b2013-06-03 10:38:22 -07002581};
2582
2583/*****************************************************************************/
2584/* LED control commands */
2585
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002586#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002587
Bill Richardsone221aad2013-06-12 10:50:41 -07002588enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002589 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002590 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002591 /*
2592 * LED to indicate system power state (on or in suspend).
2593 * May be on power button or on C-panel.
2594 */
2595 EC_LED_ID_POWER_LED,
2596 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002597 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002598 /* LED to indicate left side */
2599 EC_LED_ID_LEFT_LED,
2600 /* LED to indicate right side */
2601 EC_LED_ID_RIGHT_LED,
2602 /* LED to indicate recovery mode with HW_REINIT */
2603 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2604 /* LED to indicate sysrq debug mode. */
2605 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002606
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002607 EC_LED_ID_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002608};
Duncan Laurie433432b2013-06-03 10:38:22 -07002609
Bill Richardsone221aad2013-06-12 10:50:41 -07002610/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002611#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002612#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002613
2614enum ec_led_colors {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002615 EC_LED_COLOR_INVALID = -1,
Bill Richardsone221aad2013-06-12 10:50:41 -07002616 EC_LED_COLOR_RED = 0,
2617 EC_LED_COLOR_GREEN,
2618 EC_LED_COLOR_BLUE,
2619 EC_LED_COLOR_YELLOW,
2620 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002621 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002622
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002623 EC_LED_COLOR_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002624};
2625
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002626struct ec_params_led_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002627 uint8_t led_id; /* Which LED to control */
2628 uint8_t flags; /* Control flags */
Bill Richardsone221aad2013-06-12 10:50:41 -07002629
2630 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002631} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002632
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002633struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002634 /*
2635 * Available brightness value range.
2636 *
2637 * Range 0 means color channel not present.
2638 * Range 1 means on/off control.
2639 * Other values means the LED is control by PWM.
2640 */
2641 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002642} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002643
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002644/*****************************************************************************/
2645/* Verified boot commands */
2646
2647/*
2648 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2649 * reused for other purposes with version > 0.
2650 */
2651
2652/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002653#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002654
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002655struct ec_params_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002656 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2657 uint8_t hash_type; /* enum ec_vboot_hash_type */
2658 uint8_t nonce_size; /* Nonce size; may be 0 */
2659 uint8_t reserved0; /* Reserved; set 0 */
2660 uint32_t offset; /* Offset in flash to hash */
2661 uint32_t size; /* Number of bytes to hash */
2662 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002663} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002664
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002665struct ec_response_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002666 uint8_t status; /* enum ec_vboot_hash_status */
2667 uint8_t hash_type; /* enum ec_vboot_hash_type */
2668 uint8_t digest_size; /* Size of hash digest in bytes */
2669 uint8_t reserved0; /* Ignore; will be 0 */
2670 uint32_t offset; /* Offset in flash which was hashed */
2671 uint32_t size; /* Number of bytes hashed */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002672 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002673} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002674
2675enum ec_vboot_hash_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002676 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2677 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2678 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2679 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002680};
2681
2682enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002683 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002684};
2685
2686enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002687 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2688 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2689 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002690};
2691
Duncan Laurie433432b2013-06-03 10:38:22 -07002692/*
2693 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2694 * If one of these is specified, the EC will automatically update offset and
2695 * size to the correct values for the specified image (RO or RW).
2696 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002697#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2698#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2699#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002700
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002701/*
2702 * 'RW' is vague if there are multiple RW images; we mean the active one,
2703 * so the old constant is deprecated.
2704 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002705#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002706
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002707/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002708/*
2709 * Motion sense commands. We'll make separate structs for sub-commands with
2710 * different input args, so that we know how much to expect.
2711 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002712#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002713
2714/* Motion sense commands */
2715enum motionsense_command {
2716 /*
2717 * Dump command returns all motion sensor data including motion sense
2718 * module flags and individual sensor flags.
2719 */
2720 MOTIONSENSE_CMD_DUMP = 0,
2721
2722 /*
2723 * Info command returns data describing the details of a given sensor,
2724 * including enum motionsensor_type, enum motionsensor_location, and
2725 * enum motionsensor_chip.
2726 */
2727 MOTIONSENSE_CMD_INFO = 1,
2728
2729 /*
2730 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002731 * in milliseconds.
2732 * It is per sensor, the EC run sample task at the minimum of all
2733 * sensors EC_RATE.
2734 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2735 * to collect all the sensor samples.
2736 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2737 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002738 */
2739 MOTIONSENSE_CMD_EC_RATE = 2,
2740
2741 /*
2742 * Sensor ODR command is a setter/getter command for the output data
2743 * rate of a specific motion sensor in millihertz.
2744 */
2745 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2746
2747 /*
2748 * Sensor range command is a setter/getter command for the range of
2749 * a specified motion sensor in +/-G's or +/- deg/s.
2750 */
2751 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2752
2753 /*
2754 * Setter/getter command for the keyboard wake angle. When the lid
2755 * angle is greater than this value, keyboard wake is disabled in S3,
2756 * and when the lid angle goes less than this value, keyboard wake is
2757 * enabled. Note, the lid angle measurement is an approximate,
2758 * un-calibrated value, hence the wake angle isn't exact.
2759 */
2760 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2761
Duncan Laurieeb316852015-12-01 18:51:18 -08002762 /*
2763 * Returns a single sensor data.
2764 */
2765 MOTIONSENSE_CMD_DATA = 6,
2766
2767 /*
2768 * Return sensor fifo info.
2769 */
2770 MOTIONSENSE_CMD_FIFO_INFO = 7,
2771
2772 /*
2773 * Insert a flush element in the fifo and return sensor fifo info.
2774 * The host can use that element to synchronize its operation.
2775 */
2776 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2777
2778 /*
2779 * Return a portion of the fifo.
2780 */
2781 MOTIONSENSE_CMD_FIFO_READ = 9,
2782
2783 /*
2784 * Perform low level calibration.
2785 * On sensors that support it, ask to do offset calibration.
2786 */
2787 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2788
2789 /*
2790 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002791 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002792 * The offsets can be calculated by the host, or via
2793 * PERFORM_CALIB command.
2794 */
2795 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2796
2797 /*
2798 * List available activities for a MOTION sensor.
2799 * Indicates if they are enabled or disabled.
2800 */
2801 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2802
2803 /*
2804 * Activity management
2805 * Enable/Disable activity recognition.
2806 */
2807 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2808
2809 /*
2810 * Lid Angle
2811 */
2812 MOTIONSENSE_CMD_LID_ANGLE = 14,
2813
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002814 /*
2815 * Allow the FIFO to trigger interrupt via MKBP events.
2816 * By default the FIFO does not send interrupt to process the FIFO
2817 * until the AP is ready or it is coming from a wakeup sensor.
2818 */
2819 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2820
2821 /*
2822 * Spoof the readings of the sensors. The spoofed readings can be set
2823 * to arbitrary values, or will lock to the last read actual values.
2824 */
2825 MOTIONSENSE_CMD_SPOOF = 16,
2826
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002827 /* Set lid angle for tablet mode detection. */
2828 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2829
2830 /*
2831 * Sensor Scale command is a setter/getter command for the calibration
2832 * scale.
2833 */
2834 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2835
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002836 /*
2837 * Read the current online calibration values (if available).
2838 */
2839 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2840
Yidi Lin42f79592020-09-21 18:04:10 +08002841 /*
2842 * Activity management
2843 * Retrieve current status of given activity.
2844 */
2845 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2846
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002847 /* Number of motionsense sub-commands. */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002848 MOTIONSENSE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002849};
2850
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002851/* List of motion sensor types. */
2852enum motionsensor_type {
2853 MOTIONSENSE_TYPE_ACCEL = 0,
2854 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002855 MOTIONSENSE_TYPE_MAG = 2,
2856 MOTIONSENSE_TYPE_PROX = 3,
2857 MOTIONSENSE_TYPE_LIGHT = 4,
2858 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002859 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002860 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002861 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002862 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002863};
2864
2865/* List of motion sensor locations. */
2866enum motionsensor_location {
2867 MOTIONSENSE_LOC_BASE = 0,
2868 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002869 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002870 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002871};
2872
2873/* List of motion sensor chips. */
2874enum motionsensor_chip {
2875 MOTIONSENSE_CHIP_KXCJ9 = 0,
2876 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002877 MOTIONSENSE_CHIP_BMI160 = 2,
2878 MOTIONSENSE_CHIP_SI1141 = 3,
2879 MOTIONSENSE_CHIP_SI1142 = 4,
2880 MOTIONSENSE_CHIP_SI1143 = 5,
2881 MOTIONSENSE_CHIP_KX022 = 6,
2882 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002883 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884 MOTIONSENSE_CHIP_BMP280 = 9,
2885 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002886 MOTIONSENSE_CHIP_BH1730 = 11,
2887 MOTIONSENSE_CHIP_GPIO = 12,
2888 MOTIONSENSE_CHIP_LIS2DH = 13,
2889 MOTIONSENSE_CHIP_LSM6DSM = 14,
2890 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002891 MOTIONSENSE_CHIP_LIS2MDL = 16,
2892 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2893 MOTIONSENSE_CHIP_LSM6DSO = 18,
2894 MOTIONSENSE_CHIP_LNG2DM = 19,
2895 MOTIONSENSE_CHIP_TCS3400 = 20,
2896 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2897 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002898 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002899 MOTIONSENSE_CHIP_BMI260 = 24,
2900 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002901 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002902 MOTIONSENSE_CHIP_BMA422 = 27,
2903 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002904 MOTIONSENSE_CHIP_BMI220 = 29,
2905 MOTIONSENSE_CHIP_CM32183 = 30,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05002906 MOTIONSENSE_CHIP_VEML3328 = 31,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002907 MOTIONSENSE_CHIP_MAX,
2908};
2909
2910/* List of orientation positions */
2911enum motionsensor_orientation {
2912 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2913 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2914 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2915 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2916 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002917};
2918
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002919struct ec_response_activity_data {
2920 uint8_t activity; /* motionsensor_activity */
2921 uint8_t state;
2922} __ec_todo_packed;
2923
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002924struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002925 /* Flags for each sensor. */
2926 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002927 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002928 uint8_t sensor_num;
2929 /* Each sensor is up to 3-axis. */
2930 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002931 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002932 /* for sensors using unsigned data */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002933 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002934 struct __ec_todo_packed {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002935 uint16_t reserved;
2936 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002937 };
2938 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002939 struct ec_response_activity_data activity_data;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002940 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002941 };
2942 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002943} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002944
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002945/* Response to AP reporting calibration data for a given sensor. */
2946struct ec_response_online_calibration_data {
2947 /** The calibration values. */
2948 int16_t data[3];
2949};
2950
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002951/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002952struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002953 /* Size of the fifo */
2954 uint16_t size;
2955 /* Amount of space used in the fifo */
2956 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002957 /* Timestamp recorded in us.
2958 * aka accurate timestamp when host event was triggered.
2959 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002960 uint32_t timestamp;
2961 /* Total amount of vector lost */
2962 uint16_t total_lost;
2963 /* Lost events since the last fifo_info, per sensors */
2964 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002965} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002966
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002967struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002968 uint32_t number_data;
2969 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002970} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002971
2972/* List supported activity recognition */
2973enum motionsensor_activity {
2974 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2975 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2976 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002977 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002978 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002979};
2980
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002981struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002982 uint8_t sensor_num;
2983 uint8_t activity; /* one of enum motionsensor_activity */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002984 uint8_t enable; /* 1: enable, 0: disable */
Duncan Laurieeb316852015-12-01 18:51:18 -08002985 uint8_t reserved;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002986 uint16_t parameters[4]; /* activity dependent parameters */
2987} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002988
2989/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002990#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002991
2992/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002993#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002994
2995/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002996 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002997 * data contains time stamp
2998 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002999#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
3000#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
3001#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
3002#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
3003#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08003004
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003005#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
3006
Duncan Laurieeb316852015-12-01 18:51:18 -08003007/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003008 * Send this value for the data element to only perform a read. If you
3009 * send any other value, the EC will interpret it as data to set and will
3010 * return the actual value set.
3011 */
3012#define EC_MOTION_SENSE_NO_VALUE -1
3013
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003014#define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
Duncan Laurieeb316852015-12-01 18:51:18 -08003015
3016/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
3017/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003018#define MOTION_SENSE_SET_OFFSET BIT(0)
3019
3020/* Default Scale value, factor 1. */
3021#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08003022
3023#define LID_ANGLE_UNRELIABLE 500
3024
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003025enum motionsense_spoof_mode {
3026 /* Disable spoof mode. */
3027 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
3028
3029 /* Enable spoof mode, but use provided component values. */
3030 MOTIONSENSE_SPOOF_MODE_CUSTOM,
3031
3032 /* Enable spoof mode, but use the current sensor values. */
3033 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
3034
3035 /* Query the current spoof mode status for the sensor. */
3036 MOTIONSENSE_SPOOF_MODE_QUERY,
3037};
3038
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003039struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003040 uint8_t cmd;
3041 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003042 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003043 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003044 /*
3045 * Maximal number of sensor the host is expecting.
3046 * 0 means the host is only interested in the number
3047 * of sensors controlled by the EC.
3048 */
3049 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003050 } dump;
3051
3052 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08003053 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003054 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003055 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003056 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08003057 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08003058 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003059 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08003060 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003061
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003062 /*
3063 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
3064 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003065 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003066 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003067 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003068
3069 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003070 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
3071 * Allow entering/exiting the calibration mode.
3072 */
3073 struct __ec_todo_unpacked {
3074 uint8_t sensor_num;
3075 uint8_t enable;
3076 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003077
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003078 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08003079 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
3080 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003081 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003082 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003083 uint8_t sensor_num;
3084
3085 /* Rounding flag, true for round-up, false for down. */
3086 uint8_t roundup;
3087
3088 uint16_t reserved;
3089
3090 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
3091 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08003092 } ec_rate, sensor_odr, sensor_range;
3093
3094 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003095 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003096 uint8_t sensor_num;
3097
3098 /*
3099 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3100 * the calibration information in the EC.
3101 * If unset, just retrieve calibration information.
3102 */
3103 uint16_t flags;
3104
3105 /*
3106 * Temperature at calibration, in units of 0.01 C
3107 * 0x8000: invalid / unknown.
3108 * 0x0: 0C
3109 * 0x7fff: +327.67C
3110 */
3111 int16_t temp;
3112
3113 /*
3114 * Offset for calibration.
3115 * Unit:
3116 * Accelerometer: 1/1024 g
3117 * Gyro: 1/1024 deg/s
3118 * Compass: 1/16 uT
3119 */
3120 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003121 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08003122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003123 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3124 struct __ec_todo_packed {
3125 uint8_t sensor_num;
3126
3127 /*
3128 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3129 * the calibration information in the EC.
3130 * If unset, just retrieve calibration information.
3131 */
3132 uint16_t flags;
3133
3134 /*
3135 * Temperature at calibration, in units of 0.01 C
3136 * 0x8000: invalid / unknown.
3137 * 0x0: 0C
3138 * 0x7fff: +327.67C
3139 */
3140 int16_t temp;
3141
3142 /*
3143 * Scale for calibration:
3144 * By default scale is 1, it is encoded on 16bits:
3145 * 1 = BIT(15)
3146 * ~2 = 0xFFFF
3147 * ~0 = 0.
3148 */
3149 uint16_t scale[3];
3150 } sensor_scale;
3151
Duncan Laurieeb316852015-12-01 18:51:18 -08003152 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003153 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08003154
3155 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003156 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003157 /*
3158 * Number of expected vector to return.
3159 * EC may return less or 0 if none available.
3160 */
3161 uint32_t max_data_vector;
3162 } fifo_read;
3163
Yidi Lin42f79592020-09-21 18:04:10 +08003164 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08003165 struct ec_motion_sense_activity set_activity;
3166
3167 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003168 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003169
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003170 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3171 struct __ec_todo_unpacked {
3172 /*
3173 * 1: enable, 0 disable fifo,
3174 * EC_MOTION_SENSE_NO_VALUE return value.
3175 */
3176 int8_t enable;
3177 } fifo_int_enable;
3178
3179 /* Used for MOTIONSENSE_CMD_SPOOF */
3180 struct __ec_todo_packed {
3181 uint8_t sensor_id;
3182
3183 /* See enum motionsense_spoof_mode. */
3184 uint8_t spoof_enable;
3185
3186 /* Ignored, used for alignment. */
3187 uint8_t reserved;
3188
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003189 union {
3190 /* Individual component values to spoof. */
3191 int16_t components[3];
3192
3193 /* Used when spoofing an activity */
3194 struct {
3195 /* enum motionsensor_activity */
3196 uint8_t activity_num;
3197
3198 /* spoof activity state */
3199 uint8_t activity_state;
3200 };
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003201 } __ec_todo_packed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003202 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003203
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003204 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3205 struct __ec_todo_unpacked {
3206 /*
3207 * Lid angle threshold for switching between tablet and
3208 * clamshell mode.
3209 */
3210 int16_t lid_angle;
3211
3212 /*
3213 * Hysteresis degree to prevent fluctuations between
3214 * clamshell and tablet mode if lid angle keeps
3215 * changing around the threshold. Lid motion driver will
3216 * use lid_angle + hys_degree to trigger tablet mode and
3217 * lid_angle - hys_degree to trigger clamshell mode.
3218 */
3219 int16_t hys_degree;
3220 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003221
3222 /*
3223 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3224 * Allow reading a single sensor's online calibration value.
3225 */
3226 struct __ec_todo_unpacked {
3227 uint8_t sensor_num;
3228 } online_calib_read;
3229
Yidi Lin42f79592020-09-21 18:04:10 +08003230 /*
3231 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3232 */
3233 struct __ec_todo_unpacked {
3234 uint8_t sensor_num;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003235 uint8_t activity; /* enum motionsensor_activity */
Yidi Lin42f79592020-09-21 18:04:10 +08003236 } get_activity;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003237 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003238} __ec_todo_packed;
3239
Jett Rinkba2edaf2020-01-14 11:49:06 -07003240enum motion_sense_cmd_info_flags {
3241 /* The sensor supports online calibration */
3242 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3243};
3244
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003245struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003246 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003247 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003248 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003249 /* Flags representing the motion sensor module. */
3250 uint8_t module_flags;
3251
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003252 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003253 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003254
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003255 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003256 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003257 * for holding all the data.
3258 */
3259 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003260 } dump;
3261
3262 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003263 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003264 /* Should be element of enum motionsensor_type. */
3265 uint8_t type;
3266
3267 /* Should be element of enum motionsensor_location. */
3268 uint8_t location;
3269
3270 /* Should be element of enum motionsensor_chip. */
3271 uint8_t chip;
3272 } info;
3273
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003274 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3275 struct __ec_todo_unpacked {
3276 /* Should be element of enum motionsensor_type. */
3277 uint8_t type;
3278
3279 /* Should be element of enum motionsensor_location. */
3280 uint8_t location;
3281
3282 /* Should be element of enum motionsensor_chip. */
3283 uint8_t chip;
3284
3285 /* Minimum sensor sampling frequency */
3286 uint32_t min_frequency;
3287
3288 /* Maximum sensor sampling frequency */
3289 uint32_t max_frequency;
3290
3291 /* Max number of sensor events that could be in fifo */
3292 uint32_t fifo_max_event_count;
3293 } info_3;
3294
Jett Rinkba2edaf2020-01-14 11:49:06 -07003295 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3296 struct __ec_align4 {
3297 /* Should be element of enum motionsensor_type. */
3298 uint8_t type;
3299
3300 /* Should be element of enum motionsensor_location. */
3301 uint8_t location;
3302
3303 /* Should be element of enum motionsensor_chip. */
3304 uint8_t chip;
3305
3306 /* Minimum sensor sampling frequency */
3307 uint32_t min_frequency;
3308
3309 /* Maximum sensor sampling frequency */
3310 uint32_t max_frequency;
3311
3312 /* Max number of sensor events that could be in fifo */
3313 uint32_t fifo_max_event_count;
3314
3315 /*
3316 * Should be elements of
3317 * enum motion_sense_cmd_info_flags
3318 */
3319 uint32_t flags;
3320 } info_4;
3321
Duncan Laurieeb316852015-12-01 18:51:18 -08003322 /* Used for MOTIONSENSE_CMD_DATA */
3323 struct ec_response_motion_sensor_data data;
3324
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003325 /*
3326 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003327 * MOTIONSENSE_CMD_SENSOR_RANGE,
3328 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3329 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3330 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003331 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003332 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003333 /* Current value of the parameter queried. */
3334 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003335 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Caveh Jalali024ffe32023-01-30 14:35:19 -08003336 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003337
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003338 /*
3339 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3340 * PERFORM_CALIB.
3341 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003342 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003343 int16_t temp;
3344 int16_t offset[3];
3345 } sensor_offset, perform_calib;
3346
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003347 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003348 struct __ec_todo_unpacked {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003349 int16_t temp;
3350 uint16_t scale[3];
3351 } sensor_scale;
3352
Duncan Laurieeb316852015-12-01 18:51:18 -08003353 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3354
3355 struct ec_response_motion_sense_fifo_data fifo_read;
3356
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003357 struct ec_response_online_calibration_data online_calib_read;
3358
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003359 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003360 uint16_t reserved;
3361 uint32_t enabled;
3362 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003363 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003364
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003365 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003366
Duncan Laurieeb316852015-12-01 18:51:18 -08003367 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003368 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003369 /*
3370 * Angle between 0 and 360 degree if available,
3371 * LID_ANGLE_UNRELIABLE otherwise.
3372 */
3373 uint16_t value;
3374 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003375
3376 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3377 struct __ec_todo_unpacked {
3378 /*
3379 * Lid angle threshold for switching between tablet and
3380 * clamshell mode.
3381 */
3382 uint16_t lid_angle;
3383
3384 /* Hysteresis degree. */
3385 uint16_t hys_degree;
3386 } tablet_mode_threshold;
3387
Yidi Lin42f79592020-09-21 18:04:10 +08003388 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3389 struct __ec_todo_unpacked {
3390 uint8_t state;
3391 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003392 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003393} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003394
3395/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003396/* Force lid open command */
3397
3398/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003399#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003400
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003401struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003402 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003403} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003404
3405/*****************************************************************************/
3406/* Configure the behavior of the power button */
3407#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3408
3409enum ec_config_power_button_flags {
3410 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003411 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003412};
3413
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003414struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003415 /* See enum ec_config_power_button_flags */
3416 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003417} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003418
3419/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003420/* USB charging control commands */
3421
3422/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003423#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003424
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003425enum usb_charge_mode {
3426 /* Disable USB port. */
3427 USB_CHARGE_MODE_DISABLED,
3428 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3429 USB_CHARGE_MODE_SDP2,
3430 /* Set USB port to Charging Downstream Port, BC 1.2. */
3431 USB_CHARGE_MODE_CDP,
3432 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3433 USB_CHARGE_MODE_DCP_SHORT,
3434 /* Enable USB port (for dumb ports). */
3435 USB_CHARGE_MODE_ENABLED,
3436 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3437 USB_CHARGE_MODE_DEFAULT,
3438
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003439 USB_CHARGE_MODE_COUNT,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003440};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003441
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003442enum usb_suspend_charge {
3443 /* Enable charging in suspend */
3444 USB_ALLOW_SUSPEND_CHARGE,
3445 /* Disable charging in suspend */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003446 USB_DISALLOW_SUSPEND_CHARGE,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003447};
3448
3449struct ec_params_usb_charge_set_mode {
3450 uint8_t usb_port_id;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003451 uint8_t mode : 7; /* enum usb_charge_mode */
3452 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003453} __ec_align1;
3454
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003455/*****************************************************************************/
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003456/* Tablet mode commands */
3457
3458/* Set tablet mode */
3459#define EC_CMD_SET_TABLET_MODE 0x0031
3460
3461enum tablet_mode_override {
3462 TABLET_MODE_DEFAULT,
3463 TABLET_MODE_FORCE_TABLET,
3464 TABLET_MODE_FORCE_CLAMSHELL,
3465};
3466
3467struct ec_params_set_tablet_mode {
3468 uint8_t tablet_mode; /* enum tablet_mode_override */
3469} __ec_align1;
3470
3471/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003472/* Persistent storage for host */
3473
3474/* Maximum bytes that can be read/written in a single command */
3475#define EC_PSTORE_SIZE_MAX 64
3476
3477/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003478#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003479
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003480struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003481 /* Persistent storage size, in bytes */
3482 uint32_t pstore_size;
3483 /* Access size; read/write offset and size must be a multiple of this */
3484 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003485} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003486
3487/*
3488 * Read persistent storage
3489 *
3490 * Response is params.size bytes of data.
3491 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003492#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003493
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003494struct ec_params_pstore_read {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003495 uint32_t offset; /* Byte offset to read */
3496 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003497} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003498
3499/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003500#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003502struct ec_params_pstore_write {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003503 uint32_t offset; /* Byte offset to write */
3504 uint32_t size; /* Size to write in bytes */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003505 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003506} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003507
3508/*****************************************************************************/
3509/* Real-time clock */
3510
3511/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003512struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003513 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003514} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003516struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003517 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003518} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003519
3520/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003521#define EC_CMD_RTC_GET_VALUE 0x0044
3522#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003523
3524/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003525#define EC_CMD_RTC_SET_VALUE 0x0046
3526#define EC_CMD_RTC_SET_ALARM 0x0047
3527
3528/* Pass as time param to SET_ALARM to clear the current alarm */
3529#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003530
3531/*****************************************************************************/
3532/* Port80 log access */
3533
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003534/* Maximum entries that can be read/written in a single command */
3535#define EC_PORT80_SIZE_MAX 32
3536
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003537/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003538#define EC_CMD_PORT80_LAST_BOOT 0x0048
3539#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003540
3541enum ec_port80_subcmd {
3542 EC_PORT80_GET_INFO = 0,
3543 EC_PORT80_READ_BUFFER,
3544};
3545
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003546struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003547 uint16_t subcmd;
3548 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003549 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003550 uint32_t offset;
3551 uint32_t num_entries;
3552 } read_buffer;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003553 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003554} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003555
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003556struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003557 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003558 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003559 uint32_t writes;
3560 uint32_t history_size;
3561 uint32_t last_boot;
3562 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003563 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003564 uint16_t codes[EC_PORT80_SIZE_MAX];
3565 } data;
3566 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003567} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003568
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003569struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003570 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003571} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003572
3573/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003574/* Temporary secure storage for host verified boot use */
3575
3576/* Number of bytes in a vstore slot */
3577#define EC_VSTORE_SLOT_SIZE 64
3578
3579/* Maximum number of vstore slots */
3580#define EC_VSTORE_SLOT_MAX 32
3581
3582/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003583#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003584struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003585 /* Indicates which slots are locked */
3586 uint32_t slot_locked;
3587 /* Total number of slots available */
3588 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003589} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003590
3591/*
3592 * Read temporary secure storage
3593 *
3594 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3595 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003596#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003597
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003598struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003599 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003600} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003601
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003602struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003603 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003604} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003605
3606/*
3607 * Write temporary secure storage and lock it.
3608 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003609#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003610
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003611struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003612 uint8_t slot; /* Slot to write to */
3613 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003614} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003615
3616/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003617/* Thermal engine commands. Note that there are two implementations. We'll
3618 * reuse the command number, but the data and behavior is incompatible.
3619 * Version 0 is what originally shipped on Link.
3620 * Version 1 separates the CPU thermal limits from the fan control.
3621 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003622
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003623#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3624#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003625
Duncan Laurie93e24442014-01-06 12:30:52 -08003626/* The version 0 structs are opaque. You have to know what they are for
3627 * the get/set commands to make any sense.
3628 */
3629
3630/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003631struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003632 uint8_t sensor_type;
3633 uint8_t threshold_id;
3634 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003635} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003636
Duncan Laurie93e24442014-01-06 12:30:52 -08003637/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003638struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003639 uint8_t sensor_type;
3640 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003641} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003642
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003643struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003644 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003645} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003646
Duncan Laurie93e24442014-01-06 12:30:52 -08003647/* The version 1 structs are visible. */
3648enum ec_temp_thresholds {
3649 EC_TEMP_THRESH_WARN = 0,
3650 EC_TEMP_THRESH_HIGH,
3651 EC_TEMP_THRESH_HALT,
3652
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003653 EC_TEMP_THRESH_COUNT,
Duncan Laurie93e24442014-01-06 12:30:52 -08003654};
3655
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003656/*
3657 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003658 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003659 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003660 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3661 * hysteresis.
3662 * For example,
3663 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3664 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3665 * EC will throttle ap when temperature >= 301 K, and release throttling when
3666 * temperature <= 299 K.
3667 *
3668 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3669 * For example,
3670 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3671 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3672 * EC will throttle ap when temperature >= 301 K, and release throttling when
3673 * temperature <= 294 K.
3674 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003675 * Note that this structure is a sub-structure of
3676 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003677 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003678struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003679 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003680 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003681 uint32_t temp_fan_off; /* no active cooling needed */
3682 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003683} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003684
3685/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003686struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003687 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003688} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003689/* This returns a struct ec_thermal_config */
3690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003691/*
3692 * Version 1 - set config for one sensor.
3693 * Use read-modify-write for best results!
3694 */
3695struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003696 uint32_t sensor_num;
3697 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003698} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003699/* This returns no data */
3700
3701/****************************************************************************/
3702
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003703/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003704#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003705
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003706/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003707struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003708 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003709} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003710
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003711/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003712#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3713#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003714
3715/*
3716 * The original TMP006 calibration only needed four params, but now we need
3717 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3718 * the params opaque. The v1 "get" response will include the algorithm number
3719 * and how many params it requires. That way we can change the EC code without
3720 * needing to update this file. We can also use a different algorithm on each
3721 * sensor.
3722 */
3723
3724/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003725struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003726 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003727} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003728
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003729/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003730struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003731 float s0;
3732 float b0;
3733 float b1;
3734 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003735} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003736
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003737struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003738 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003739 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003740 float s0;
3741 float b0;
3742 float b1;
3743 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003744} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003745
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003746/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003747struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003748 uint8_t algorithm;
3749 uint8_t num_params;
3750 uint8_t reserved[2];
3751 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003752} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003753
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003754struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003755 uint8_t index;
3756 uint8_t algorithm;
3757 uint8_t num_params;
3758 uint8_t reserved;
3759 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003760} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003761
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003762/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003763#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003764
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003765struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003766 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003767} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003768
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003769struct ec_response_tmp006_get_raw {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003770 int32_t t; /* In 1/100 K */
3771 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003772} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003773
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003774/*****************************************************************************/
3775/* MKBP - Matrix KeyBoard Protocol */
3776
3777/*
3778 * Read key state
3779 *
3780 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3781 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003782 *
3783 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3784 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3785 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003786 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003787#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003788
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003789/*
3790 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3791 */
3792#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003793
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003794struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003795 uint32_t rows;
3796 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003797 /* Formerly "switches", which was 0. */
3798 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003799} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003800
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003801struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003802 uint8_t info_type;
3803 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003804} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003805
3806enum ec_mkbp_info_type {
3807 /*
3808 * Info about the keyboard matrix: number of rows and columns.
3809 *
3810 * Returns struct ec_response_mkbp_info.
3811 */
3812 EC_MKBP_INFO_KBD = 0,
3813
3814 /*
3815 * For buttons and switches, info about which specifically are
3816 * supported. event_type must be set to one of the values in enum
3817 * ec_mkbp_event.
3818 *
3819 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3820 * bitmask indicating which buttons or switches are present. See the
3821 * bit inidices below.
3822 */
3823 EC_MKBP_INFO_SUPPORTED = 1,
3824
3825 /*
3826 * Instantaneous state of buttons and switches.
3827 *
3828 * event_type must be set to one of the values in enum ec_mkbp_event.
3829 *
3830 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3831 * indicating the current state of the keyboard matrix.
3832 *
3833 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3834 * event state.
3835 *
3836 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3837 * state of supported buttons.
3838 *
3839 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3840 * state of supported switches.
3841 */
3842 EC_MKBP_INFO_CURRENT = 2,
3843};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003844
3845/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003846#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003847
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003848struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003849 uint8_t col;
3850 uint8_t row;
3851 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003852} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003853
Duncan Laurie433432b2013-06-03 10:38:22 -07003854/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003855#define EC_CMD_MKBP_SET_CONFIG 0x0064
3856#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003857
3858/* flags */
3859enum mkbp_config_flags {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003860 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
Duncan Laurie433432b2013-06-03 10:38:22 -07003861};
3862
3863enum mkbp_config_valid {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003864 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3865 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3866 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3867 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3868 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3869 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3870 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003871};
3872
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003873/*
3874 * Configuration for our key scanning algorithm.
3875 *
3876 * Note that this is used as a sub-structure of
3877 * ec_{params/response}_mkbp_get_config.
3878 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003879struct ec_mkbp_config {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003880 uint32_t valid_mask; /* valid fields */
3881 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3882 uint8_t valid_flags; /* which flags are valid */
3883 uint16_t scan_period_us; /* period between start of scans */
Duncan Laurie433432b2013-06-03 10:38:22 -07003884 /* revert to interrupt mode after no activity for this long */
3885 uint32_t poll_timeout_us;
3886 /*
3887 * minimum post-scan relax time. Once we finish a scan we check
3888 * the time until we are due to start the next one. If this time is
3889 * shorter this field, we use this instead.
3890 */
3891 uint16_t min_post_scan_delay_us;
3892 /* delay between setting up output and waiting for it to settle */
3893 uint16_t output_settle_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003894 uint16_t debounce_down_us; /* time for debounce on key down */
3895 uint16_t debounce_up_us; /* time for debounce on key up */
Duncan Laurie433432b2013-06-03 10:38:22 -07003896 /* maximum depth to allow for fifo (0 = no keyscan output) */
3897 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003898} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003900struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003901 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003902} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003903
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003904struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003905 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003906} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003907
3908/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003909#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003910
3911enum ec_keyscan_seq_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003912 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3913 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3914 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3915 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3916 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003917};
3918
3919enum ec_collect_flags {
3920 /*
3921 * Indicates this scan was processed by the EC. Due to timing, some
3922 * scans may be skipped.
3923 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003924 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003925};
3926
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003927struct ec_collect_item {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003928 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003929} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003930
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003931struct ec_params_keyscan_seq_ctrl {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003932 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
Duncan Laurie433432b2013-06-03 10:38:22 -07003933 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003934 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003935 uint8_t active; /* still active */
3936 uint8_t num_items; /* number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003937 /* Current item being presented */
3938 uint8_t cur_item;
3939 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003940 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003941 /*
3942 * Absolute time for this scan, measured from the
3943 * start of the sequence.
3944 */
3945 uint32_t time_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003946 uint8_t scan[0]; /* keyscan data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003947 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003948 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003949 uint8_t start_item; /* First item to return */
3950 uint8_t num_items; /* Number of items to return */
Duncan Laurie433432b2013-06-03 10:38:22 -07003951 } collect;
3952 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003953} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003954
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003955struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003956 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003957 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003958 uint8_t num_items; /* Number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003959 /* Data for each item */
3960 struct ec_collect_item item[0];
3961 } collect;
3962 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003963} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003964
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003965/*
3966 * Get the next pending MKBP event.
3967 *
3968 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3969 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003970#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003971
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003972#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3973
3974/*
3975 * We use the most significant bit of the event type to indicate to the host
3976 * that the EC has more MKBP events available to provide.
3977 */
3978#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3979
3980/* The mask to apply to get the raw event type */
3981#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3982
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003983enum ec_mkbp_event {
3984 /* Keyboard matrix changed. The event data is the new matrix state. */
3985 EC_MKBP_EVENT_KEY_MATRIX = 0,
3986
3987 /* New host event. The event data is 4 bytes of host event flags. */
3988 EC_MKBP_EVENT_HOST_EVENT = 1,
3989
Duncan Laurieeb316852015-12-01 18:51:18 -08003990 /* New Sensor FIFO data. The event data is fifo_info structure. */
3991 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3992
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003993 /* The state of the non-matrixed buttons have changed. */
3994 EC_MKBP_EVENT_BUTTON = 3,
3995
3996 /* The state of the switches have changed. */
3997 EC_MKBP_EVENT_SWITCH = 4,
3998
3999 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
4000 EC_MKBP_EVENT_FINGERPRINT = 5,
4001
4002 /*
4003 * Sysrq event: send emulated sysrq. The event data is sysrq,
4004 * corresponding to the key to be pressed.
4005 */
4006 EC_MKBP_EVENT_SYSRQ = 6,
4007
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004008 /*
4009 * New 64-bit host event.
4010 * The event data is 8 bytes of host event flags.
4011 */
4012 EC_MKBP_EVENT_HOST_EVENT64 = 7,
4013
4014 /* Notify the AP that something happened on CEC */
4015 EC_MKBP_EVENT_CEC_EVENT = 8,
4016
4017 /* Send an incoming CEC message to the AP */
4018 EC_MKBP_EVENT_CEC_MESSAGE = 9,
4019
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004020 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
4021 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
4022
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07004023 /* New online calibration values are available. */
4024 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
4025
Rob Barnes8bc5fa92021-06-28 09:32:28 -06004026 /* Peripheral device charger event */
4027 EC_MKBP_EVENT_PCHG = 12,
4028
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004029 /* Number of MKBP events */
4030 EC_MKBP_EVENT_COUNT,
4031};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004032BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004033
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004034/* clang-format off */
4035#define EC_MKBP_EVENT_TEXT \
4036 { \
4037 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
4038 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
4039 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
4040 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
4041 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
4042 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
4043 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
4044 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
4045 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
4046 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
4047 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
4048 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
4049 [EC_MKBP_EVENT_PCHG] = "PCHG", \
4050 }
4051/* clang-format on */
4052
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004053union __ec_align_offset1 ec_response_get_next_data {
4054 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08004055
4056 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004057 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004058 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08004059
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004060 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08004061 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004062 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08004063 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004064 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08004065
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004066 uint32_t buttons;
4067
4068 uint32_t switches;
4069
4070 uint32_t fp_events;
4071
4072 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004073
4074 /* CEC events from enum mkbp_cec_event */
4075 uint32_t cec_events;
4076};
4077
4078union __ec_align_offset1 ec_response_get_next_data_v1 {
4079 uint8_t key_matrix[16];
4080
4081 /* Unaligned */
4082 uint32_t host_event;
4083 uint64_t host_event64;
4084
4085 struct __ec_todo_unpacked {
4086 /* For aligning the fifo_info */
4087 uint8_t reserved[3];
4088 struct ec_response_motion_sense_fifo_info info;
4089 } sensor_fifo;
4090
4091 uint32_t buttons;
4092
4093 uint32_t switches;
4094
4095 uint32_t fp_events;
4096
4097 uint32_t sysrq;
4098
4099 /* CEC events from enum mkbp_cec_event */
4100 uint32_t cec_events;
4101
4102 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004103};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004104BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004106struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004107 uint8_t event_type;
4108 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08004109 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004110} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004111
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004112struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004113 uint8_t event_type;
4114 /* Followed by event data if any */
4115 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004116} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004117
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004118/* Bit indices for buttons and switches.*/
4119/* Buttons */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004120#define EC_MKBP_POWER_BUTTON 0
4121#define EC_MKBP_VOL_UP 1
4122#define EC_MKBP_VOL_DOWN 2
4123#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004124
4125/* Switches */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004126#define EC_MKBP_LID_OPEN 0
4127#define EC_MKBP_TABLET_MODE 1
4128#define EC_MKBP_BASE_ATTACHED 2
4129#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004130
Gwendal Grignou880b4582016-06-20 08:49:25 -07004131/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004132#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07004133
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004134struct ec_response_keyboard_factory_test {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004135 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004136} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004137
4138/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004139#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
4140#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004141#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
Caveh Jalali024ffe32023-01-30 14:35:19 -08004142#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004143 (((fpe) & 0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004144#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4145#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
Caveh Jalali024ffe32023-01-30 14:35:19 -08004146#define EC_MKBP_FP_MATCH_IDX(fpe) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004147 (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
Caveh Jalali024ffe32023-01-30 14:35:19 -08004148#define EC_MKBP_FP_ENROLL BIT(27)
4149#define EC_MKBP_FP_MATCH BIT(28)
4150#define EC_MKBP_FP_FINGER_DOWN BIT(29)
4151#define EC_MKBP_FP_FINGER_UP BIT(30)
4152#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004153/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004154#define EC_MKBP_FP_ERR_ENROLL_OK 0
4155#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4156#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4157#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4158#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004159/* Can be used to detect if image was usable for enrollment or not. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004160#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004161/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004162#define EC_MKBP_FP_ERR_MATCH_NO 0
4163#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4164#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004165#define EC_MKBP_FP_ERR_MATCH_NO_AUTH_FAIL 8
Caveh Jalali024ffe32023-01-30 14:35:19 -08004166#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4167#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4168#define EC_MKBP_FP_ERR_MATCH_YES 1
4169#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004170#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4171
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004172#define EC_CMD_MKBP_WAKE_MASK 0x0069
4173enum ec_mkbp_event_mask_action {
4174 /* Retrieve the value of a wake mask. */
4175 GET_WAKE_MASK = 0,
4176
4177 /* Set the value of a wake mask. */
4178 SET_WAKE_MASK,
4179};
4180
4181enum ec_mkbp_mask_type {
4182 /*
4183 * These are host events sent via MKBP.
4184 *
4185 * Some examples are:
4186 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4187 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4188 *
4189 * The only things that should be in this mask are:
4190 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4191 */
4192 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4193
4194 /*
4195 * These are MKBP events. Some examples are:
4196 *
4197 * EC_MKBP_EVENT_KEY_MATRIX
4198 * EC_MKBP_EVENT_SWITCH
4199 *
4200 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4201 */
4202 EC_MKBP_EVENT_WAKE_MASK,
4203};
4204
4205struct ec_params_mkbp_event_wake_mask {
4206 /* One of enum ec_mkbp_event_mask_action */
4207 uint8_t action;
4208
4209 /*
4210 * Which MKBP mask are you interested in acting upon? This is one of
4211 * ec_mkbp_mask_type.
4212 */
4213 uint8_t mask_type;
4214
4215 /* If setting a new wake mask, this contains the mask to set. */
4216 uint32_t new_wake_mask;
4217};
4218
4219struct ec_response_mkbp_event_wake_mask {
4220 uint32_t wake_mask;
4221};
4222
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004223/*****************************************************************************/
4224/* Temperature sensor commands */
4225
4226/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004227#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004228
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004229struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004230 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004231} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004232
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004233struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004234 char sensor_name[32];
4235 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004236} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004237
4238/*****************************************************************************/
4239
4240/*
4241 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4242 * commands accidentally sent to the wrong interface. See the ACPI section
4243 * below.
4244 */
4245
4246/*****************************************************************************/
4247/* Host event commands */
4248
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004249/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004250/*
4251 * Host event mask params and response structures, shared by all of the host
4252 * event commands below.
4253 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004254struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004255 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004256} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004257
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004258struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004259 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004260} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004261
4262/* These all use ec_response_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004263#define EC_CMD_HOST_EVENT_GET_B 0x0087
4264#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4265#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004266#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004267
4268/* These all use ec_params_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004269#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4270#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4271#define EC_CMD_HOST_EVENT_CLEAR 0x008C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004272#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
Caveh Jalali024ffe32023-01-30 14:35:19 -08004273#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004274
Jenny TC1dfc2c32017-12-14 14:24:39 +05304275/*
4276 * Unified host event programming interface - Should be used by newer versions
4277 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004278 *
4279 * EC returns:
4280 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4281 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304282 */
4283
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004284struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304285 /* Action requested by host - one of enum ec_host_event_action. */
4286 uint8_t action;
4287
4288 /*
4289 * Mask type that the host requested the action on - one of
4290 * enum ec_host_event_mask_type.
4291 */
4292 uint8_t mask_type;
4293
4294 /* Set to 0, ignore on read */
4295 uint16_t reserved;
4296
4297 /* Value to be used in case of set operations. */
4298 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004299} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304300
4301/*
4302 * Response structure returned by EC_CMD_HOST_EVENT.
4303 * Update the value on a GET request. Set to 0 on GET/CLEAR
4304 */
4305
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004306struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304307 /* Mask value in case of get operation */
4308 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004309} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304310
4311enum ec_host_event_action {
4312 /*
4313 * params.value is ignored. Value of mask_type populated
4314 * in response.value
4315 */
4316 EC_HOST_EVENT_GET,
4317
4318 /* Bits in params.value are set */
4319 EC_HOST_EVENT_SET,
4320
4321 /* Bits in params.value are cleared */
4322 EC_HOST_EVENT_CLEAR,
4323};
4324
4325enum ec_host_event_mask_type {
4326
4327 /* Main host event copy */
4328 EC_HOST_EVENT_MAIN,
4329
4330 /* Copy B of host events */
4331 EC_HOST_EVENT_B,
4332
4333 /* SCI Mask */
4334 EC_HOST_EVENT_SCI_MASK,
4335
4336 /* SMI Mask */
4337 EC_HOST_EVENT_SMI_MASK,
4338
4339 /* Mask of events that should be always reported in hostevents */
4340 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4341
4342 /* Active wake mask */
4343 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4344
4345 /* Lazy wake mask for S0ix */
4346 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4347
4348 /* Lazy wake mask for S3 */
4349 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4350
4351 /* Lazy wake mask for S5 */
4352 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4353};
4354
Caveh Jalali024ffe32023-01-30 14:35:19 -08004355#define EC_CMD_HOST_EVENT 0x00A4
Jenny TC1dfc2c32017-12-14 14:24:39 +05304356
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004357/*****************************************************************************/
4358/* Switch commands */
4359
4360/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004361#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004362
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004363struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004364 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004365} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004366
4367/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004368#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004369#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004370
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004371/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004372struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004373 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004374} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004375
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004376/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004377struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004378 /* Flags to enable now */
4379 uint8_t now_flags;
4380
4381 /* Which flags to copy from now_flags */
4382 uint8_t now_mask;
4383
4384 /*
4385 * Flags to leave enabled in S3, if they're on at the S0->S3
4386 * transition. (Other flags will be disabled by the S0->S3
4387 * transition.)
4388 */
4389 uint8_t suspend_flags;
4390
4391 /* Which flags to copy from suspend_flags */
4392 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004393} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004394
4395/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004396struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004397 /* Flags to enable now */
4398 uint8_t now_flags;
4399
4400 /* Flags to leave enabled in S3 */
4401 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004402} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004403
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004404/*****************************************************************************/
4405/* GPIO commands. Only available on EC if write protect has been disabled. */
4406
4407/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004408#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004409
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004410struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004411 char name[32];
4412 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004413} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004414
4415/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004416#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004417
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004418/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004419struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004420 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004421} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004422
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004423struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004424 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004425} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004426
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004427/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004428struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004429 uint8_t subcmd;
4430 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004431 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004432 char name[32];
4433 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004434 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004435 uint8_t index;
4436 } get_info;
4437 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004438} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004440struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004441 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004442 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004443 uint8_t val;
4444 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004445 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004446 uint8_t val;
4447 char name[32];
4448 uint32_t flags;
4449 } get_info;
4450 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004451} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004452
4453enum gpio_get_subcmd {
4454 EC_GPIO_GET_BY_NAME = 0,
4455 EC_GPIO_GET_COUNT = 1,
4456 EC_GPIO_GET_INFO = 2,
4457};
4458
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004459/*****************************************************************************/
4460/* I2C commands. Only available when flash write protect is unlocked. */
4461
Duncan Laurie93e24442014-01-06 12:30:52 -08004462/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004463 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4464 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4465 *
4466 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004467 */
4468
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004469/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004470#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004471
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004472struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004473 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004474 uint8_t read_size; /* Either 8 or 16. */
4475 uint8_t port;
4476 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004477} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004478
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004479struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004480 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004481} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004482
4483/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004484#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004485
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004486struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004487 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004488 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004489 uint8_t write_size; /* Either 8 or 16. */
4490 uint8_t port;
4491 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004492} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004493
4494/*****************************************************************************/
4495/* Charge state commands. Only available when flash write protect unlocked. */
4496
Duncan Laurie93e24442014-01-06 12:30:52 -08004497/* Force charge state machine to stop charging the battery or force it to
4498 * discharge the battery.
4499 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004500#define EC_CMD_CHARGE_CONTROL 0x0096
Simon Glassd3870a22023-11-09 08:43:30 -07004501#define EC_VER_CHARGE_CONTROL 3
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004502
Duncan Laurie93e24442014-01-06 12:30:52 -08004503enum ec_charge_control_mode {
4504 CHARGE_CONTROL_NORMAL = 0,
4505 CHARGE_CONTROL_IDLE,
4506 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004507 /* Add no more entry below. */
4508 CHARGE_CONTROL_COUNT,
4509};
4510
Caveh Jalali024ffe32023-01-30 14:35:19 -08004511#define EC_CHARGE_MODE_TEXT \
4512 { \
4513 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4514 [CHARGE_CONTROL_IDLE] = "IDLE", \
4515 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
Scott Chao18141d8c2021-07-30 10:40:57 +08004516 }
4517
4518enum ec_charge_control_cmd {
4519 EC_CHARGE_CONTROL_CMD_SET = 0,
4520 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004521};
4522
Simon Glassd3870a22023-11-09 08:43:30 -07004523enum ec_charge_control_flag {
4524 EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0),
4525};
4526
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004527struct ec_params_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004528 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004529
4530 /* Below are the fields added in V2. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004531 uint8_t cmd; /* enum ec_charge_control_cmd. */
Simon Glassd3870a22023-11-09 08:43:30 -07004532 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
Scott Chao18141d8c2021-07-30 10:40:57 +08004533 /*
4534 * Lower and upper thresholds for battery sustainer. This struct isn't
4535 * named to avoid tainting foreign projects' name spaces.
4536 *
4537 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4538 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4539 * lower=-1, upper=-1.
4540 */
4541 struct {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004542 int8_t lower; /* Display SoC in percentage. */
4543 int8_t upper; /* Display SoC in percentage. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004544 } sustain_soc;
4545} __ec_align4;
4546
4547/* Added in v2 */
4548struct ec_response_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004549 uint32_t mode; /* enum charge_control_mode */
4550 struct { /* Battery sustainer thresholds */
Scott Chao18141d8c2021-07-30 10:40:57 +08004551 int8_t lower;
4552 int8_t upper;
4553 } sustain_soc;
Simon Glassd3870a22023-11-09 08:43:30 -07004554 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
4555 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004556} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004557
4558/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004559
4560/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004561#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004562
4563/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004564 * Read data from the saved snapshot. If the subcmd parameter is
4565 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4566 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4567 * end of the previous snapshot.
4568 *
4569 * The params are only looked at in version >= 1 of this command. Prior
4570 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004571 *
4572 * Response is null-terminated string. Empty string, if there is no more
4573 * remaining output.
4574 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004575#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004576
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004577enum ec_console_read_subcmd {
4578 CONSOLE_READ_NEXT = 0,
4579 CONSOLE_READ_RECENT,
4580};
Duncan Laurieeb316852015-12-01 18:51:18 -08004581
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004582struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004583 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004584} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004585
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004586/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004587
4588/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004589 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004590 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004591 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4592 * EC_RES_SUCCESS if the command was successful.
4593 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004594 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004595#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004596
Caveh Jalali024ffe32023-01-30 14:35:19 -08004597#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004598
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004599struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004600 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004601} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004602
Duncan Laurie433432b2013-06-03 10:38:22 -07004603/*****************************************************************************/
4604/* USB port mux control. */
4605
4606/*
4607 * Switch USB mux or return to automatic switching.
4608 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004609#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004610
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004611struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004612 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004613} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004614
4615/*****************************************************************************/
4616/* LDOs / FETs control. */
4617
4618enum ec_ldo_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004619 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4620 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
Duncan Laurie433432b2013-06-03 10:38:22 -07004621};
4622
4623/*
4624 * Switch on/off a LDO.
4625 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004626#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004627
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004628struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004629 uint8_t index;
4630 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004631} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004632
4633/*
4634 * Get LDO state.
4635 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004636#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004637
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004638struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004639 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004640} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004641
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004642struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004643 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004644} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004645
4646/*****************************************************************************/
4647/* Power info. */
4648
4649/*
4650 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004651 *
4652 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004653 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004654#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004655
Jett Rinkba2edaf2020-01-14 11:49:06 -07004656/*
4657 * v1 of EC_CMD_POWER_INFO
4658 */
4659enum system_power_source {
4660 /*
4661 * Haven't established which power source is used yet,
4662 * or no presence signals are available
4663 */
4664 POWER_SOURCE_UNKNOWN = 0,
4665 /* System is running on battery alone */
4666 POWER_SOURCE_BATTERY = 1,
4667 /* System is running on A/C alone */
4668 POWER_SOURCE_AC = 2,
4669 /* System is running on A/C and battery */
4670 POWER_SOURCE_AC_BATTERY = 3,
4671};
4672
4673struct ec_response_power_info_v1 {
4674 /* enum system_power_source */
4675 uint8_t system_power_source;
4676 /* Battery state-of-charge, 0-100, 0 if not present */
4677 uint8_t battery_soc;
4678 /* AC Adapter 100% rating, Watts */
4679 uint8_t ac_adapter_100pct;
4680 /* AC Adapter 10ms rating, Watts */
4681 uint8_t ac_adapter_10ms;
4682 /* Battery 1C rating, derated */
4683 uint8_t battery_1cd;
4684 /* Rest of Platform average, Watts */
4685 uint8_t rop_avg;
4686 /* Rest of Platform peak, Watts */
4687 uint8_t rop_peak;
4688 /* Nominal charger efficiency, % */
4689 uint8_t nominal_charger_eff;
4690 /* Rest of Platform VR Average Efficiency, % */
4691 uint8_t rop_avg_eff;
4692 /* Rest of Platform VR Peak Efficiency, % */
4693 uint8_t rop_peak_eff;
4694 /* SoC VR Efficiency at Average level, % */
4695 uint8_t soc_avg_eff;
4696 /* SoC VR Efficiency at Peak level, % */
4697 uint8_t soc_peak_eff;
4698 /* Intel-specific items */
4699 struct {
4700 /* Battery's level of DBPT support: 0, 2 */
4701 uint8_t batt_dbpt_support_level;
4702 /*
4703 * Maximum peak power from battery (10ms), Watts
4704 * If DBPT is not supported, this is 0
4705 */
4706 uint8_t batt_dbpt_max_peak_power;
4707 /*
4708 * Sustained peak power from battery, Watts
4709 * If DBPT is not supported, this is 0
4710 */
4711 uint8_t batt_dbpt_sus_peak_power;
4712 } intel;
4713} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004714
4715/*****************************************************************************/
4716/* I2C passthru command */
4717
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004718#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004719
Duncan Laurie433432b2013-06-03 10:38:22 -07004720/* Read data; if not present, message is a write */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004721#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004722
4723/* Mask for address */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004724#define EC_I2C_ADDR_MASK 0x3ff
Duncan Laurie433432b2013-06-03 10:38:22 -07004725
Caveh Jalali024ffe32023-01-30 14:35:19 -08004726#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4727#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004728
4729/* Any error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004730#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
Duncan Laurie433432b2013-06-03 10:38:22 -07004731
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004732struct ec_params_i2c_passthru_msg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004733 uint16_t addr_flags; /* I2C peripheral address and flags */
4734 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004735} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004736
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004737struct ec_params_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004738 uint8_t port; /* I2C port number */
4739 uint8_t num_msgs; /* Number of messages */
Duncan Laurie433432b2013-06-03 10:38:22 -07004740 struct ec_params_i2c_passthru_msg msg[];
4741 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004742} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004743
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004744struct ec_response_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004745 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4746 uint8_t num_msgs; /* Number of messages processed */
4747 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004748} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004749
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004750/*****************************************************************************/
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004751/* AP hang detect */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004752#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004753
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004754#define EC_HANG_DETECT_MIN_TIMEOUT 5
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004755
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004756/* EC hang detect commands */
4757enum ec_hang_detect_cmds {
4758 /* Reload AP hang detect timer. */
4759 EC_HANG_DETECT_CMD_RELOAD = 0x0,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004760
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004761 /* Stop AP hang detect timer. */
4762 EC_HANG_DETECT_CMD_CANCEL = 0x1,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004763
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004764 /* Configure watchdog with given reboot timeout and
4765 * cancel currently running AP hand detect timer.
4766 */
4767 EC_HANG_DETECT_CMD_SET_TIMEOUT = 0x2,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004768
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004769 /* Get last hang status - whether the AP boot was clear or not */
4770 EC_HANG_DETECT_CMD_GET_STATUS = 0x3,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004771
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004772 /* Clear last hang status. Called when AP is rebooting/shutting down
4773 * gracefully.
4774 */
4775 EC_HANG_DETECT_CMD_CLEAR_STATUS = 0x4
4776};
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004777
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004778struct ec_params_hang_detect {
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004779 uint16_t command; /* enum ec_hang_detect_cmds */
4780 /* Timeout in seconds before generating reboot */
4781 uint16_t reboot_timeout_sec;
4782} __ec_align2;
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004783
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004784/* Status codes that describe whether AP has boot normally or the hang has been
4785 * detected and EC has reset AP
4786 */
4787enum ec_hang_detect_status {
4788 EC_HANG_DETECT_AP_BOOT_NORMAL = 0x0,
4789 EC_HANG_DETECT_AP_BOOT_EC_WDT = 0x1,
4790 EC_HANG_DETECT_AP_BOOT_COUNT,
4791};
4792struct ec_response_hang_detect {
4793 uint8_t status; /* enum ec_hang_detect_status */
4794} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004795/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004796/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004797
4798/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004799 * This is the single catch-all host command to exchange data regarding the
4800 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004801 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004802#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004803
4804/* Subcommands for this host command */
4805enum charge_state_command {
4806 CHARGE_STATE_CMD_GET_STATE,
4807 CHARGE_STATE_CMD_GET_PARAM,
4808 CHARGE_STATE_CMD_SET_PARAM,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004809 CHARGE_STATE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004810};
4811
4812/*
4813 * Known param numbers are defined here. Ranges are reserved for board-specific
4814 * params, which are handled by the particular implementations.
4815 */
4816enum charge_state_params {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004817 /* charger voltage limit */
4818 CS_PARAM_CHG_VOLTAGE,
4819
4820 /* charger current limit */
4821 CS_PARAM_CHG_CURRENT,
4822
4823 /* charger input current limit */
4824 CS_PARAM_CHG_INPUT_CURRENT,
4825
4826 /* charger-specific status */
4827 CS_PARAM_CHG_STATUS,
4828
4829 /* charger-specific options */
4830 CS_PARAM_CHG_OPTION,
4831
4832 /*
4833 * Check if power is limited due to low battery and / or a
4834 * weak external charger. READ ONLY.
4835 */
4836 CS_PARAM_LIMIT_POWER,
4837
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004838 /* How many so far? */
4839 CS_NUM_BASE_PARAMS,
4840
4841 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4842 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4843 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4844
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004845 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4846 CS_PARAM_DEBUG_MIN = 0x20000,
4847 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4848 CS_PARAM_DEBUG_MANUAL_MODE,
4849 CS_PARAM_DEBUG_SEEMS_DEAD,
4850 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004851 CS_PARAM_DEBUG_BATT_REMOVED, /* Deprecated */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004852 CS_PARAM_DEBUG_MANUAL_CURRENT,
4853 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4854 CS_PARAM_DEBUG_MAX = 0x2ffff,
4855
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004856 /* Other custom param ranges go here... */
4857};
4858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004859struct ec_params_charge_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004860 uint8_t cmd; /* enum charge_state_command */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004861 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004862 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004863
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004864 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004865 uint32_t param; /* enum charge_state_param */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004866 } get_param;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004867
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004868 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004869 uint32_t param; /* param to set */
4870 uint32_t value; /* value to set */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004871 } set_param;
4872 } __ec_todo_packed;
Caveh Jalali024ffe32023-01-30 14:35:19 -08004873 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004874} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004875
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004876struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004877 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004878 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004879 int ac;
4880 int chg_voltage;
4881 int chg_current;
4882 int chg_input_current;
4883 int batt_state_of_charge;
4884 } get_state;
4885
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004886 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004887 uint32_t value;
4888 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004889
4890 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004891 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004892} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004893
Duncan Laurie433432b2013-06-03 10:38:22 -07004894/*
4895 * Set maximum battery charging current.
4896 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004897#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Tim Van Pattencab60602023-02-24 12:27:04 -07004898#define EC_VER_CHARGE_CURRENT_LIMIT 1
Duncan Laurie433432b2013-06-03 10:38:22 -07004899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004900struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004901 uint32_t limit; /* in mA */
Caveh Jalali839ada12022-10-31 23:16:48 -07004902} __ec_align4;
Tim Van Pattencab60602023-02-24 12:27:04 -07004903
Caveh Jalali839ada12022-10-31 23:16:48 -07004904struct ec_params_current_limit_v1 {
4905 uint32_t limit; /* in mA */
Tim Van Pattencab60602023-02-24 12:27:04 -07004906 /*
4907 * Battery state of charge is the minimum charge percentage at which
4908 * the battery charge current limit will apply.
4909 * When not set, the limit will apply regardless of state of charge.
4910 */
4911 uint8_t battery_soc; /* battery state of charge, 0-100 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004912} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004913
4914/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004915 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004916 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004917#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004918
Duncan Laurieeb316852015-12-01 18:51:18 -08004919/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004920struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004921 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4922 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004923} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004924
Duncan Laurieeb316852015-12-01 18:51:18 -08004925#define EC_POWER_LIMIT_NONE 0xffff
4926
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004927/*
4928 * Set maximum voltage & current of a dedicated charge port
4929 */
4930#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4931
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004932struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004933 uint16_t current_lim; /* in mA */
4934 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004935} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004936
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08004937/*
4938 * Get and set charging splashscreen variables
4939 */
4940#define EC_CMD_CHARGESPLASH 0x00A5
4941
4942enum ec_chargesplash_cmd {
4943 /* Get the current state variables */
4944 EC_CHARGESPLASH_GET_STATE = 0,
4945
4946 /* Indicate initialization of the display loop */
4947 EC_CHARGESPLASH_DISPLAY_READY,
4948
4949 /* Manually put the EC into the requested state */
4950 EC_CHARGESPLASH_REQUEST,
4951
4952 /* Reset all state variables */
4953 EC_CHARGESPLASH_RESET,
4954
4955 /* Manually trigger a lockout */
4956 EC_CHARGESPLASH_LOCKOUT,
4957};
4958
4959struct __ec_align1 ec_params_chargesplash {
4960 /* enum ec_chargesplash_cmd */
4961 uint8_t cmd;
4962};
4963
4964struct __ec_align1 ec_response_chargesplash {
4965 uint8_t requested;
4966 uint8_t display_initialized;
4967 uint8_t locked_out;
4968};
4969
Duncan Laurieeb316852015-12-01 18:51:18 -08004970/*****************************************************************************/
4971/* Hibernate/Deep Sleep Commands */
4972
4973/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004974#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004975
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004976struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004977 /*
4978 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4979 * current settings without changing them.
4980 */
4981 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004982} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004983
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004984struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004985 /*
4986 * The current time in seconds in which the system has been in the G3
4987 * state. This value is reset if the EC transitions out of G3.
4988 */
4989 uint32_t time_g3;
4990
4991 /*
4992 * The current time remaining in seconds until the EC should hibernate.
4993 * This value is also reset if the EC transitions out of G3.
4994 */
4995 uint32_t time_remaining;
4996
4997 /*
4998 * The current time in seconds that the EC should wait in G3 before
4999 * hibernating.
5000 */
5001 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005002} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005003
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005004/* Inform the EC when entering a sleep state */
5005#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
5006
5007enum host_sleep_event {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005008 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
5009 HOST_SLEEP_EVENT_S3_RESUME = 2,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005010 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005011 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005012 /* S3 suspend with additional enabled wake sources */
5013 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005014};
5015
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005016struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005017 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005018} __ec_align1;
5019
5020/*
5021 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
5022 * transition failures
5023 */
5024#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
5025
5026/* Disable timeout detection for this sleep transition */
5027#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
5028
5029struct ec_params_host_sleep_event_v1 {
5030 /* The type of sleep being entered or exited. */
5031 uint8_t sleep_event;
5032
5033 /* Padding */
5034 uint8_t reserved;
5035 union {
5036 /* Parameters that apply for suspend messages. */
5037 struct {
5038 /*
5039 * The timeout in milliseconds between when this message
5040 * is received and when the EC will declare sleep
5041 * transition failure if the sleep signal is not
5042 * asserted.
5043 */
5044 uint16_t sleep_timeout_ms;
5045 } suspend_params;
5046
5047 /* No parameters for non-suspend messages. */
5048 };
5049} __ec_align2;
5050
5051/* A timeout occurred when this bit is set */
5052#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
5053
5054/*
5055 * The mask defining which bits correspond to the number of sleep transitions,
5056 * as well as the maximum number of suspend line transitions that will be
5057 * reported back to the host.
5058 */
5059#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
5060
5061struct ec_response_host_sleep_event_v1 {
5062 union {
5063 /* Response fields that apply for resume messages. */
5064 struct {
5065 /*
5066 * The number of sleep power signal transitions that
5067 * occurred since the suspend message. The high bit
5068 * indicates a timeout occurred.
5069 */
5070 uint32_t sleep_transitions;
5071 } resume_response;
5072
5073 /* No response fields for non-resume messages. */
5074 };
5075} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005076
5077/*****************************************************************************/
5078/* Device events */
5079#define EC_CMD_DEVICE_EVENT 0x00AA
5080
5081enum ec_device_event {
5082 EC_DEVICE_EVENT_TRACKPAD,
5083 EC_DEVICE_EVENT_DSP,
5084 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005085 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005086};
5087
5088enum ec_device_event_param {
5089 /* Get and clear pending device events */
5090 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
5091 /* Get device event mask */
5092 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
5093 /* Set device event mask */
5094 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
5095};
5096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005097#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005098
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005099struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005100 uint32_t event_mask;
5101 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005102} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005103
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005104struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005105 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005106} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005107
Duncan Laurie433432b2013-06-03 10:38:22 -07005108/*****************************************************************************/
Caveh Jalali839ada12022-10-31 23:16:48 -07005109/* Get s0ix counter */
5110#define EC_CMD_GET_S0IX_COUNTER 0x00AB
5111
5112/* Flag use to reset the counter */
5113#define EC_S0IX_COUNTER_RESET 0x1
5114
5115struct ec_params_s0ix_cnt {
5116 /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */
5117 uint32_t flags;
5118} __ec_align4;
5119
5120struct ec_response_s0ix_cnt {
5121 /* Value of the s0ix_counter */
5122 uint32_t s0ix_counter;
5123} __ec_align4;
5124
5125/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07005126/* Smart battery pass-through */
5127
Caveh Jalali839ada12022-10-31 23:16:48 -07005128/* Get / Set 16-bit smart battery registers - OBSOLETE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005129#define EC_CMD_SB_READ_WORD 0x00B0
5130#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07005131
5132/* Get / Set string smart battery parameters
Caveh Jalali839ada12022-10-31 23:16:48 -07005133 * formatted as SMBUS "block". - OBSOLETE
Duncan Laurie433432b2013-06-03 10:38:22 -07005134 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005135#define EC_CMD_SB_READ_BLOCK 0x00B2
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005136#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07005137
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005138/*****************************************************************************/
5139/* Battery vendor parameters
5140 *
5141 * Get or set vendor-specific parameters in the battery. Implementations may
5142 * differ between boards or batteries. On a set operation, the response
5143 * contains the actual value set, which may be rounded or clipped from the
5144 * requested value.
5145 */
5146
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005147#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005148
5149enum ec_battery_vendor_param_mode {
5150 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5151 BATTERY_VENDOR_PARAM_MODE_SET,
5152};
5153
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005154struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005155 uint32_t param;
5156 uint32_t value;
5157 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005158} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005159
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005160struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005161 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005162} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005163
5164/*****************************************************************************/
5165/*
Caveh Jalali839ada12022-10-31 23:16:48 -07005166 * Smart Battery Firmware Update Command - OBSOLETE
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005167 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005168#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005169
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005170/*
5171 * Entering Verified Boot Mode Command
5172 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5173 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07005174 *
5175 * EC no longer needs to know what mode vboot has entered,
5176 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005177 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005178#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005179
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005180struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005181 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005182} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005183
Caveh Jalali024ffe32023-01-30 14:35:19 -08005184#define VBOOT_MODE_NORMAL 0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005185#define VBOOT_MODE_DEVELOPER 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08005186#define VBOOT_MODE_RECOVERY 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005187
Duncan Laurie433432b2013-06-03 10:38:22 -07005188/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07005189/*
5190 * I2C passthru protection command: Protects I2C tunnels against access on
5191 * certain addresses (board-specific).
5192 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005193#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07005194
5195enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005196 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5197 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5198 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005199};
5200
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005201struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005202 uint8_t subcmd;
Caveh Jalali024ffe32023-01-30 14:35:19 -08005203 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005204} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005205
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005206struct ec_response_i2c_passthru_protect {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005207 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005208} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005209
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005210/*****************************************************************************/
5211/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005212 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005213 *
5214 * These commands are for sending and receiving message via HDMI CEC
5215 */
5216
Simon Glassd3870a22023-11-09 08:43:30 -07005217#define EC_CEC_MAX_PORTS 16
5218
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005219#define MAX_CEC_MSG_LEN 16
5220
Simon Glassd3870a22023-11-09 08:43:30 -07005221/*
5222 * Helper macros for packing/unpacking cec_events.
5223 * bits[27:0] : bitmask of events from enum mkbp_cec_event
5224 * bits[31:28]: port number
5225 */
5226#define EC_MKBP_EVENT_CEC_PACK(events, port) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05005227 (((events) & GENMASK(27, 0)) | (((port) & 0xf) << 28))
5228#define EC_MKBP_EVENT_CEC_GET_EVENTS(event) ((event) & GENMASK(27, 0))
Simon Glassd3870a22023-11-09 08:43:30 -07005229#define EC_MKBP_EVENT_CEC_GET_PORT(event) (((event) >> 28) & 0xf)
5230
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005231/* CEC message from the AP to be written on the CEC bus */
5232#define EC_CMD_CEC_WRITE_MSG 0x00B8
5233
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005234/**
5235 * struct ec_params_cec_write - Message to write to the CEC bus
5236 * @msg: message content to write to the CEC bus
5237 */
5238struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005239 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005240} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005241
Simon Glassd3870a22023-11-09 08:43:30 -07005242/**
5243 * struct ec_params_cec_write_v1 - Message to write to the CEC bus
5244 * @port: CEC port to write the message on
5245 * @msg_len: length of msg in bytes
5246 * @msg: message content to write to the CEC bus
5247 */
5248struct ec_params_cec_write_v1 {
5249 uint8_t port;
5250 uint8_t msg_len;
5251 uint8_t msg[MAX_CEC_MSG_LEN];
5252} __ec_align1;
5253
5254/* CEC message read from a CEC bus reported back to the AP */
5255#define EC_CMD_CEC_READ_MSG 0x00B9
5256
5257/**
5258 * struct ec_params_cec_read - Read a message from the CEC bus
5259 * @port: CEC port to read a message on
5260 */
5261struct ec_params_cec_read {
5262 uint8_t port;
5263} __ec_align1;
5264
5265/**
5266 * struct ec_response_cec_read - Message read from the CEC bus
5267 * @msg_len: length of msg in bytes
5268 * @msg: message content read from the CEC bus
5269 */
5270struct ec_response_cec_read {
5271 uint8_t msg_len;
5272 uint8_t msg[MAX_CEC_MSG_LEN];
5273} __ec_align1;
5274
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005275/* Set various CEC parameters */
5276#define EC_CMD_CEC_SET 0x00BA
5277
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005278/**
5279 * struct ec_params_cec_set - CEC parameters set
5280 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
Simon Glassd3870a22023-11-09 08:43:30 -07005281 * @port: CEC port to set the parameter on
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005282 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5283 * or 1 to enable CEC functionality, in case cmd is
5284 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5285 * address between 0 and 15 or 0xff to unregister
5286 */
5287struct ec_params_cec_set {
Simon Glassd3870a22023-11-09 08:43:30 -07005288 uint8_t cmd : 4; /* enum cec_command */
5289 uint8_t port : 4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005290 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005291} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005292
5293/* Read various CEC parameters */
5294#define EC_CMD_CEC_GET 0x00BB
5295
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005296/**
5297 * struct ec_params_cec_get - CEC parameters get
5298 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
Simon Glassd3870a22023-11-09 08:43:30 -07005299 * @port: CEC port to get the parameter on
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005300 */
5301struct ec_params_cec_get {
Simon Glassd3870a22023-11-09 08:43:30 -07005302 uint8_t cmd : 4; /* enum cec_command */
5303 uint8_t port : 4;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005304} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005305
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005306/**
5307 * struct ec_response_cec_get - CEC parameters get response
5308 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5309 * disabled or 1 if CEC functionality is enabled,
5310 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5311 * configured logical address between 0 and 15 or 0xff if unregistered
5312 */
5313struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005314 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005315} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005316
Simon Glassd3870a22023-11-09 08:43:30 -07005317/* Get the number of CEC ports */
5318#define EC_CMD_CEC_PORT_COUNT 0x00C1
5319
5320/**
5321 * struct ec_response_cec_port_count - CEC port count response
5322 * @port_count: number of CEC ports
5323 */
5324struct ec_response_cec_port_count {
5325 uint8_t port_count;
5326} __ec_align1;
5327
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005328/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005329enum cec_command {
5330 /* CEC reading, writing and events enable */
5331 CEC_CMD_ENABLE,
5332 /* CEC logical address */
5333 CEC_CMD_LOGICAL_ADDRESS,
5334};
5335
5336/* Events from CEC to AP */
5337enum mkbp_cec_event {
5338 /* Outgoing message was acknowledged by a follower */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005339 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005340 /* Outgoing message was not acknowledged */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005341 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Simon Glassd3870a22023-11-09 08:43:30 -07005342 /* Incoming message can be read out by AP */
5343 EC_MKBP_CEC_HAVE_DATA = BIT(2),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005344};
5345
Gwendal Grignou880b4582016-06-20 08:49:25 -07005346/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005347
Jett Rinkba2edaf2020-01-14 11:49:06 -07005348/* Commands for audio codec. */
5349#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005350
Jett Rinkba2edaf2020-01-14 11:49:06 -07005351enum ec_codec_subcmd {
5352 EC_CODEC_GET_CAPABILITIES = 0x0,
5353 EC_CODEC_GET_SHM_ADDR = 0x1,
5354 EC_CODEC_SET_SHM_ADDR = 0x2,
5355 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005356};
5357
Jett Rinkba2edaf2020-01-14 11:49:06 -07005358enum ec_codec_cap {
5359 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5360 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5361 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005362};
5363
Jett Rinkba2edaf2020-01-14 11:49:06 -07005364enum ec_codec_shm_id {
5365 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5366 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5367 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005368};
5369
Jett Rinkba2edaf2020-01-14 11:49:06 -07005370enum ec_codec_shm_type {
5371 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5372 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005373};
5374
Jett Rinkba2edaf2020-01-14 11:49:06 -07005375struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5376 uint8_t shm_id;
5377 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005378};
5379
Jett Rinkba2edaf2020-01-14 11:49:06 -07005380struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5381 uint64_t phys_addr;
5382 uint32_t len;
5383 uint8_t shm_id;
5384 uint8_t reserved[3];
5385};
5386
5387struct __ec_align4 ec_param_ec_codec {
5388 uint8_t cmd; /* enum ec_codec_subcmd */
5389 uint8_t reserved[3];
5390
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005391 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005392 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5393 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005394 };
5395};
5396
Jett Rinkba2edaf2020-01-14 11:49:06 -07005397struct __ec_align4 ec_response_ec_codec_get_capabilities {
5398 uint32_t capabilities;
5399};
5400
5401struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5402 uint64_t phys_addr;
5403 uint32_t len;
5404 uint8_t type;
5405 uint8_t reserved[3];
5406};
5407
5408/*****************************************************************************/
5409
5410/* Commands for DMIC on audio codec. */
5411#define EC_CMD_EC_CODEC_DMIC 0x00BD
5412
5413enum ec_codec_dmic_subcmd {
5414 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5415 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5416 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5417 EC_CODEC_DMIC_SUBCMD_COUNT,
5418};
5419
5420enum ec_codec_dmic_channel {
5421 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5422 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5423 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5424 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5425 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5426 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5427 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5428 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5429 EC_CODEC_DMIC_CHANNEL_COUNT,
5430};
5431
5432struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5433 uint8_t channel; /* enum ec_codec_dmic_channel */
5434 uint8_t gain;
5435 uint8_t reserved[2];
5436};
5437
5438struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5439 uint8_t channel; /* enum ec_codec_dmic_channel */
5440 uint8_t reserved[3];
5441};
5442
5443struct __ec_align4 ec_param_ec_codec_dmic {
5444 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5445 uint8_t reserved[3];
5446
5447 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005448 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5449 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005450 };
5451};
5452
5453struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5454 uint8_t max_gain;
5455};
5456
5457struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5458 uint8_t gain;
5459};
5460
5461/*****************************************************************************/
5462
5463/* Commands for I2S RX on audio codec. */
5464
5465#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5466
5467enum ec_codec_i2s_rx_subcmd {
5468 EC_CODEC_I2S_RX_ENABLE = 0x0,
5469 EC_CODEC_I2S_RX_DISABLE = 0x1,
5470 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5471 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5472 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005473 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005474 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5475};
5476
5477enum ec_codec_i2s_rx_sample_depth {
5478 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5479 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5480 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5481};
5482
5483enum ec_codec_i2s_rx_daifmt {
5484 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5485 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5486 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5487 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5488};
5489
5490struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5491 uint8_t depth;
5492 uint8_t reserved[3];
5493};
5494
5495struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5496 uint8_t left;
5497 uint8_t right;
5498 uint8_t reserved[2];
5499};
5500
5501struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5502 uint8_t daifmt;
5503 uint8_t reserved[3];
5504};
5505
5506struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5507 uint32_t bclk;
5508};
5509
5510struct __ec_align4 ec_param_ec_codec_i2s_rx {
5511 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5512 uint8_t reserved[3];
5513
5514 union {
5515 struct ec_param_ec_codec_i2s_rx_set_sample_depth
Caveh Jalali024ffe32023-01-30 14:35:19 -08005516 set_sample_depth_param;
5517 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5518 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005519 };
5520};
5521
5522/*****************************************************************************/
5523/* Commands for WoV on audio codec. */
5524
5525#define EC_CMD_EC_CODEC_WOV 0x00BF
5526
5527enum ec_codec_wov_subcmd {
5528 EC_CODEC_WOV_SET_LANG = 0x0,
5529 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5530 EC_CODEC_WOV_GET_LANG = 0x2,
5531 EC_CODEC_WOV_ENABLE = 0x3,
5532 EC_CODEC_WOV_DISABLE = 0x4,
5533 EC_CODEC_WOV_READ_AUDIO = 0x5,
5534 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5535 EC_CODEC_WOV_SUBCMD_COUNT,
5536};
5537
5538/*
5539 * @hash is SHA256 of the whole language model.
5540 * @total_len indicates the length of whole language model.
5541 * @offset is the cursor from the beginning of the model.
5542 * @buf is the packet buffer.
5543 * @len denotes how many bytes in the buf.
5544 */
5545struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5546 uint8_t hash[32];
5547 uint32_t total_len;
5548 uint32_t offset;
5549 uint8_t buf[128];
5550 uint32_t len;
5551};
5552
5553struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5554 uint8_t hash[32];
5555 uint32_t total_len;
5556};
5557
5558struct __ec_align4 ec_param_ec_codec_wov {
5559 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5560 uint8_t reserved[3];
5561
5562 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005563 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5564 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005565 };
5566};
5567
5568struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5569 uint8_t hash[32];
5570};
5571
5572struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5573 uint8_t buf[128];
5574 uint32_t len;
5575};
5576
5577struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5578 uint32_t offset;
5579 uint32_t len;
5580};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005581
5582/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005583/* Commands for PoE PSE controller */
5584
5585#define EC_CMD_PSE 0x00C0
5586
5587enum ec_pse_subcmd {
5588 EC_PSE_STATUS = 0x0,
5589 EC_PSE_ENABLE = 0x1,
5590 EC_PSE_DISABLE = 0x2,
5591 EC_PSE_SUBCMD_COUNT,
5592};
5593
5594struct __ec_align1 ec_params_pse {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005595 uint8_t cmd; /* enum ec_pse_subcmd */
5596 uint8_t port; /* PSE port */
Yidi Lin42f79592020-09-21 18:04:10 +08005597};
5598
5599enum ec_pse_status {
5600 EC_PSE_STATUS_DISABLED = 0x0,
5601 EC_PSE_STATUS_ENABLED = 0x1,
5602 EC_PSE_STATUS_POWERED = 0x2,
5603};
5604
5605struct __ec_align1 ec_response_pse_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005606 uint8_t status; /* enum ec_pse_status */
Yidi Lin42f79592020-09-21 18:04:10 +08005607};
5608
5609/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005610/* System commands */
5611
5612/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005613 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5614 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005615 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005616#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005617
5618/* Command */
5619enum ec_reboot_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005620 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5621 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5622 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005623 /* (command 3 was jump to RW-B) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005624 EC_REBOOT_COLD = 4, /* Cold-reboot */
5625 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5626 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005627 /*
5628 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5629 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5630 */
5631 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005632 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5633 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005634};
5635
5636/* Flags for ec_params_reboot_ec.reboot_flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005637#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5638#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5639#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5640#define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005641
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005642struct ec_params_reboot_ec {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005643 uint8_t cmd; /* enum ec_reboot_cmd */
5644 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005645} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005646
Duncan Laurie433432b2013-06-03 10:38:22 -07005647/*
5648 * Get information on last EC panic.
5649 *
5650 * Returns variable-length platform-dependent panic information. See panic.h
5651 * for details.
5652 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005653#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005654
Simon Glassd3870a22023-11-09 08:43:30 -07005655struct ec_params_get_panic_info_v1 {
5656 /* Do not modify PANIC_DATA_FLAG_OLD_HOSTCMD when reading panic info */
5657 uint8_t preserve_old_hostcmd_flag;
5658} __ec_align1;
5659
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005660/*****************************************************************************/
5661/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005662 * Special commands
5663 *
5664 * These do not follow the normal rules for commands. See each command for
5665 * details.
5666 */
5667
5668/*
5669 * Reboot NOW
5670 *
5671 * This command will work even when the EC LPC interface is busy, because the
5672 * reboot command is processed at interrupt level. Note that when the EC
5673 * reboots, the host will reboot too, so there is no response to this command.
5674 *
5675 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5676 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005677#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005678
5679/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005680 * Resend last response (not supported on LPC).
5681 *
5682 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5683 * there was no previous command, or the previous command's response was too
5684 * big to save.
5685 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005686#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005687
5688/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005689 * This header byte on a command indicate version 0. Any header byte less
5690 * than this means that we are talking to an old EC which doesn't support
5691 * versioning. In that case, we assume version 0.
5692 *
5693 * Header bytes greater than this indicate a later version. For example,
5694 * EC_CMD_VERSION0 + 1 means we are using version 1.
5695 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005696 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005697 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005698#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005699
Caveh Jalali839ada12022-10-31 23:16:48 -07005700/*
5701 * Memory Dump Commands
5702 *
5703 * Since the HOSTCMD response size is limited, depending on the
5704 * protocol, retrieving a memory dump is split into 3 commands.
5705 *
5706 * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries,
5707 * and the total dump size.
5708 * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given
5709 * memory dump entry index.
5710 * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given
5711 * address. The address and size must be within the bounds of the given
5712 * memory dump entry index. Each response is limited to the max response size
5713 * of the host protocol, so this may need to be called repeatedly to retrieve
5714 * the entire memory dump entry.
5715 *
5716 * Memory entries may overlap and may be out of order.
5717 * The host should check for overlaps to optimize transfer rate.
5718 */
5719#define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD
5720struct ec_response_memory_dump_get_metadata {
5721 uint16_t memory_dump_entry_count;
5722 uint32_t memory_dump_total_size;
5723} __ec_align4;
5724
5725#define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE
5726struct ec_params_memory_dump_get_entry_info {
5727 uint16_t memory_dump_entry_index;
5728} __ec_align4;
5729
5730struct ec_response_memory_dump_get_entry_info {
5731 uint32_t address;
5732 uint32_t size;
5733} __ec_align4;
5734
5735#define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF
5736
5737struct ec_params_memory_dump_read_memory {
5738 uint16_t memory_dump_entry_index;
5739 uint32_t address;
5740 uint32_t size;
5741} __ec_align4;
5742
5743/*
5744 * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into
5745 * host_cmd_handler_args.response and host_cmd_handler_args.response_size.
5746 */
5747
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005748/*****************************************************************************/
5749/*
5750 * PD commands
5751 *
5752 * These commands are for PD MCU communication.
5753 */
5754
5755/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005756#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005757#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005758
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005759enum pd_charge_state {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005760 /* Don't change charge state */
5761 PD_CHARGE_NO_CHANGE = 0,
5762
5763 /* No charging allowed */
5764 PD_CHARGE_NONE,
5765
5766 /* 5V charging only */
5767 PD_CHARGE_5V,
5768
5769 /* Charge at max voltage */
5770 PD_CHARGE_MAX,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005771};
5772
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005773/* Status of EC being sent to PD */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005774#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005775
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005776struct ec_params_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005777 /* EC status */
5778 uint8_t status;
5779
5780 /* battery state of charge */
5781 int8_t batt_soc;
5782
5783 /* charging state (from enum pd_charge_state) */
5784 uint8_t charge_state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005785} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005786
5787/* Status of PD being sent back to EC */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005788#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5789#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005790#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005791#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5792#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5793#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5794#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
5795#define PD_STATUS_EC_INT_ACTIVE \
5796 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005797struct ec_response_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005798 /* input current limit */
5799 uint32_t curr_lim_ma;
5800
5801 /* PD MCU status */
5802 uint16_t status;
5803
5804 /* active charging port */
5805 int8_t active_charge_port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005806} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005807
5808/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005809#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005810
5811/* PD MCU host event status bits */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005812#define PD_EVENT_UPDATE_DEVICE BIT(0)
5813#define PD_EVENT_POWER_CHANGE BIT(1)
5814#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5815#define PD_EVENT_DATA_SWAP BIT(3)
5816#define PD_EVENT_TYPEC BIT(4)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005817
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005818struct ec_response_host_event_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005819 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005820} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005821
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005822/*
5823 * Set USB type-C port role and muxes
5824 *
5825 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5826 *
5827 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5828 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005829#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005830
5831enum usb_pd_control_role {
5832 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5833 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5834 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5835 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5836 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005837 USB_PD_CTRL_ROLE_FREEZE = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005838 USB_PD_CTRL_ROLE_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005839};
5840
5841enum usb_pd_control_mux {
5842 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5843 USB_PD_CTRL_MUX_NONE = 1,
5844 USB_PD_CTRL_MUX_USB = 2,
5845 USB_PD_CTRL_MUX_DP = 3,
5846 USB_PD_CTRL_MUX_DOCK = 4,
5847 USB_PD_CTRL_MUX_AUTO = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005848 USB_PD_CTRL_MUX_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005849};
5850
Duncan Laurieeb316852015-12-01 18:51:18 -08005851enum usb_pd_control_swap {
5852 USB_PD_CTRL_SWAP_NONE = 0,
5853 USB_PD_CTRL_SWAP_DATA = 1,
5854 USB_PD_CTRL_SWAP_POWER = 2,
5855 USB_PD_CTRL_SWAP_VCONN = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005856 USB_PD_CTRL_SWAP_COUNT,
Duncan Laurieeb316852015-12-01 18:51:18 -08005857};
5858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005859struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005860 uint8_t port;
5861 uint8_t role;
5862 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005863 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005864} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005865
Caveh Jalali024ffe32023-01-30 14:35:19 -08005866#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5867#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005868#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005869
Caveh Jalali024ffe32023-01-30 14:35:19 -08005870#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5871#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5872#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5873#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5874#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5875#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005876/* Partner unconstrained power */
5877#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
Duncan Laurieeb316852015-12-01 18:51:18 -08005878
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005879struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005880 uint8_t enabled;
5881 uint8_t role;
5882 uint8_t polarity;
5883 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005884} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005885
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005886struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005887 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005888 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005889 uint8_t polarity;
5890 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005891} __ec_align1;
5892
Jett Rinkba2edaf2020-01-14 11:49:06 -07005893/* Possible port partner connections based on CC line states */
5894enum pd_cc_states {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005895 PD_CC_NONE = 0, /* No port partner attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005896
5897 /* From DFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005898 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
5899 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5900 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5901 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005902
5903 /* From UFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005904 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
5905 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005906};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005907
Jett Rinkba2edaf2020-01-14 11:49:06 -07005908/* Active/Passive Cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005909#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005910/* Optical/Non-optical cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005911#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005912/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005913#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005914/* Active Link Uni-Direction */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005915#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Caveh Jalali839ada12022-10-31 23:16:48 -07005916/* Retimer/Redriver cable */
5917#define USB_PD_CTRL_RETIMER_CABLE BIT(4)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005918
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005919struct ec_response_usb_pd_control_v2 {
5920 uint8_t enabled;
5921 uint8_t role;
5922 uint8_t polarity;
5923 char state[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08005924 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5925 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
5926 uint8_t reserved; /* Reserved for future use */
5927 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5928 uint8_t cable_speed; /* TBT_SS_* cable speed */
5929 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005930} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005931
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005932#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005933
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005934/* Maximum number of PD ports on a device, num_ports will be <= this */
5935#define EC_USB_PD_MAX_PORTS 8
5936
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005937struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005938 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005939} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005940
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005941#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005942
5943#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005944struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005945 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005946} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005947
5948enum usb_chg_type {
5949 USB_CHG_TYPE_NONE,
5950 USB_CHG_TYPE_PD,
5951 USB_CHG_TYPE_C,
5952 USB_CHG_TYPE_PROPRIETARY,
5953 USB_CHG_TYPE_BC12_DCP,
5954 USB_CHG_TYPE_BC12_CDP,
5955 USB_CHG_TYPE_BC12_SDP,
5956 USB_CHG_TYPE_OTHER,
5957 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005958 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005959 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005960};
5961enum usb_power_roles {
5962 USB_PD_PORT_POWER_DISCONNECTED,
5963 USB_PD_PORT_POWER_SOURCE,
5964 USB_PD_PORT_POWER_SINK,
5965 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5966};
5967
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005968struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005969 uint16_t voltage_max;
5970 uint16_t voltage_now;
5971 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005972 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005973} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005974
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005975struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005976 uint8_t role;
5977 uint8_t type;
5978 uint8_t dualrole;
5979 uint8_t reserved1;
5980 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005981 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005982} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005983
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005984/*
5985 * This command will return the number of USB PD charge port + the number
5986 * of dedicated port present.
5987 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5988 */
5989#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005990struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005991 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005992} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005993
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08005994/*
5995 * This command enable/disable dynamic PDO selection.
5996 */
5997#define EC_CMD_USB_PD_DPS_CONTROL 0x0106
5998
5999struct ec_params_usb_pd_dps_control {
6000 uint8_t enable;
6001} __ec_align1;
6002
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006003/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006004#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006005
6006enum usb_pd_fw_update_cmds {
6007 USB_PD_FW_REBOOT,
6008 USB_PD_FW_FLASH_ERASE,
6009 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006010 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006011};
6012
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006013struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006014 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006015 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006016 uint8_t port;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006017
6018 /* Size to write in bytes */
6019 uint32_t size;
6020
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006021 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006022} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006023
6024/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006025#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006026/* RW hash is first 20 bytes of SHA-256 of RW section */
6027#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006028struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006029 uint16_t dev_id;
6030 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006031
6032 /*
6033 * Reserved for alignment of current_image
6034 * TODO(rspangler) but it's not aligned!
6035 * Should have been reserved[2].
6036 */
6037 uint8_t reserved;
6038
6039 /* One of ec_image */
6040 uint32_t current_image;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006041} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006042
6043/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006044#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006045
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006046struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006047 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006048} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006049
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006050/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006051#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006052struct ec_params_usb_pd_discovery_entry {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006053 uint16_t vid; /* USB-IF VID */
6054 uint16_t pid; /* USB-IF PID */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006055 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006056} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006057
6058/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006059#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006060
6061/* Negative port parameters have special meaning */
6062enum usb_pd_override_ports {
Simon Glassd3870a22023-11-09 08:43:30 -07006063 /*
6064 * DONT_CHARGE is for all ports. Thus it's persistent across plug-in
6065 * or plug-out.
6066 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006067 OVERRIDE_DONT_CHARGE = -2,
6068 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07006069 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006070};
6071
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006072struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006073 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006074} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006075
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006076/*
6077 * Read (and delete) one entry of PD event log.
6078 * TODO(crbug.com/751742): Make this host command more generic to accommodate
6079 * future non-PD logs that use the same internal EC event_log.
6080 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006081#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006082
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006083struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006084 uint32_t timestamp; /* relative timestamp in milliseconds */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006085 uint8_t type; /* event type : see PD_EVENT_xx below */
6086 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
6087 uint16_t data; /* type-defined data payload */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006088 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006089} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006090
6091/* The timestamp is the microsecond counter shifted to get about a ms. */
6092#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
6093
Caveh Jalali024ffe32023-01-30 14:35:19 -08006094#define PD_LOG_SIZE_MASK 0x1f
6095#define PD_LOG_PORT_MASK 0xe0
6096#define PD_LOG_PORT_SHIFT 5
6097#define PD_LOG_PORT_SIZE(port, size) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006098 (((port) << PD_LOG_PORT_SHIFT) | ((size) & PD_LOG_SIZE_MASK))
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006099#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006100#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006101
6102/* PD event log : entry types */
6103/* PD MCU events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006104#define PD_EVENT_MCU_BASE 0x00
6105#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
6106#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006107/* Reserved for custom board event */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006108#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006109/* PD generic accessory events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006110#define PD_EVENT_ACC_BASE 0x20
6111#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
6112#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006113/* PD power supply events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006114#define PD_EVENT_PS_BASE 0x40
6115#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006116/* PD video dongles events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006117#define PD_EVENT_VIDEO_BASE 0x60
6118#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
6119#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006120/* Returned in the "type" field, when there is no entry available */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006121#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006122
6123/*
6124 * PD_EVENT_MCU_CHARGE event definition :
6125 * the payload is "struct usb_chg_measures"
6126 * the data field contains the port state flags as defined below :
6127 */
6128/* Port partner is a dual role device */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006129#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006130/* Port is the pending override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006131#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006132/* Port is the override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006133#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006134/* Charger type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006135#define CHARGE_FLAGS_TYPE_SHIFT 3
6136#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006137/* Power delivery role */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006138#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006139
6140/*
6141 * PD_EVENT_PS_FAULT data field flags definition :
6142 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006143#define PS_FAULT_OCP 1
6144#define PS_FAULT_FAST_OCP 2
6145#define PS_FAULT_OVP 3
6146#define PS_FAULT_DISCH 4
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006147
6148/*
6149 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
6150 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006151struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006152 uint8_t major;
6153 uint8_t minor;
6154 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006155} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006156
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006157struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006158 uint8_t family[2];
6159 uint8_t chipid[2];
6160 struct mcdp_version irom;
6161 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006162} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006163
6164/* struct mcdp_info field decoding */
6165#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
6166#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
6167
6168/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006169#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006170struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006171 uint16_t svid_idx; /* SVID index to get */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006172 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006173} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006174
Caveh Jalali839ada12022-10-31 23:16:48 -07006175#define VDO_MAX_SIZE 7
6176/* Max number of VDM data objects without VDM header */
6177#define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1)
6178
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006179struct ec_params_usb_pd_get_mode_response {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006180 uint16_t svid; /* SVID */
6181 uint16_t opos; /* Object Position */
Caveh Jalali839ada12022-10-31 23:16:48 -07006182 uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006183} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006184
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006185#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006186
6187enum pd_mode_cmd {
6188 PD_EXIT_MODE = 0,
6189 PD_ENTER_MODE = 1,
6190 /* Not a command. Do NOT remove. */
6191 PD_MODE_CMD_COUNT,
6192};
6193
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006194struct ec_params_usb_pd_set_mode_request {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006195 uint32_t cmd; /* enum pd_mode_cmd */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006196 uint16_t svid; /* SVID to set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006197 uint8_t opos; /* Object Position */
6198 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006199} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006200
6201/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006202#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006203
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006204struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006205 uint8_t type; /* event type : see PD_EVENT_xx above */
6206 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006207} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006208
Gwendal Grignou880b4582016-06-20 08:49:25 -07006209/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006210#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07006211
6212enum ec_pd_control_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006213 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6214 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6215 PD_RESET, /* Force reset the PD chip */
6216 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6217 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006218};
6219
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006220struct ec_params_pd_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006221 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006222 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006223} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07006224
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006225/* Get info about USB-C SS muxes */
6226#define EC_CMD_USB_PD_MUX_INFO 0x011A
6227
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006228struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006229 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006230} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006231
6232/* Flags representing mux state */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006233#define USB_PD_MUX_NONE 0 /* Open switch */
6234#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6235#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6236#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6237#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6238#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6239#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6240#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6241#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006242#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006243#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006244
6245/* USB-C Dock connected */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006246#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006247
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006248struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006249 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006250} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006251
Caveh Jalali024ffe32023-01-30 14:35:19 -08006252#define EC_CMD_PD_CHIP_INFO 0x011B
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006253
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006254struct ec_params_pd_chip_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006255 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006256 /*
6257 * Fetch the live chip info or hard-coded + cached chip info
6258 * 0: hardcoded value for VID/PID, cached value for FW version
6259 * 1: live chip value for VID/PID/FW Version
6260 */
6261 uint8_t live;
6262} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006263
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006264struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006265 uint16_t vendor_id;
6266 uint16_t product_id;
6267 uint16_t device_id;
6268 union {
6269 uint8_t fw_version_string[8];
6270 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006271 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006272} __ec_align2;
6273
6274struct ec_response_pd_chip_info_v1 {
6275 uint16_t vendor_id;
6276 uint16_t product_id;
6277 uint16_t device_id;
6278 union {
6279 uint8_t fw_version_string[8];
6280 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006281 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006282 union {
6283 uint8_t min_req_fw_version_string[8];
6284 uint64_t min_req_fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006285 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006286} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006287
6288/* Run RW signature verification and get status */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006289#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006290
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006291struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006292 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006293} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006294
6295/* For controlling RWSIG task */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006296#define EC_CMD_RWSIG_ACTION 0x011D
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006297
6298enum rwsig_action {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006299 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6300 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006301};
6302
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006303struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006304 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006305} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006306
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006307/* Run verification on a slot */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006308#define EC_CMD_EFS_VERIFY 0x011E
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006309
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006310struct ec_params_efs_verify {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006311 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006312} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006313
6314/*
6315 * Retrieve info from Cros Board Info store. Response is based on the data
6316 * type. Integers return a uint32. Strings return a string, using the response
6317 * size to determine how big it is.
6318 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006319#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006320/*
6321 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6322 * hardware write-protect enabled.
6323 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006324#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006325
Daisuke Nojirif984a052018-02-15 12:38:15 -08006326enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006327 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006328 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6329 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06006330 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006331 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6332 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6333 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6334 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08006335 /* Second Source Factory Cache */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006336 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6337 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006338 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */
Simon Glassd3870a22023-11-09 08:43:30 -07006339
6340 /*
6341 * A uint32_t field reserved for controlling common features at runtime.
6342 * It shouldn't be used at board-level. See union ec_common_control for
6343 * the bit definitions.
6344 */
6345 CBI_TAG_COMMON_CONTROL = 11,
6346
6347 /* struct board_batt_params */
6348 CBI_TAG_BATTERY_CONFIG = 12,
6349 /* CBI_TAG_BATTERY_CONFIG_1 ~ 15 will use 13 ~ 27. */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006350 CBI_TAG_BATTERY_CONFIG_15 = 27,
Simon Glassd3870a22023-11-09 08:43:30 -07006351
6352 /* Last entry */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006353 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006354};
6355
Simon Glassd3870a22023-11-09 08:43:30 -07006356union ec_common_control {
6357 struct {
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006358 uint32_t bcic_enabled : 1; /* Unused. Take it over as yours. */
Simon Glassd3870a22023-11-09 08:43:30 -07006359 };
6360 uint32_t raw_value;
6361};
6362
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006363/*
6364 * Flags to control read operation
6365 *
6366 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6367 * write was successful without reboot.
6368 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006369#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006370
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006371struct ec_params_get_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006372 uint32_t tag; /* enum cbi_data_tag */
6373 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006374} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006375
6376/*
6377 * Flags to control write behavior.
6378 *
6379 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6380 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006381 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006382 * will be initialized to zero first.
6383 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006384#define CBI_SET_NO_SYNC BIT(0)
6385#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006386
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006387struct ec_params_set_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006388 uint32_t tag; /* enum cbi_data_tag */
6389 uint32_t flag; /* CBI_SET_* */
6390 uint32_t size; /* Data size */
6391 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006392} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006393
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006394/*
6395 * Information about resets of the AP by the EC and the EC's own uptime.
6396 */
6397#define EC_CMD_GET_UPTIME_INFO 0x0121
6398
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006399/* EC reset causes */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006400#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6401#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6402#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6403#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6404#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6405#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6406#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6407#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6408#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6409#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6410#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6411#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6412#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006413/* Some reset flags preserved from previous boot */
6414#define EC_RESET_FLAG_PRESERVED BIT(13)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006415#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6416#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6417#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6418#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006419/* AP experienced a watchdog reset */
6420#define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6421/* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6422#define EC_RESET_FLAG_STAY_IN_RO BIT(19)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006423#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6424#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6425#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006426
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006427/*
6428 * Reason codes used by the AP after a shutdown to figure out why it was reset
6429 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6430 * compatibility:
6431 * - New entries must be inserted prior to the _COUNT field
6432 * - If an existing entry is no longer in service, it must be replaced with a
6433 * RESERVED entry instead.
6434 * - The semantic meaning of an entry should not change.
6435 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6436 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006437enum chipset_shutdown_reason {
6438 /*
6439 * Beginning of reset reasons.
6440 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006441 CHIPSET_RESET_BEGIN = 0,
6442 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6443 /* Custom reason defined by a board.c or baseboard.c file */
6444 CHIPSET_RESET_BOARD_CUSTOM,
6445 /* Believe that the AP has hung */
6446 CHIPSET_RESET_HANG_REBOOT,
6447 /* Reset by EC console command */
6448 CHIPSET_RESET_CONSOLE_CMD,
6449 /* Reset by EC host command */
6450 CHIPSET_RESET_HOST_CMD,
6451 /* Keyboard module reset key combination */
6452 CHIPSET_RESET_KB_SYSRESET,
6453 /* Keyboard module warm reboot */
6454 CHIPSET_RESET_KB_WARM_REBOOT,
6455 /* Debug module warm reboot */
6456 CHIPSET_RESET_DBG_WARM_REBOOT,
6457 /* I cannot self-terminate. You must lower me into the steel. */
6458 CHIPSET_RESET_AP_REQ,
6459 /* Reset as side-effect of startup sequence */
6460 CHIPSET_RESET_INIT,
6461 /* EC detected an AP watchdog event. */
6462 CHIPSET_RESET_AP_WATCHDOG,
6463
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006464 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006465
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006466 /*
6467 * Beginning of shutdown reasons.
6468 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006469 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6470 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6471 /* Forcing a shutdown as part of EC initialization */
6472 CHIPSET_SHUTDOWN_INIT,
6473 /* Custom reason on a per-board basis. */
6474 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6475 /* This is a reason to inhibit startup, not cause shut down. */
6476 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6477 /* A power_wait_signal is being asserted */
6478 CHIPSET_SHUTDOWN_WAIT,
6479 /* Critical battery level. */
6480 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6481 /* Because you told me to. */
6482 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6483 /* Forcing a shutdown to effect entry to G3. */
6484 CHIPSET_SHUTDOWN_G3,
6485 /* Force shutdown due to over-temperature. */
6486 CHIPSET_SHUTDOWN_THERMAL,
6487 /* Force a chipset shutdown from the power button through EC */
6488 CHIPSET_SHUTDOWN_BUTTON,
6489
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006490 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006491};
6492
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006493struct ec_response_uptime_info {
6494 /*
6495 * Number of milliseconds since the last EC boot. Sysjump resets
6496 * typically do not restart the EC's time_since_boot epoch.
6497 *
6498 * WARNING: The EC's sense of time is much less accurate than the AP's
6499 * sense of time, in both phase and frequency. This timebase is similar
6500 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6501 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006502 uint32_t time_since_ec_boot_ms;
6503
6504 /*
6505 * Number of times the AP was reset by the EC since the last EC boot.
6506 * Note that the AP may be held in reset by the EC during the initial
6507 * boot sequence, such that the very first AP boot may count as more
6508 * than one here.
6509 */
6510 uint32_t ap_resets_since_ec_boot;
6511
6512 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006513 * The set of flags which describe the EC's most recent reset.
6514 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006515 */
6516 uint32_t ec_reset_flags;
6517
6518 /* Empty log entries have both the cause and timestamp set to zero. */
6519 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006520 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006521 uint16_t reset_cause;
6522
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006523 /* Reserved for protocol growth. */
6524 uint16_t reserved;
6525
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006526 /*
6527 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006528 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6529 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006530 */
6531 uint32_t reset_time_ms;
6532 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006533} __ec_align4;
6534
6535/*
6536 * Add entropy to the device secret (stored in the rollback region).
6537 *
6538 * Depending on the chip, the operation may take a long time (e.g. to erase
6539 * flash), so the commands are asynchronous.
6540 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006541#define EC_CMD_ADD_ENTROPY 0x0122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006542
6543enum add_entropy_action {
6544 /* Add entropy to the current secret. */
6545 ADD_ENTROPY_ASYNC = 0,
6546 /*
6547 * Add entropy, and also make sure that the previous secret is erased.
6548 * (this can be implemented by adding entropy multiple times until
6549 * all rolback blocks have been overwritten).
6550 */
6551 ADD_ENTROPY_RESET_ASYNC = 1,
6552 /* Read back result from the previous operation. */
6553 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006554};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006555
6556struct ec_params_rollback_add_entropy {
6557 uint8_t action;
6558} __ec_align1;
6559
6560/*
6561 * Perform a single read of a given ADC channel.
6562 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006563#define EC_CMD_ADC_READ 0x0123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006564
6565struct ec_params_adc_read {
6566 uint8_t adc_channel;
6567} __ec_align1;
6568
6569struct ec_response_adc_read {
6570 int32_t adc_value;
6571} __ec_align4;
6572
6573/*
6574 * Read back rollback info
6575 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006576#define EC_CMD_ROLLBACK_INFO 0x0124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006577
6578struct ec_response_rollback_info {
6579 int32_t id; /* Incrementing number to indicate which region to use. */
6580 int32_t rollback_min_version;
6581 int32_t rw_rollback_version;
6582} __ec_align4;
6583
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006584/* Issue AP reset */
6585#define EC_CMD_AP_RESET 0x0125
6586
6587/*****************************************************************************/
6588/* Locate peripheral chips
6589 *
6590 * Return values:
6591 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6592 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6593 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6594 */
6595#define EC_CMD_LOCATE_CHIP 0x0126
6596
6597enum ec_chip_type {
6598 EC_CHIP_TYPE_CBI_EEPROM = 0,
6599 EC_CHIP_TYPE_TCPC = 1,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006600 EC_CHIP_TYPE_PDC = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006601 EC_CHIP_TYPE_COUNT,
6602 EC_CHIP_TYPE_MAX = 0xFF,
6603};
6604
6605enum ec_bus_type {
6606 EC_BUS_TYPE_I2C = 0,
6607 EC_BUS_TYPE_EMBEDDED = 1,
6608 EC_BUS_TYPE_COUNT,
6609 EC_BUS_TYPE_MAX = 0xFF,
6610};
6611
6612struct ec_i2c_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006613 uint16_t port; /* Physical port for device */
6614 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006615};
6616
6617struct ec_params_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006618 uint8_t type; /* enum ec_chip_type */
6619 uint8_t index; /* Specifies one instance of chip type */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006620 /* Used for type specific parameters in future */
6621 union {
6622 uint16_t reserved;
6623 };
6624} __ec_align2;
6625
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006626struct ec_response_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006627 uint8_t bus_type; /* enum ec_bus_type */
6628 uint8_t reserved; /* Aligning the following union to 2 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006629 union {
6630 struct ec_i2c_info i2c_info;
6631 };
6632} __ec_align2;
6633
Jett Rinkba2edaf2020-01-14 11:49:06 -07006634/*
6635 * Reboot AP on G3
6636 *
6637 * This command is used for validation purpose, where the AP needs to be
6638 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006639 * wake events.
6640 * - With command version 0:
6641 * AP reboots immediately from G3
6642 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6643 * - With command version 1:
6644 * AP reboots after the user specified delay
6645 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006646 */
6647#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6648
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006649struct ec_params_reboot_ap_on_g3_v1 {
6650 /* configurable delay in seconds in G3 state */
6651 uint32_t reboot_ap_at_g3_delay;
6652} __ec_align4;
6653
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006654/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006655/* Get PD port capabilities
6656 *
6657 * Returns the following static *capabilities* of the given port:
6658 * 1) Power role: source, sink, or dual. It is not anticipated that
6659 * future CrOS devices would ever be only a source, so the options are
6660 * sink or dual.
6661 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6662 * believe any CrOS device would support Try.SNK, so this would be source
6663 * or none).
6664 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6665 * for CrOS devices.
6666 */
6667#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6668
6669enum ec_pd_power_role_caps {
6670 EC_PD_POWER_ROLE_SOURCE = 0,
6671 EC_PD_POWER_ROLE_SINK = 1,
6672 EC_PD_POWER_ROLE_DUAL = 2,
6673};
6674
6675enum ec_pd_try_power_role_caps {
6676 EC_PD_TRY_POWER_ROLE_NONE = 0,
6677 EC_PD_TRY_POWER_ROLE_SINK = 1,
6678 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6679};
6680
6681enum ec_pd_data_role_caps {
6682 EC_PD_DATA_ROLE_DFP = 0,
6683 EC_PD_DATA_ROLE_UFP = 1,
6684 EC_PD_DATA_ROLE_DUAL = 2,
6685};
6686
6687/* From: power_manager/power_supply_properties.proto */
6688enum ec_pd_port_location {
6689 /* The location of the port is unknown, or there's only one port. */
6690 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6691
6692 /*
6693 * Various positions on the device. The first word describes the side of
6694 * the device where the port is located while the second clarifies the
6695 * position. For example, LEFT_BACK means the farthest-back port on the
6696 * left side, while BACK_LEFT means the leftmost port on the back of the
6697 * device.
6698 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006699 EC_PD_PORT_LOCATION_LEFT = 1,
6700 EC_PD_PORT_LOCATION_RIGHT = 2,
6701 EC_PD_PORT_LOCATION_BACK = 3,
6702 EC_PD_PORT_LOCATION_FRONT = 4,
6703 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6704 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006705 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006706 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6707 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6708 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006709};
6710
6711struct ec_params_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006712 uint8_t port; /* Which port to interrogate */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006713} __ec_align1;
6714
6715struct ec_response_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006716 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6717 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6718 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6719 uint8_t pd_port_location; /* enum ec_pd_port_location */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006720} __ec_align1;
6721
6722/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006723/*
6724 * Button press simulation
6725 *
6726 * This command is used to simulate a button press.
6727 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6728 * Time duration for which button needs to be pressed is an optional parameter.
6729 *
6730 * NOTE: This is only available on unlocked devices for testing purposes only.
6731 */
6732#define EC_CMD_BUTTON 0x0129
6733
6734struct ec_params_button {
6735 /* Button mask aligned to enum keyboard_button_type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006736 uint32_t btn_mask;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006737
6738 /* Duration in milliseconds button needs to be pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006739 uint32_t press_ms;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006740} __ec_align1;
6741
6742enum keyboard_button_type {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006743 KEYBOARD_BUTTON_POWER = 0,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006744 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006745 KEYBOARD_BUTTON_VOLUME_UP = 2,
6746 KEYBOARD_BUTTON_RECOVERY = 3,
6747 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6748 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6749 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6750 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6751 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6752 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6753 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6754 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006755
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006756 KEYBOARD_BUTTON_COUNT,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006757};
Yidi Lin42f79592020-09-21 18:04:10 +08006758
Rajat Jainc0495722020-04-02 23:58:35 -07006759/*****************************************************************************/
6760/*
6761 * "Get the Keyboard Config". An EC implementing this command is expected to be
6762 * vivaldi capable, i.e. can send action codes for the top row keys.
6763 * Additionally, capability to send function codes for the same keys is
6764 * optional and acceptable.
6765 *
6766 * Note: If the top row can generate both function and action codes by
6767 * using a dedicated Fn key, it does not matter whether the key sends
6768 * "function" or "action" codes by default. In both cases, the response
6769 * for this command will look the same.
6770 */
6771#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6772
6773/* Possible values for the top row keys */
6774enum action_key {
6775 TK_ABSENT = 0,
6776 TK_BACK = 1,
6777 TK_FORWARD = 2,
6778 TK_REFRESH = 3,
6779 TK_FULLSCREEN = 4,
6780 TK_OVERVIEW = 5,
6781 TK_BRIGHTNESS_DOWN = 6,
6782 TK_BRIGHTNESS_UP = 7,
6783 TK_VOL_MUTE = 8,
6784 TK_VOL_DOWN = 9,
6785 TK_VOL_UP = 10,
6786 TK_SNAPSHOT = 11,
6787 TK_PRIVACY_SCRN_TOGGLE = 12,
6788 TK_KBD_BKLIGHT_DOWN = 13,
6789 TK_KBD_BKLIGHT_UP = 14,
6790 TK_PLAY_PAUSE = 15,
6791 TK_NEXT_TRACK = 16,
6792 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006793 TK_KBD_BKLIGHT_TOGGLE = 18,
6794 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006795 TK_MENU = 20,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006796 TK_DICTATE = 21,
6797
6798 TK_COUNT
Rajat Jainc0495722020-04-02 23:58:35 -07006799};
6800
6801/*
6802 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6803 * If this needs to change, please create a new version of the command.
6804 */
6805#define MAX_TOP_ROW_KEYS 15
6806#define MIN_TOP_ROW_KEYS 10
6807
6808/*
6809 * Is the keyboard capable of sending function keys *in addition to*
6810 * action keys. This is possible for e.g. if the keyboard has a
6811 * dedicated Fn key.
6812 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006813#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
Rajat Jainc0495722020-04-02 23:58:35 -07006814/*
6815 * Whether the keyboard has a dedicated numeric keyboard.
6816 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006817#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
Rajat Jainc0495722020-04-02 23:58:35 -07006818/*
6819 * Whether the keyboard has a screenlock key.
6820 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006821#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
Rajat Jainc0495722020-04-02 23:58:35 -07006822
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006823/*
6824 * Whether the keyboard has an assistant key.
6825 */
6826#define KEYBD_CAP_ASSISTANT_KEY BIT(3)
6827
Rajat Jainc0495722020-04-02 23:58:35 -07006828struct ec_response_keybd_config {
6829 /*
6830 * Number of top row keys, excluding Esc and Screenlock.
6831 * If this is 0, all Vivaldi keyboard code is disabled.
6832 * (i.e. does not expose any tables to the kernel).
6833 */
6834 uint8_t num_top_row_keys;
6835
6836 /*
6837 * The action keys in the top row, in order from left to right.
6838 * The values are filled from enum action_key. Esc and Screenlock
6839 * keys are not considered part of top row keys.
6840 */
6841 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6842
6843 /* Capability flags */
6844 uint8_t capabilities;
6845
6846} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006847
Yidi Lin42f79592020-09-21 18:04:10 +08006848/*
6849 * Configure smart discharge
6850 */
6851#define EC_CMD_SMART_DISCHARGE 0x012B
6852
Caveh Jalali024ffe32023-01-30 14:35:19 -08006853#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
Yidi Lin42f79592020-09-21 18:04:10 +08006854
6855/* Discharge rates when the system is in cutoff or hibernation. */
6856struct discharge_rate {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006857 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6858 uint16_t hibern; /* Discharge rate (uA) in hibernation */
Yidi Lin42f79592020-09-21 18:04:10 +08006859};
6860
6861struct smart_discharge_zone {
6862 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6863 int cutoff;
6864 /* When the capacity (mAh) is below this, EC stays up. */
6865 int stayup;
6866};
6867
6868struct ec_params_smart_discharge {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006869 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
Yidi Lin42f79592020-09-21 18:04:10 +08006870 /*
6871 * Desired hours for the battery to survive before reaching 0%. Set to
6872 * zero to disable smart discharging. That is, the system hibernates as
6873 * soon as the G3 idle timer expires.
6874 */
6875 uint16_t hours_to_zero;
6876 /* Set both to zero to keep the current rates. */
6877 struct discharge_rate drate;
6878};
6879
6880struct ec_response_smart_discharge {
6881 uint16_t hours_to_zero;
6882 struct discharge_rate drate;
6883 struct smart_discharge_zone dzone;
6884};
6885
6886/*****************************************************************************/
6887/* Voltage regulator controls */
6888
6889/*
6890 * Get basic info of voltage regulator for given index.
6891 *
6892 * Returns the regulator name and supported voltage list in mV.
6893 */
6894#define EC_CMD_REGULATOR_GET_INFO 0x012C
6895
6896/* Maximum length of regulator name */
6897#define EC_REGULATOR_NAME_MAX_LEN 16
6898
6899/* Maximum length of the supported voltage list. */
6900#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6901
6902struct ec_params_regulator_get_info {
6903 uint32_t index;
6904} __ec_align4;
6905
6906struct ec_response_regulator_get_info {
6907 char name[EC_REGULATOR_NAME_MAX_LEN];
6908 uint16_t num_voltages;
6909 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6910} __ec_align2;
6911
6912/*
6913 * Configure the regulator as enabled / disabled.
6914 */
6915#define EC_CMD_REGULATOR_ENABLE 0x012D
6916
6917struct ec_params_regulator_enable {
6918 uint32_t index;
6919 uint8_t enable;
6920} __ec_align4;
6921
6922/*
6923 * Query if the regulator is enabled.
6924 *
6925 * Returns 1 if the regulator is enabled, 0 if not.
6926 */
6927#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6928
6929struct ec_params_regulator_is_enabled {
6930 uint32_t index;
6931} __ec_align4;
6932
6933struct ec_response_regulator_is_enabled {
6934 uint8_t enabled;
6935} __ec_align1;
6936
6937/*
6938 * Set voltage for the voltage regulator within the range specified.
6939 *
6940 * The driver should select the voltage in range closest to min_mv.
6941 *
6942 * Also note that this might be called before the regulator is enabled, and the
6943 * setting should be in effect after the regulator is enabled.
6944 */
6945#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6946
6947struct ec_params_regulator_set_voltage {
6948 uint32_t index;
6949 uint32_t min_mv;
6950 uint32_t max_mv;
6951} __ec_align4;
6952
6953/*
6954 * Get the currently configured voltage for the voltage regulator.
6955 *
6956 * Note that this might be called before the regulator is enabled, and this
6957 * should return the configured output voltage if the regulator is enabled.
6958 */
6959#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6960
6961struct ec_params_regulator_get_voltage {
6962 uint32_t index;
6963} __ec_align4;
6964
6965struct ec_response_regulator_get_voltage {
6966 uint32_t voltage_mv;
6967} __ec_align4;
6968
6969/*
6970 * Gather all discovery information for the given port and partner type.
6971 *
6972 * Note that if discovery has not yet completed, only the currently completed
6973 * responses will be filled in. If the discovery data structures are changed
6974 * in the process of the command running, BUSY will be returned.
6975 *
6976 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6977 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6978 * maximum parameter size.
6979 */
6980#define EC_CMD_TYPEC_DISCOVERY 0x0131
6981
6982enum typec_partner_type {
6983 TYPEC_PARTNER_SOP = 0,
6984 TYPEC_PARTNER_SOP_PRIME = 1,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006985 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
Yidi Lin42f79592020-09-21 18:04:10 +08006986};
6987
6988struct ec_params_typec_discovery {
6989 uint8_t port;
6990 uint8_t partner_type; /* enum typec_partner_type */
6991} __ec_align1;
6992
6993struct svid_mode_info {
6994 uint16_t svid;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006995 uint16_t mode_count; /* Number of modes partner sent */
Caveh Jalali839ada12022-10-31 23:16:48 -07006996 uint32_t mode_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08006997};
6998
6999struct ec_response_typec_discovery {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007000 uint8_t identity_count; /* Number of identity VDOs partner sent */
7001 uint8_t svid_count; /* Number of SVIDs partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08007002 uint16_t reserved;
Caveh Jalali839ada12022-10-31 23:16:48 -07007003 uint32_t discovery_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08007004 struct svid_mode_info svids[0];
7005} __ec_align1;
7006
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007007/* USB Type-C commands for AP-controlled device policy. */
7008#define EC_CMD_TYPEC_CONTROL 0x0132
7009
7010enum typec_control_command {
7011 TYPEC_CONTROL_COMMAND_EXIT_MODES,
7012 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007013 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007014 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007015 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007016 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
7017 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007018};
7019
7020/* Modes (USB or alternate) that a type-C port may enter. */
7021enum typec_mode {
7022 TYPEC_MODE_DP,
7023 TYPEC_MODE_TBT,
7024 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007025};
7026
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007027/* Replies the AP may specify to the TBT EnterMode command as a UFP */
7028enum typec_tbt_ufp_reply {
7029 TYPEC_TBT_UFP_REPLY_NAK,
7030 TYPEC_TBT_UFP_REPLY_ACK,
7031};
7032
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007033#define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
7034
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007035struct typec_usb_mux_set {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007036 /* Index of the mux to set in the chain */
7037 uint8_t mux_index;
7038
7039 /* USB_PD_MUX_*-encoded USB mux state to set */
7040 uint8_t mux_flags;
7041} __ec_align1;
7042
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007043struct typec_vdm_req {
7044 /* VDM data, including VDM header */
7045 uint32_t vdm_data[VDO_MAX_SIZE];
7046 /* Number of 32-bit fields filled in */
7047 uint8_t vdm_data_objects;
7048 /* Partner to address - see enum typec_partner_type */
7049 uint8_t partner_type;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007050} __ec_align1;
7051
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007052struct ec_params_typec_control {
7053 uint8_t port;
Caveh Jalali024ffe32023-01-30 14:35:19 -08007054 uint8_t command; /* enum typec_control_command */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007055 uint16_t reserved;
7056
7057 /*
7058 * This section will be interpreted based on |command|. Define a
7059 * placeholder structure to avoid having to increase the size and bump
7060 * the command version when adding new sub-commands.
7061 */
7062 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007063 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007064 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007065 /* Used for ENTER_MODE - enum typec_mode */
7066 uint8_t mode_to_enter;
7067 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
7068 uint8_t tbt_ufp_reply;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007069 /* Used for USB_MUX_SET */
7070 struct typec_usb_mux_set mux_params;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007071 /* Used for BIST_SHARE_MODE */
7072 uint8_t bist_share_mode;
7073 /* Used for VMD_REQ */
7074 struct typec_vdm_req vdm_req_params;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007075 uint8_t placeholder[128];
7076 };
7077} __ec_align1;
7078
7079/*
7080 * Gather all status information for a port.
7081 *
7082 * Note: this covers many of the return fields from the deprecated
7083 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
7084 * discovery data. The "enum pd_cc_states" is defined with the deprecated
7085 * EC_CMD_USB_PD_CONTROL command.
7086 *
7087 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007088 */
7089#define EC_CMD_TYPEC_STATUS 0x0133
7090
7091/*
7092 * Power role.
7093 *
7094 * Note this is also used for PD header creation, and values align to those in
7095 * the Power Delivery Specification Revision 3.0 (See
7096 * 6.2.1.1.4 Port Power Role).
7097 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007098enum pd_power_role {
7099 PD_ROLE_SINK = 0,
7100 PD_ROLE_SOURCE = 1,
7101};
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007102
7103/*
7104 * Data role.
7105 *
7106 * Note this is also used for PD header creation, and the first two values
7107 * align to those in the Power Delivery Specification Revision 3.0 (See
7108 * 6.2.1.1.6 Port Data Role).
7109 */
7110enum pd_data_role {
7111 PD_ROLE_UFP = 0,
7112 PD_ROLE_DFP = 1,
7113 PD_ROLE_DISCONNECTED = 2,
7114};
7115
7116enum pd_vconn_role {
7117 PD_ROLE_VCONN_OFF = 0,
7118 PD_ROLE_VCONN_SRC = 1,
7119};
7120
7121/*
7122 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
7123 * regardless of whether a debug accessory is connected.
7124 */
7125enum tcpc_cc_polarity {
7126 /*
7127 * _CCx: is used to indicate the polarity while not connected to
7128 * a Debug Accessory. Only one CC line will assert a resistor and
7129 * the other will be open.
7130 */
7131 POLARITY_CC1 = 0,
7132 POLARITY_CC2 = 1,
7133
7134 /*
7135 * _CCx_DTS is used to indicate the polarity while connected to a
7136 * SRC Debug Accessory. Assert resistors on both lines.
7137 */
7138 POLARITY_CC1_DTS = 2,
7139 POLARITY_CC2_DTS = 3,
7140
7141 /*
7142 * The current TCPC code relies on these specific POLARITY values.
7143 * Adding in a check to verify if the list grows for any reason
7144 * that this will give a hint that other places need to be
7145 * adjusted.
7146 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007147 POLARITY_COUNT,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007148};
7149
Caveh Jalali024ffe32023-01-30 14:35:19 -08007150#define MODE_DP_PIN_A BIT(0)
7151#define MODE_DP_PIN_B BIT(1)
7152#define MODE_DP_PIN_C BIT(2)
7153#define MODE_DP_PIN_D BIT(3)
7154#define MODE_DP_PIN_E BIT(4)
7155#define MODE_DP_PIN_F BIT(5)
7156#define MODE_DP_PIN_ALL GENMASK(5, 0)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007157
Caveh Jalali024ffe32023-01-30 14:35:19 -08007158#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
7159#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
7160#define PD_STATUS_EVENT_HARD_RESET BIT(2)
7161#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
7162#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
7163#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007164#define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
7165#define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
7166#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007167#define PD_STATUS_EVENT_COUNT 9
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007168
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007169/*
7170 * Encode and decode for BCD revision response
7171 *
7172 * Note: the major revision set is written assuming that the value given is the
7173 * Specification Revision from the PD header, which currently only maps to PD
7174 * 1.0-3.0 with the major revision being one greater than the binary value.
7175 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007176#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
7177#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
7178#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007179
7180/*
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007181 * Encode revision from partner RMDO
7182 *
7183 * Unlike the specification revision given in the PD header, specification and
7184 * version information returned in the revision message data object (RMDO) is
7185 * not offset.
7186 */
7187#define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
7188#define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
7189#define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
7190#define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
7191
7192/*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007193 * Decode helpers for Source and Sink Capability PDOs
7194 *
7195 * Note: The Power Delivery Specification should be considered the ultimate
7196 * source of truth on the decoding of these PDOs
7197 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007198#define PDO_TYPE_FIXED (0 << 30)
7199#define PDO_TYPE_BATTERY (1 << 30)
7200#define PDO_TYPE_VARIABLE (2 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007201#define PDO_TYPE_AUGMENTED (3 << 30)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007202#define PDO_TYPE_MASK (3 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007203
7204/*
7205 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
7206 *
7207 * <31:30> : Fixed Supply
7208 * <29> : Dual-Role Power
7209 * <28> : SNK/SRC dependent
7210 * <27> : Unconstrained Power
7211 * <26> : USB Communications Capable
7212 * <25> : Dual-Role Data
7213 * <24:20> : SNK/SRC dependent
7214 * <19:10> : Voltage in 50mV Units
7215 * <9:0> : Maximum Current in 10mA units
7216 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007217#define PDO_FIXED_DUAL_ROLE BIT(29)
7218#define PDO_FIXED_UNCONSTRAINED BIT(27)
7219#define PDO_FIXED_COMM_CAP BIT(26)
7220#define PDO_FIXED_DATA_SWAP BIT(25)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007221#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007222#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7223#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007224
7225/*
7226 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
7227 *
7228 * <31:30> : Battery
7229 * <29:20> : Maximum Voltage in 50mV units
7230 * <19:10> : Minimum Voltage in 50mV units
7231 * <9:0> : Maximum Allowable Power in 250mW units
7232 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007233#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7234#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7235#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007236
7237/*
7238 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7239 *
7240 * <31:30> : Variable Supply (non-Battery)
7241 * <29:20> : Maximum Voltage in 50mV units
7242 * <19:10> : Minimum Voltage in 50mV units
7243 * <9:0> : Operational Current in 10mA units
7244 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007245#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7246#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7247#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007248
7249/*
7250 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7251 *
7252 * Note this type is reserved in PD 2.0, and only one type of APDO is
7253 * supported as of the cited version.
7254 *
7255 * <31:30> : Augmented Power Data Object
7256 * <29:28> : Programmable Power Supply
7257 * <27> : PPS Power Limited
7258 * <26:25> : Reserved
7259 * <24:17> : Maximum Voltage in 100mV increments
7260 * <16> : Reserved
7261 * <15:8> : Minimum Voltage in 100mV increments
7262 * <7> : Reserved
7263 * <6:0> : Maximum Current in 50mA increments
7264 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007265#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7266#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7267#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007268
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007269struct ec_params_typec_status {
7270 uint8_t port;
7271} __ec_align1;
7272
Caveh Jalali839ada12022-10-31 23:16:48 -07007273/*
7274 * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1.
7275 * If you need to support old ECs who speak only v0, use
7276 * ec_response_typec_status_v0 instead. They're binary-compatible.
7277 */
7278struct ec_response_typec_status /* DEPRECATED */ {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007279 uint8_t pd_enabled; /* PD communication enabled - bool */
7280 uint8_t dev_connected; /* Device connected - bool */
7281 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7282 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007283
Caveh Jalali024ffe32023-01-30 14:35:19 -08007284 uint8_t power_role; /* enum pd_power_role */
7285 uint8_t data_role; /* enum pd_data_role */
7286 uint8_t vconn_role; /* enum pd_vconn_role */
7287 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007288
Caveh Jalali024ffe32023-01-30 14:35:19 -08007289 uint8_t polarity; /* enum tcpc_cc_polarity */
7290 uint8_t cc_state; /* enum pd_cc_states */
7291 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7292 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007293
Caveh Jalali024ffe32023-01-30 14:35:19 -08007294 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007295
Caveh Jalali024ffe32023-01-30 14:35:19 -08007296 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007297
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007298 /*
7299 * BCD PD revisions for partners
7300 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007301 * The format has the PD major revision in the upper nibble, and the PD
7302 * minor revision in the next nibble. The following two nibbles hold the
7303 * major and minor specification version. If a partner does not support
7304 * the Revision message, only the major revision will be given.
7305 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007306 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007307 * PD revision/version will be 0 if no PD device is connected.
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007308 */
7309 uint16_t sop_revision;
7310 uint16_t sop_prime_revision;
7311
Caveh Jalali024ffe32023-01-30 14:35:19 -08007312 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007313
Caveh Jalali024ffe32023-01-30 14:35:19 -08007314 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007315} __ec_align1;
7316
Caveh Jalali839ada12022-10-31 23:16:48 -07007317struct cros_ec_typec_status {
7318 uint8_t pd_enabled; /* PD communication enabled - bool */
7319 uint8_t dev_connected; /* Device connected - bool */
7320 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7321 uint8_t source_cap_count; /* Number of Source Cap PDOs */
7322
7323 uint8_t power_role; /* enum pd_power_role */
7324 uint8_t data_role; /* enum pd_data_role */
7325 uint8_t vconn_role; /* enum pd_vconn_role */
7326 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
7327
7328 uint8_t polarity; /* enum tcpc_cc_polarity */
7329 uint8_t cc_state; /* enum pd_cc_states */
7330 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7331 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
7332
7333 char tc_state[32]; /* TC state name */
7334
7335 uint32_t events; /* PD_STATUS_EVENT bitmask */
7336
7337 /*
7338 * BCD PD revisions for partners
7339 *
7340 * The format has the PD major revision in the upper nibble, and the PD
7341 * minor revision in the next nibble. The following two nibbles hold the
7342 * major and minor specification version. If a partner does not support
7343 * the Revision message, only the major revision will be given.
7344 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
7345 *
7346 * PD revision/version will be 0 if no PD device is connected.
7347 */
7348 uint16_t sop_revision;
7349 uint16_t sop_prime_revision;
7350} __ec_align1;
7351
7352struct ec_response_typec_status_v0 {
7353 struct cros_ec_typec_status typec_status;
7354 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
7355 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
7356} __ec_align1;
7357
7358struct ec_response_typec_status_v1 {
7359 struct cros_ec_typec_status typec_status;
7360 uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */
7361 uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */
7362} __ec_align1;
7363
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007364/**
7365 * Get the number of peripheral charge ports
7366 */
7367#define EC_CMD_PCHG_COUNT 0x0134
7368
7369#define EC_PCHG_MAX_PORTS 8
7370
7371struct ec_response_pchg_count {
7372 uint8_t port_count;
7373} __ec_align1;
7374
7375/**
7376 * Get the status of a peripheral charge port
7377 */
7378#define EC_CMD_PCHG 0x0135
7379
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007380/* For v1 and v2 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007381struct ec_params_pchg {
7382 uint8_t port;
7383} __ec_align1;
7384
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007385struct ec_params_pchg_v3 {
7386 uint8_t port;
7387 /* Below are new in v3. */
7388 uint8_t reserved1;
7389 uint8_t reserved2;
7390 uint8_t reserved3;
7391 /* Errors acked by the host (thus to be cleared) */
7392 uint32_t error;
7393} __ec_align1;
7394
7395/* For v1 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007396struct ec_response_pchg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007397 uint32_t error; /* enum pchg_error */
7398 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007399 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007400 uint8_t unused0;
7401 uint8_t unused1;
7402 /* Fields added in version 1 */
7403 uint32_t fw_version;
7404 uint32_t dropped_event_count;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007405} __ec_align4;
7406
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007407/* For v2 and v3 */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007408struct ec_response_pchg_v2 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007409 uint32_t error; /* enum pchg_error */
7410 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007411 uint8_t battery_percentage;
7412 uint8_t unused0;
7413 uint8_t unused1;
7414 /* Fields added in version 1 */
7415 uint32_t fw_version;
7416 uint32_t dropped_event_count;
7417 /* Fields added in version 2 */
7418 uint32_t dropped_host_event_count;
7419} __ec_align4;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007420
7421enum pchg_state {
7422 /* Charger is reset and not initialized. */
7423 PCHG_STATE_RESET = 0,
7424 /* Charger is initialized or disabled. */
7425 PCHG_STATE_INITIALIZED,
7426 /* Charger is enabled and ready to detect a device. */
7427 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007428 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007429 PCHG_STATE_DETECTED,
7430 /* Device is being charged. */
7431 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007432 /* Device is fully charged. It implies DETECTED (& not charging). */
7433 PCHG_STATE_FULL,
7434 /* In download (a.k.a. firmware update) mode */
7435 PCHG_STATE_DOWNLOAD,
7436 /* In download mode. Ready for receiving data. */
7437 PCHG_STATE_DOWNLOADING,
7438 /* Device is ready for data communication. */
7439 PCHG_STATE_CONNECTED,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007440 /* Charger is in Built-In Self Test mode. */
7441 PCHG_STATE_BIST,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007442 /* Put no more entry below */
7443 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007444};
7445
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007446/* clang-format off */
7447#define EC_PCHG_STATE_TEXT \
7448 { \
7449 [PCHG_STATE_RESET] = "RESET", \
7450 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7451 [PCHG_STATE_ENABLED] = "ENABLED", \
7452 [PCHG_STATE_DETECTED] = "DETECTED", \
7453 [PCHG_STATE_CHARGING] = "CHARGING", \
7454 [PCHG_STATE_FULL] = "FULL", \
7455 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7456 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7457 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7458 [PCHG_STATE_BIST] = "BIST", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007459 }
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007460/* clang-format on */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007461
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007462/**
7463 * Update firmware of peripheral chip
7464 */
7465#define EC_CMD_PCHG_UPDATE 0x0136
7466
7467/* Port number is encoded in bit[28:31]. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007468#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007469/* Utility macros for converting MKBP event <-> port number. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007470#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7471#define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007472/* Utility macro for extracting event bits. */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007473#define EC_MKBP_PCHG_EVENT_MASK(e) \
7474 ((e) & GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007475
Caveh Jalali024ffe32023-01-30 14:35:19 -08007476#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7477#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7478#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7479#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7480#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007481
7482enum ec_pchg_update_cmd {
7483 /* Reset chip to normal mode. */
7484 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7485 /* Reset and put a chip in update (a.k.a. download) mode. */
7486 EC_PCHG_UPDATE_CMD_OPEN,
7487 /* Write a block of data containing FW image. */
7488 EC_PCHG_UPDATE_CMD_WRITE,
7489 /* Close update session. */
7490 EC_PCHG_UPDATE_CMD_CLOSE,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007491 /* Reset chip (without mode change). */
7492 EC_PCHG_UPDATE_CMD_RESET,
7493 /* Enable pass-through mode. */
7494 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007495 /* End of commands */
7496 EC_PCHG_UPDATE_CMD_COUNT,
7497};
7498
7499struct ec_params_pchg_update {
7500 /* PCHG port number */
7501 uint8_t port;
7502 /* enum ec_pchg_update_cmd */
7503 uint8_t cmd;
7504 /* Padding */
7505 uint8_t reserved0;
7506 uint8_t reserved1;
7507 /* Version of new firmware */
7508 uint32_t version;
7509 /* CRC32 of new firmware */
7510 uint32_t crc32;
7511 /* Address in chip memory where <data> is written to */
7512 uint32_t addr;
7513 /* Size of <data> */
7514 uint32_t size;
7515 /* Partial data of new firmware */
7516 uint8_t data[];
7517} __ec_align4;
7518
Caveh Jalali024ffe32023-01-30 14:35:19 -08007519BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7520 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007521
7522struct ec_response_pchg_update {
7523 /* Block size */
7524 uint32_t block_size;
7525} __ec_align4;
7526
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007527#define EC_CMD_DISPLAY_SOC 0x0137
7528
7529struct ec_response_display_soc {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007530 /* Display charge in 10ths of a % (1000=100.0%) */
7531 int16_t display_soc;
7532 /* Full factor in 10ths of a % (1000=100.0%) */
7533 int16_t full_factor;
7534 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7535 int16_t shutdown_soc;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007536} __ec_align2;
7537
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007538#define EC_CMD_SET_BASE_STATE 0x0138
7539
7540struct ec_params_set_base_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007541 uint8_t cmd; /* enum ec_set_base_state_cmd */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007542} __ec_align1;
7543
7544enum ec_set_base_state_cmd {
7545 EC_SET_BASE_STATE_DETACH = 0,
7546 EC_SET_BASE_STATE_ATTACH,
7547 EC_SET_BASE_STATE_RESET,
7548};
7549
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007550#define EC_CMD_I2C_CONTROL 0x0139
7551
7552/* Subcommands for I2C control */
7553
7554enum ec_i2c_control_command {
7555 EC_I2C_CONTROL_GET_SPEED,
7556 EC_I2C_CONTROL_SET_SPEED,
7557};
7558
7559#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7560
7561struct ec_params_i2c_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007562 uint8_t port; /* I2C port number */
7563 uint8_t cmd; /* enum ec_i2c_control_command */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007564 union {
7565 uint16_t speed_khz;
7566 } cmd_params;
7567} __ec_align_size1;
7568
7569struct ec_response_i2c_control {
7570 union {
7571 uint16_t speed_khz;
7572 } cmd_response;
7573} __ec_align_size1;
7574
Caveh Jalali024ffe32023-01-30 14:35:19 -08007575#define EC_CMD_RGBKBD_SET_COLOR 0x013A
7576#define EC_CMD_RGBKBD 0x013B
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007577
Caveh Jalali024ffe32023-01-30 14:35:19 -08007578#define EC_RGBKBD_MAX_KEY_COUNT 128
7579#define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7580#define EC_RGBKBD_MAX_SCALE 0xFF
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007581
7582enum rgbkbd_state {
7583 /* RGB keyboard is reset and not initialized. */
7584 RGBKBD_STATE_RESET = 0,
7585 /* RGB keyboard is initialized but not enabled. */
7586 RGBKBD_STATE_INITIALIZED,
7587 /* RGB keyboard is disabled. */
7588 RGBKBD_STATE_DISABLED,
7589 /* RGB keyboard is enabled and ready to receive a command. */
7590 RGBKBD_STATE_ENABLED,
7591
7592 /* Put no more entry below */
7593 RGBKBD_STATE_COUNT,
7594};
7595
7596enum ec_rgbkbd_subcmd {
7597 EC_RGBKBD_SUBCMD_CLEAR = 1,
7598 EC_RGBKBD_SUBCMD_DEMO = 2,
7599 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007600 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007601 EC_RGBKBD_SUBCMD_COUNT
7602};
7603
7604enum ec_rgbkbd_demo {
7605 EC_RGBKBD_DEMO_OFF = 0,
7606 EC_RGBKBD_DEMO_FLOW = 1,
7607 EC_RGBKBD_DEMO_DOT = 2,
7608 EC_RGBKBD_DEMO_COUNT,
7609};
7610
7611BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7612
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007613enum ec_rgbkbd_type {
7614 EC_RGBKBD_TYPE_UNKNOWN = 0,
7615 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7616 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7617 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7618 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7619 EC_RGBKBD_TYPE_COUNT,
7620};
7621
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007622struct ec_rgbkbd_set_scale {
7623 uint8_t key;
7624 struct rgb_s scale;
7625};
7626
7627struct ec_params_rgbkbd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007628 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007629 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007630 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7631 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007632 struct ec_rgbkbd_set_scale set_scale;
7633 };
7634} __ec_align1;
7635
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007636struct ec_response_rgbkbd {
7637 /*
7638 * RGBKBD type supported by the device.
7639 */
7640
7641 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7642} __ec_align1;
7643
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007644struct ec_params_rgbkbd_set_color {
7645 /* Specifies the starting key ID whose color is being changed. */
7646 uint8_t start_key;
7647 /* Specifies # of elements in <color>. */
7648 uint8_t length;
7649 /* RGB color data array of length up to MAX_KEY_COUNT. */
7650 struct rgb_s color[];
7651} __ec_align1;
7652
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007653/*
7654 * Gather the response to the most recent VDM REQ from the AP, as well
7655 * as popping the oldest VDM:Attention from the DPM queue
7656 */
7657#define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7658
7659struct ec_params_typec_vdm_response {
7660 uint8_t port;
7661} __ec_align1;
7662
7663struct ec_response_typec_vdm_response {
7664 /* Number of 32-bit fields filled in */
7665 uint8_t vdm_data_objects;
7666 /* Partner to address - see enum typec_partner_type */
7667 uint8_t partner_type;
7668 /* enum ec_status describing VDM response */
7669 uint16_t vdm_response_err;
7670 /* VDM data, including VDM header */
7671 uint32_t vdm_response[VDO_MAX_SIZE];
7672 /* Number of 32-bit Attention fields filled in */
7673 uint8_t vdm_attention_objects;
7674 /* Number of remaining messages to consume */
7675 uint8_t vdm_attention_left;
7676 /* Reserved */
7677 uint16_t reserved1;
7678 /* VDM:Attention contents */
7679 uint32_t vdm_attention[2];
7680} __ec_align1;
7681
Simon Glassd3870a22023-11-09 08:43:30 -07007682/*
7683 * Get an active battery config from the EC.
7684 */
7685#define EC_CMD_BATTERY_CONFIG 0x013D
7686
7687/* Version of struct batt_conf_header and its internals. */
7688#define EC_BATTERY_CONFIG_STRUCT_VERSION 0x00
7689
7690/* Number of writes needed to invoke battery cutoff command */
7691#define SHIP_MODE_WRITES 2
7692
7693struct ship_mode_info {
7694 uint8_t reg_addr;
7695 uint8_t reserved;
7696 uint16_t reg_data[SHIP_MODE_WRITES];
7697} __packed __aligned(2);
7698
7699struct sleep_mode_info {
7700 uint8_t reg_addr;
7701 uint8_t reserved;
7702 uint16_t reg_data;
7703} __packed __aligned(2);
7704
7705struct fet_info {
7706 uint8_t reg_addr;
7707 uint8_t reserved;
7708 uint16_t reg_mask;
7709 uint16_t disconnect_val;
7710 uint16_t cfet_mask; /* CHG FET status mask */
7711 uint16_t cfet_off_val;
7712} __packed __aligned(2);
7713
7714enum fuel_gauge_flags {
7715 /*
7716 * Write Block Support. If enabled, we use a i2c write block command
7717 * instead of a 16-bit write. The effective difference is the i2c
7718 * transaction will prefix the length (2).
7719 */
7720 FUEL_GAUGE_FLAG_WRITE_BLOCK = BIT(0),
7721 /* Sleep command support. fuel_gauge_info.sleep_mode must be defined. */
7722 FUEL_GAUGE_FLAG_SLEEP_MODE = BIT(1),
7723 /*
7724 * Manufacturer access command support. If enabled, FET status is read
7725 * from the OperationStatus (0x54) register using the
7726 * ManufacturerBlockAccess (0x44).
7727 */
7728 FUEL_GAUGE_FLAG_MFGACC = BIT(2),
7729 /*
7730 * SMB block protocol support in manufacturer access command. If
7731 * enabled, FET status is read from the OperationStatus (0x54) register
7732 * using the ManufacturerBlockAccess (0x44).
7733 */
7734 FUEL_GAUGE_FLAG_MFGACC_SMB_BLOCK = BIT(3),
7735};
7736
7737struct fuel_gauge_info {
7738 uint32_t flags;
7739 uint32_t board_flags;
7740 struct ship_mode_info ship_mode;
7741 struct sleep_mode_info sleep_mode;
7742 struct fet_info fet;
7743} __packed __aligned(4);
7744
7745/* Battery constants */
7746struct battery_info {
7747 /* Operation voltage in mV */
7748 uint16_t voltage_max;
7749 uint16_t voltage_normal;
7750 uint16_t voltage_min;
7751 /* (TODO(chromium:756700): add desired_charging_current */
7752 /**
7753 * Pre-charge to fast charge threshold in mV,
7754 * default to voltage_min if not specified.
7755 * This option is only available on isl923x and rt946x.
7756 */
7757 uint16_t precharge_voltage;
7758 /* Pre-charge current in mA */
7759 uint16_t precharge_current;
7760 /* Working temperature ranges in degrees C */
7761 int8_t start_charging_min_c;
7762 int8_t start_charging_max_c;
7763 int8_t charging_min_c;
7764 int8_t charging_max_c;
7765 int8_t discharging_min_c;
7766 int8_t discharging_max_c;
7767 /* Used only if CONFIG_BATTERY_VENDOR_PARAM is defined. */
7768 uint8_t vendor_param_start;
7769 uint8_t reserved;
7770} __packed __aligned(2);
7771
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007772/*
Simon Glassd3870a22023-11-09 08:43:30 -07007773 * The 'config' of a battery.
7774 */
7775struct board_batt_params {
7776 struct fuel_gauge_info fuel_gauge;
7777 struct battery_info batt_info;
7778} __packed __aligned(4);
7779
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007780/*
7781 * The SBS defines a string object as a block of chars, 32 byte maximum, where
7782 * the first byte indicates the number of chars in the block (excluding the
7783 * first byte).
7784 *
7785 * Thus, the actual string length (i.e. the value strlen returns) is limited to
7786 * 31 (=SBS_MAX_STR_SIZE).
7787 *
7788 * SBS_MAX_STR_OBJ_SIZE can be used as the size of a buffer for an SBS string
7789 * object but also as a buffer for a c-lang string because the null terminating
7790 * char also takes one byte.
7791 */
7792#define SBS_MAX_STR_SIZE 31
7793#define SBS_MAX_STR_OBJ_SIZE (SBS_MAX_STR_SIZE + 1)
Simon Glassd3870a22023-11-09 08:43:30 -07007794
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007795/*
Simon Glassd3870a22023-11-09 08:43:30 -07007796 * Header describing a battery config stored in CBI. Only struct_version has
7797 * size and position independent of struct_version. The rest varies as
7798 * struct_version changes.
7799 *
7800 * Version 0
7801 * Layout:
7802 * +-------------+
7803 * | header |
7804 * +-------------+
7805 * | | ^
7806 * | manuf_name | | manuf_name_size
7807 * | | v
7808 * +-------------+
7809 * | device_name | ^
7810 * | | | device_name_size
7811 * | | v
7812 * +-------------+
7813 * | config | ^
7814 * | | |
7815 * | | | cbi data size
7816 * | | | - (header_size+manuf_name_size+device_name_size)
7817 * | | |
7818 * | | v
7819 * +-------------+
7820 * Note:
7821 * - manuf_name and device_name are not null-terminated.
7822 * - The config isn't aligned. It should be copied to struct board_batt_params
7823 * before its contents are accessed.
7824 */
7825struct batt_conf_header {
7826 /* Version independent field. It's always here as a uint8_t. */
7827 uint8_t struct_version;
7828 /* Version 0 members */
7829 uint8_t manuf_name_size;
7830 uint8_t device_name_size;
7831 uint8_t reserved;
7832 /* manuf_name, device_name, board_batt_params follow after this. */
7833} __packed;
7834
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007835#define BATT_CONF_MAX_SIZE \
7836 (sizeof(struct batt_conf_header) + SBS_MAX_STR_OBJ_SIZE * 2 + \
Simon Glassd3870a22023-11-09 08:43:30 -07007837 sizeof(struct board_batt_params))
7838
7839/*
7840 * Record the current AP firmware state. This is used to help testing, such as
7841 * with FAFT (Fully-Automated Firmware Test), which likes to know which firmware
7842 * screen is currently displayed.
7843 */
7844
7845#define EC_CMD_AP_FW_STATE 0x013E
7846
7847struct ec_params_ap_fw_state {
7848 /*
7849 * Value which indicates the state. This is not decoded by the EC, so
7850 * its meaning is entirely outside this code base.
7851 */
7852 uint32_t state;
7853} __ec_align1;
7854
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007855/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007856/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007857
7858/*****************************************************************************/
7859/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007860 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007861 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007862#define EC_CMD_CR51_BASE 0x0300
7863#define EC_CMD_CR51_LAST 0x03FF
7864
7865/*****************************************************************************/
7866/* Fingerprint MCU commands: range 0x0400-0x040x */
7867
Simon Glassd3870a22023-11-09 08:43:30 -07007868/*
7869 * Fingerprint SPI sensor passthru command
7870 *
7871 * This command was used for prototyping and it's now deprecated.
7872 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007873#define EC_CMD_FP_PASSTHRU 0x0400
7874
7875#define EC_FP_FLAG_NOT_COMPLETE 0x1
7876
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007877struct ec_params_fp_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007878 uint16_t len; /* Number of bytes to write then read */
7879 uint16_t flags; /* EC_FP_FLAG_xxx */
7880 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007881} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007882
7883/* Configure the Fingerprint MCU behavior */
7884#define EC_CMD_FP_MODE 0x0402
7885
7886/* Put the sensor in its lowest power mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007887#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007888/* Wait to see a finger on the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007889#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007890/* Poll until the finger has left the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007891#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007892/* Capture the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007893#define FP_MODE_CAPTURE BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007894/* Finger enrollment session on-going */
7895#define FP_MODE_ENROLL_SESSION BIT(4)
7896/* Enroll the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007897#define FP_MODE_ENROLL_IMAGE BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007898/* Try to match the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007899#define FP_MODE_MATCH BIT(6)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007900/* Reset and re-initialize the sensor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007901#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007902/* Sensor maintenance for dead pixels. */
7903#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007904/* special value: don't change anything just read back current mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007905#define FP_MODE_DONT_CHANGE BIT(31)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007906
Caveh Jalali024ffe32023-01-30 14:35:19 -08007907#define FP_VALID_MODES \
7908 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
7909 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
7910 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
7911 FP_MODE_DONT_CHANGE)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007912
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007913/* Capture types defined in bits [30..28] */
7914#define FP_MODE_CAPTURE_TYPE_SHIFT 28
Caveh Jalali024ffe32023-01-30 14:35:19 -08007915#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007916/**
7917 * enum fp_capture_type - Specifies the "mode" when capturing images.
7918 *
7919 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
7920 * image (produces 'frame_size' bytes)
7921 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
7922 * bpp bits)
7923 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
7924 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
7925 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
7926 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
7927 * @FP_CAPTURE_TYPE_MAX: End of enum
7928 *
7929 * @note This enum must remain ordered, if you add new values you must ensure
7930 * that FP_CAPTURE_TYPE_MAX is still the last one.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007931 */
7932enum fp_capture_type {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007933 FP_CAPTURE_VENDOR_FORMAT = 0,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007934 FP_CAPTURE_SIMPLE_IMAGE = 1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007935 FP_CAPTURE_PATTERN0 = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007936 FP_CAPTURE_PATTERN1 = 3,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007937 FP_CAPTURE_QUALITY_TEST = 4,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007938 FP_CAPTURE_RESET_TEST = 5,
7939 FP_CAPTURE_TYPE_MAX,
7940};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007941/* Extracts the capture type from the sensor 'mode' word */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007942#define FP_CAPTURE_TYPE(mode) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007943 (((mode) & FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007944
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007945struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007946 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007947} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007948
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007949struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007950 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007951} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007952
7953/* Retrieve Fingerprint sensor information */
7954#define EC_CMD_FP_INFO 0x0403
7955
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007956/* Number of dead pixels detected on the last maintenance */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007957#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007958/* Unknown number of dead pixels detected on the last maintenance */
7959#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007960/* No interrupt from the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007961#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007962/* SPI communication error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007963#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007964/* Invalid sensor Hardware ID */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007965#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007966/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007967#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007968
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007969struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007970 /* Sensor identification */
7971 uint32_t vendor_id;
7972 uint32_t product_id;
7973 uint32_t model_id;
7974 uint32_t version;
7975 /* Image frame characteristics */
7976 uint32_t frame_size;
7977 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7978 uint16_t width;
7979 uint16_t height;
7980 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007981 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007982} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007983
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007984struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007985 /* Sensor identification */
7986 uint32_t vendor_id;
7987 uint32_t product_id;
7988 uint32_t model_id;
7989 uint32_t version;
7990 /* Image frame characteristics */
7991 uint32_t frame_size;
7992 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7993 uint16_t width;
7994 uint16_t height;
7995 uint16_t bpp;
7996 uint16_t errors; /* see FP_ERROR_ flags above */
7997 /* Template/finger current information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007998 uint32_t template_size; /* max template size in bytes */
7999 uint16_t template_max; /* maximum number of fingers/templates */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008000 uint16_t template_valid; /* number of valid fingers/templates */
8001 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008002 uint32_t template_version; /* version of the template format */
8003} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008004
8005/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008006#define EC_CMD_FP_FRAME 0x0404
8007
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008008/* constants defining the 'offset' field which also contains the frame index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008009#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008010/* Frame buffer where the captured image is stored */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008011#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008012/* First frame buffer holding a template */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008013#define FP_FRAME_INDEX_TEMPLATE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008014#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08008015#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008016
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008017/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07008018#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008019
8020/* Constants for encryption parameters */
8021#define FP_CONTEXT_NONCE_BYTES 12
8022#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
8023#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07008024#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008025#define FP_CONTEXT_TPM_BYTES 32
8026
Jett Rinkba2edaf2020-01-14 11:49:06 -07008027/* Constants for positive match parameters. */
8028#define FP_POSITIVE_MATCH_SALT_BYTES 16
8029
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008030struct ec_fp_template_encryption_metadata {
8031 /*
8032 * Version of the structure format (N=3).
8033 */
8034 uint16_t struct_version;
8035 /* Reserved bytes, set to 0. */
8036 uint16_t reserved;
8037 /*
8038 * The salt is *only* ever used for key derivation. The nonce is unique,
8039 * a different one is used for every message.
8040 */
8041 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07008042 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008043 uint8_t tag[FP_CONTEXT_TAG_BYTES];
8044};
8045
8046struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008047 /*
8048 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
8049 * in the high nibble, and the real offset within the frame in
8050 * FP_FRAME_OFFSET_MASK.
8051 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008052 uint32_t offset;
8053 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008054} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008055
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008056/* Load a template into the MCU */
8057#define EC_CMD_FP_TEMPLATE 0x0405
8058
8059/* Flag in the 'size' field indicating that the full template has been sent */
8060#define FP_TEMPLATE_COMMIT 0x80000000
8061
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008062struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008063 uint32_t offset;
8064 uint32_t size;
8065 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008066} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008067
8068/* Clear the current fingerprint user context and set a new one */
8069#define EC_CMD_FP_CONTEXT 0x0406
8070
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008071struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008072 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008073} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008074
Jett Rinkba2edaf2020-01-14 11:49:06 -07008075enum fp_context_action {
8076 FP_CONTEXT_ASYNC = 0,
8077 FP_CONTEXT_GET_RESULT = 1,
8078};
8079
8080/* Version 1 of the command is "asynchronous". */
8081struct ec_params_fp_context_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08008082 uint8_t action; /**< enum fp_context_action */
8083 uint8_t reserved[3]; /**< padding for alignment */
Jett Rinkba2edaf2020-01-14 11:49:06 -07008084 uint32_t userid[FP_CONTEXT_USERID_WORDS];
8085} __ec_align4;
8086
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008087#define EC_CMD_FP_STATS 0x0407
8088
Caveh Jalali024ffe32023-01-30 14:35:19 -08008089#define FPSTATS_CAPTURE_INV BIT(0)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008090#define FPSTATS_MATCHING_INV BIT(1)
8091
8092struct ec_response_fp_stats {
8093 uint32_t capture_time_us;
8094 uint32_t matching_time_us;
8095 uint32_t overall_time_us;
8096 struct {
8097 uint32_t lo;
8098 uint32_t hi;
8099 } overall_t0;
8100 uint8_t timestamps_invalid;
8101 int8_t template_matched;
8102} __ec_align2;
8103
8104#define EC_CMD_FP_SEED 0x0408
8105struct ec_params_fp_seed {
8106 /*
8107 * Version of the structure format (N=3).
8108 */
8109 uint16_t struct_version;
8110 /* Reserved bytes, set to 0. */
8111 uint16_t reserved;
8112 /* Seed from the TPM. */
8113 uint8_t seed[FP_CONTEXT_TPM_BYTES];
8114} __ec_align4;
8115
8116#define EC_CMD_FP_ENC_STATUS 0x0409
8117
8118/* FP TPM seed has been set or not */
8119#define FP_ENC_STATUS_SEED_SET BIT(0)
Simon Glassd3870a22023-11-09 08:43:30 -07008120/* FP using nonce context or not */
8121#define FP_CONTEXT_STATUS_NONCE_CONTEXT_SET BIT(1)
8122/* FP match had been processed or not */
8123#define FP_CONTEXT_STATUS_MATCH_PROCESSED_SET BIT(2)
8124/* FP auth_nonce had been set or not*/
8125#define FP_CONTEXT_AUTH_NONCE_SET BIT(3)
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008126/* FP user_id had been set or not*/
8127#define FP_CONTEXT_USER_ID_SET BIT(4)
8128/* FP templates are unlocked for nonce context or not */
8129#define FP_CONTEXT_TEMPLATE_UNLOCKED_SET BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008130
8131struct ec_response_fp_encryption_status {
8132 /* Used bits in encryption engine status */
8133 uint32_t valid_flags;
8134 /* Encryption engine status */
8135 uint32_t status;
8136} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008137
Jett Rinkba2edaf2020-01-14 11:49:06 -07008138#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
8139struct ec_params_fp_read_match_secret {
8140 uint16_t fgr;
8141} __ec_align4;
8142
8143/* The positive match secret has the length of the SHA256 digest. */
8144#define FP_POSITIVE_MATCH_SECRET_BYTES 32
8145struct ec_response_fp_read_match_secret {
8146 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8147} __ec_align4;
8148
Simon Glassd3870a22023-11-09 08:43:30 -07008149#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN 32
8150
8151struct fp_elliptic_curve_public_key {
8152 uint8_t x[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8153 uint8_t y[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8154} __ec_align4;
8155
8156#define FP_AES_KEY_ENC_METADATA_VERSION 1
8157#define FP_AES_KEY_NONCE_BYTES 12
8158#define FP_AES_KEY_ENCRYPTION_SALT_BYTES 16
8159#define FP_AES_KEY_TAG_BYTES 16
8160
8161struct fp_auth_command_encryption_metadata {
8162 /* Version of the structure format */
8163 uint16_t struct_version;
8164 /* Reserved bytes, set to 0. */
8165 uint16_t reserved;
8166 /*
8167 * The salt is *only* ever used for key derivation. The nonce is unique,
8168 * a different one is used for every message.
8169 */
8170 uint8_t nonce[FP_AES_KEY_NONCE_BYTES];
8171 uint8_t encryption_salt[FP_AES_KEY_ENCRYPTION_SALT_BYTES];
8172 uint8_t tag[FP_AES_KEY_TAG_BYTES];
8173} __ec_align4;
8174
8175#define FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN 32
8176#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8177
8178struct fp_encrypted_private_key {
8179 struct fp_auth_command_encryption_metadata info;
8180 uint8_t data[FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN];
8181} __ec_align4;
8182
8183#define EC_CMD_FP_ESTABLISH_PAIRING_KEY_KEYGEN 0x0410
8184
8185struct ec_response_fp_establish_pairing_key_keygen {
8186 struct fp_elliptic_curve_public_key pubkey;
8187 struct fp_encrypted_private_key encrypted_private_key;
8188} __ec_align4;
8189
8190#define FP_PAIRING_KEY_LEN 32
8191
8192struct ec_fp_encrypted_pairing_key {
8193 struct fp_auth_command_encryption_metadata info;
8194 uint8_t data[FP_PAIRING_KEY_LEN];
8195} __ec_align4;
8196
8197#define EC_CMD_FP_ESTABLISH_PAIRING_KEY_WRAP 0x0411
8198
8199struct ec_params_fp_establish_pairing_key_wrap {
8200 struct fp_elliptic_curve_public_key peers_pubkey;
8201 struct fp_encrypted_private_key encrypted_private_key;
8202} __ec_align4;
8203
8204struct ec_response_fp_establish_pairing_key_wrap {
8205 struct ec_fp_encrypted_pairing_key encrypted_pairing_key;
8206} __ec_align4;
8207
8208#define EC_CMD_FP_LOAD_PAIRING_KEY 0x0412
8209
8210typedef struct ec_response_fp_establish_pairing_key_wrap
8211 ec_params_fp_load_pairing_key;
8212
8213#define FP_CK_AUTH_NONCE_LEN 32
8214
8215#define EC_CMD_FP_GENERATE_NONCE 0x0413
8216struct ec_response_fp_generate_nonce {
8217 uint8_t nonce[FP_CK_AUTH_NONCE_LEN];
8218} __ec_align4;
8219
8220#define FP_CONTEXT_USERID_LEN 32
8221#define FP_CONTEXT_USERID_IV_LEN 16
8222#define FP_CONTEXT_KEY_LEN 32
8223
8224#define EC_CMD_FP_NONCE_CONTEXT 0x0414
8225struct ec_params_fp_nonce_context {
8226 uint8_t gsc_nonce[FP_CK_AUTH_NONCE_LEN];
8227 uint8_t enc_user_id[FP_CONTEXT_USERID_LEN];
8228 uint8_t enc_user_id_iv[FP_CONTEXT_USERID_IV_LEN];
8229} __ec_align4;
8230
8231#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8232
8233#define EC_CMD_FP_READ_MATCH_SECRET_WITH_PUBKEY 0x0415
8234
8235struct ec_params_fp_read_match_secret_with_pubkey {
8236 uint16_t fgr;
8237 uint16_t reserved;
8238 struct fp_elliptic_curve_public_key pubkey;
8239} __ec_align4;
8240
8241struct ec_response_fp_read_match_secret_with_pubkey {
8242 struct fp_elliptic_curve_public_key pubkey;
8243 uint8_t iv[FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN];
8244 uint8_t enc_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8245} __ec_align4;
8246
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008247/* Unlock the fpsensor template with the current nonce context */
8248#define EC_CMD_FP_UNLOCK_TEMPLATE 0x0417
Simon Glassd3870a22023-11-09 08:43:30 -07008249
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008250struct ec_params_fp_unlock_template {
8251 uint16_t fgr_num;
Simon Glassd3870a22023-11-09 08:43:30 -07008252} __ec_align4;
8253
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008254/*****************************************************************************/
8255/* Touchpad MCU commands: range 0x0500-0x05FF */
8256
8257/* Perform touchpad self test */
8258#define EC_CMD_TP_SELF_TEST 0x0500
8259
8260/* Get number of frame types, and the size of each type */
8261#define EC_CMD_TP_FRAME_INFO 0x0501
8262
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008263struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008264 uint32_t n_frames;
8265 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008266} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008267
8268/* Create a snapshot of current frame readings */
8269#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
8270
8271/* Read the frame */
8272#define EC_CMD_TP_FRAME_GET 0x0503
8273
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008274struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008275 uint32_t frame_index;
8276 uint32_t offset;
8277 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008278} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08008279
8280/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008281/* EC-EC communication commands: range 0x0600-0x06FF */
8282
8283#define EC_COMM_TEXT_MAX 8
8284
8285/*
8286 * Get battery static information, i.e. information that never changes, or
8287 * very infrequently.
8288 */
8289#define EC_CMD_BATTERY_GET_STATIC 0x0600
8290
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008291/**
8292 * struct ec_params_battery_static_info - Battery static info parameters
8293 * @index: Battery index.
8294 */
8295struct ec_params_battery_static_info {
8296 uint8_t index;
8297} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008298
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008299/**
8300 * struct ec_response_battery_static_info - Battery static info response
8301 * @design_capacity: Battery Design Capacity (mAh)
8302 * @design_voltage: Battery Design Voltage (mV)
8303 * @manufacturer: Battery Manufacturer String
8304 * @model: Battery Model Number String
8305 * @serial: Battery Serial Number String
8306 * @type: Battery Type String
8307 * @cycle_count: Battery Cycle Count
8308 */
8309struct ec_response_battery_static_info {
8310 uint16_t design_capacity;
8311 uint16_t design_voltage;
8312 char manufacturer[EC_COMM_TEXT_MAX];
8313 char model[EC_COMM_TEXT_MAX];
8314 char serial[EC_COMM_TEXT_MAX];
8315 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008316 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008317 uint32_t cycle_count;
8318} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008319
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08008320/**
8321 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
8322 * Equivalent to struct ec_response_battery_static_info, but with longer
8323 * strings.
8324 * @design_capacity: battery design capacity (in mAh)
8325 * @design_voltage: battery design voltage (in mV)
8326 * @cycle_count: battery cycle count
8327 * @manufacturer_ext: battery manufacturer string
8328 * @model_ext: battery model string
8329 * @serial_ext: battery serial number string
8330 * @type_ext: battery type string
8331 */
8332struct ec_response_battery_static_info_v1 {
8333 uint16_t design_capacity;
8334 uint16_t design_voltage;
8335 uint32_t cycle_count;
8336 char manufacturer_ext[12];
8337 char model_ext[12];
8338 char serial_ext[12];
8339 char type_ext[12];
8340} __ec_align4;
8341
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008342/**
8343 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
8344 *
8345 * Equivalent to struct ec_response_battery_static_info, but with strings
8346 * further lengthened (relative to v1) to accommodate the maximum string length
8347 * permitted by the Smart Battery Data Specification revision 1.1 and fields
8348 * renamed to better match that specification.
8349 *
8350 * @design_capacity: battery design capacity (in mAh)
8351 * @design_voltage: battery design voltage (in mV)
8352 * @cycle_count: battery cycle count
8353 * @manufacturer: battery manufacturer string
8354 * @device_name: battery model string
8355 * @serial: battery serial number string
8356 * @chemistry: battery type string
8357 */
8358struct ec_response_battery_static_info_v2 {
8359 uint16_t design_capacity;
8360 uint16_t design_voltage;
8361 uint32_t cycle_count;
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008362 char manufacturer[SBS_MAX_STR_OBJ_SIZE];
8363 char device_name[SBS_MAX_STR_OBJ_SIZE];
8364 char serial[SBS_MAX_STR_OBJ_SIZE];
8365 char chemistry[SBS_MAX_STR_OBJ_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008366} __ec_align4;
8367
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008368/*
8369 * Get battery dynamic information, i.e. information that is likely to change
8370 * every time it is read.
8371 */
8372#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
8373
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008374/**
8375 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
8376 * @index: Battery index.
8377 */
8378struct ec_params_battery_dynamic_info {
8379 uint8_t index;
8380} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008381
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008382/**
8383 * struct ec_response_battery_dynamic_info - Battery dynamic info response
8384 * @actual_voltage: Battery voltage (mV)
8385 * @actual_current: Battery current (mA); negative=discharging
8386 * @remaining_capacity: Remaining capacity (mAh)
8387 * @full_capacity: Capacity (mAh, might change occasionally)
8388 * @flags: Flags, see EC_BATT_FLAG_*
8389 * @desired_voltage: Charging voltage desired by battery (mV)
8390 * @desired_current: Charging current desired by battery (mA)
8391 */
8392struct ec_response_battery_dynamic_info {
8393 int16_t actual_voltage;
8394 int16_t actual_current;
8395 int16_t remaining_capacity;
8396 int16_t full_capacity;
8397 int16_t flags;
8398 int16_t desired_voltage;
8399 int16_t desired_current;
8400} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008401
8402/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06008403 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008404 */
8405#define EC_CMD_CHARGER_CONTROL 0x0602
8406
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008407/**
8408 * struct ec_params_charger_control - Charger control parameters
8409 * @max_current: Charger current (mA). Positive to allow base to draw up to
8410 * max_current and (possibly) charge battery, negative to request current
8411 * from base (OTG).
8412 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
8413 * >= 0.
8414 * @allow_charging: Allow base battery charging (only makes sense if
8415 * max_current > 0).
8416 */
8417struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008418 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008419 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008420 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008421} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008422
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08008423/* Get ACK from the USB-C SS muxes */
8424#define EC_CMD_USB_PD_MUX_ACK 0x0603
8425
8426struct ec_params_usb_pd_mux_ack {
8427 uint8_t port; /* USB-C port number */
8428} __ec_align1;
8429
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008430/* Get boot time */
8431#define EC_CMD_GET_BOOT_TIME 0x0604
8432
8433enum boot_time_param {
8434 ARAIL = 0,
8435 RSMRST,
8436 ESPIRST,
8437 PLTRST_LOW,
8438 PLTRST_HIGH,
8439 EC_CUR_TIME,
8440 RESET_CNT,
8441};
8442
8443struct ec_response_get_boot_time {
8444 uint64_t timestamp[RESET_CNT];
8445 uint16_t cnt;
8446} __ec_align4;
8447
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008448/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08008449/*
8450 * Reserve a range of host commands for board-specific, experimental, or
8451 * special purpose features. These can be (re)used without updating this file.
8452 *
8453 * CAUTION: Don't go nuts with this. Shipping products should document ALL
8454 * their EC commands for easier development, testing, debugging, and support.
8455 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008456 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
8457 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
8458 *
Duncan Laurieeb316852015-12-01 18:51:18 -08008459 * In your experimental code, you may want to do something like this:
8460 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008461 * #define EC_CMD_MAGIC_FOO 0x0000
8462 * #define EC_CMD_MAGIC_BAR 0x0001
8463 * #define EC_CMD_MAGIC_HEY 0x0002
8464 *
8465 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
8466 * EC_VER_MASK(0);
8467 *
8468 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
8469 * EC_VER_MASK(0);
8470 *
8471 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
8472 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08008473 */
8474#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
8475#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
8476
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008477/*
8478 * Given the private host command offset, calculate the true private host
8479 * command value.
8480 */
8481#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
8482 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
8483
Duncan Laurie93e24442014-01-06 12:30:52 -08008484/*****************************************************************************/
8485/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07008486 * Passthru commands
8487 *
8488 * Some platforms have sub-processors chained to each other. For example.
8489 *
8490 * AP <--> EC <--> PD MCU
8491 *
8492 * The top 2 bits of the command number are used to indicate which device the
8493 * command is intended for. Device 0 is always the device receiving the
8494 * command; other device mapping is board-specific.
8495 *
8496 * When a device receives a command to be passed to a sub-processor, it passes
8497 * it on with the device number set back to 0. This allows the sub-processor
8498 * to remain blissfully unaware of whether the command originated on the next
8499 * device up the chain, or was passed through from the AP.
8500 *
8501 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
8502 * AP sends command 0x4002 to the EC
8503 * EC sends command 0x0002 to the PD MCU
8504 * EC forwards PD MCU response back to the AP
8505 */
8506
8507/* Offset and max command number for sub-device n */
8508#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
8509#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
8510
8511/*****************************************************************************/
8512/*
Duncan Laurie93e24442014-01-06 12:30:52 -08008513 * Deprecated constants. These constants have been renamed for clarity. The
8514 * meaning and size has not changed. Programs that use the old names should
8515 * switch to the new names soon, as the old names may not be carried forward
8516 * forever.
8517 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008518#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
8519#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
8520#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
Duncan Laurie93e24442014-01-06 12:30:52 -08008521
Caveh Jalali024ffe32023-01-30 14:35:19 -08008522#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008523
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008524#ifdef __cplusplus
8525}
8526#endif
8527
Caveh Jalali024ffe32023-01-30 14:35:19 -08008528#endif /* __CROS_EC_EC_COMMANDS_H */