blob: 1673c8b362e2e4f297dc2611341b598e9c6d1d91 [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,
Pavan Holla8d6625a2024-04-18 14:19:51 +00001700 /*
1701 * The EC supports UCSI PPM.
1702 */
1703 EC_FEATURE_UCSI_PPM = 54,
Duncan Laurieeb316852015-12-01 18:51:18 -08001704};
1705
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001706#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1707#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1708
1709struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001710 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001711} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001712
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001713/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001714/* Get the board's SKU ID from EC */
1715#define EC_CMD_GET_SKU_ID 0x000E
1716
Kevin Chiue2bb0592017-09-12 09:13:41 +08001717/* Set SKU ID from AP */
1718#define EC_CMD_SET_SKU_ID 0x000F
1719
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001720struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001721 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001722} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001723
1724/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001725/* Flash commands */
1726
1727/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001728#define EC_CMD_FLASH_INFO 0x0010
1729#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001731/**
1732 * struct ec_response_flash_info - Response to the flash info command.
1733 * @flash_size: Usable flash size in bytes.
1734 * @write_block_size: Write block size. Write offset and size must be a
1735 * multiple of this.
1736 * @erase_block_size: Erase block size. Erase offset and size must be a
1737 * multiple of this.
1738 * @protect_block_size: Protection block size. Protection offset and size
1739 * must be a multiple of this.
1740 *
1741 * Version 0 returns these fields.
1742 */
1743struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001744 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001745 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001746 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001747 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001748} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001749
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001750/*
1751 * Flags for version 1+ flash info command
1752 * EC flash erases bits to 0 instead of 1.
1753 */
1754#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001755
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001756/*
1757 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001758 * be necessary on a chip where write/erase can be corrupted by other board
1759 * activity, or where the chip needs to enable some sort of programming voltage,
1760 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001761 * chip functionality.
1762 */
1763#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001764
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001765/**
1766 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1767 * @flash_size: Usable flash size in bytes.
1768 * @write_block_size: Write block size. Write offset and size must be a
1769 * multiple of this.
1770 * @erase_block_size: Erase block size. Erase offset and size must be a
1771 * multiple of this.
1772 * @protect_block_size: Protection block size. Protection offset and size
1773 * must be a multiple of this.
1774 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1775 * size is exactly this and offset is a multiple of this.
1776 * For example, an EC may have a write buffer which can do
1777 * half-page operations if data is aligned, and a slower
1778 * word-at-a-time write mode.
1779 * @flags: Flags; see EC_FLASH_INFO_*
1780 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001781 * Version 1 returns the same initial fields as version 0, with additional
1782 * fields following.
1783 *
1784 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001785 * if they did we'd define the version 0 structure as a sub-structure of this
1786 * one.
1787 *
1788 * Version 2 supports flash banks of different sizes:
1789 * The caller specified the number of banks it has preallocated
1790 * (num_banks_desc)
1791 * The EC returns the number of banks describing the flash memory.
1792 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001793 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001794struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001795 /* Version 0 fields; see above for description */
1796 uint32_t flash_size;
1797 uint32_t write_block_size;
1798 uint32_t erase_block_size;
1799 uint32_t protect_block_size;
1800
1801 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001802 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001803 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001804} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001805
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001806struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001807 /* Number of banks to describe */
1808 uint16_t num_banks_desc;
1809 /* Reserved; set 0; ignore on read */
1810 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001811} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001812
1813struct ec_flash_bank {
1814 /* Number of sector is in this bank. */
1815 uint16_t count;
1816 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1817 uint8_t size_exp;
1818 /* Minimal write size for the sectors in this bank */
1819 uint8_t write_size_exp;
1820 /* Erase size for the sectors in this bank */
1821 uint8_t erase_size_exp;
1822 /* Size for write protection, usually identical to erase size. */
1823 uint8_t protect_size_exp;
1824 /* Reserved; set 0; ignore on read */
1825 uint8_t reserved[2];
1826};
1827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001828struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001829 /* Total flash in the EC. */
1830 uint32_t flash_size;
1831 /* Flags; see EC_FLASH_INFO_* */
1832 uint32_t flags;
1833 /* Maximum size to use to send data to write to the EC. */
1834 uint32_t write_ideal_size;
1835 /* Number of banks present in the EC. */
1836 uint16_t num_banks_total;
1837 /* Number of banks described in banks array. */
1838 uint16_t num_banks_desc;
1839 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001840} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001841
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001842/*
1843 * Read flash
1844 *
1845 * Response is params.size bytes of data.
1846 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001847#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001848
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001849/**
1850 * struct ec_params_flash_read - Parameters for the flash read command.
1851 * @offset: Byte offset to read.
1852 * @size: Size to read in bytes.
1853 */
1854struct ec_params_flash_read {
1855 uint32_t offset;
1856 uint32_t size;
1857} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001858
1859/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001860#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001861#define EC_VER_FLASH_WRITE 1
1862
1863/* Version 0 of the flash command supported only 64 bytes of data */
1864#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001865
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001866/**
1867 * struct ec_params_flash_write - Parameters for the flash write command.
1868 * @offset: Byte offset to write.
1869 * @size: Size to write in bytes.
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001870 * @data: Data to write.
1871 * @data.words32: uint32_t data to write.
1872 * @data.bytes: uint8_t data to write.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001873 */
1874struct ec_params_flash_write {
1875 uint32_t offset;
1876 uint32_t size;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001877 /* Followed by data to write. This union allows accessing an
1878 * underlying buffer as uint32s or uint8s for convenience.
1879 */
1880 union {
1881 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1882 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1883 } data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001884} __ec_align4;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001885BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001886
1887/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001888#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001889
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001890/**
1891 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1892 * @offset: Byte offset to erase.
1893 * @size: Size to erase in bytes.
1894 */
1895struct ec_params_flash_erase {
1896 uint32_t offset;
1897 uint32_t size;
1898} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001900/*
1901 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001902 * subcommands can returns:
1903 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1904 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1905 * EC_RES_ERROR : other errors.
1906 * EC_RES_BUSY : an existing erase operation is in progress.
1907 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1908 *
1909 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1910 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1911 * the proper result.
1912 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1913 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1914 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1915 * permitted while erasing. (For instance, STM32F4).
1916 */
1917enum ec_flash_erase_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001918 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1919 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1920 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001921};
1922
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001923/**
1924 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1925 * @cmd: One of ec_flash_erase_cmd.
1926 * @reserved: Pad byte; currently always contains 0.
1927 * @flag: No flags defined yet; set to 0.
1928 * @params: Same as v0 parameters.
1929 */
1930struct ec_params_flash_erase_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001931 uint8_t cmd;
1932 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001933 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001934 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001935} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001936
1937/*
1938 * Get/set flash protection.
1939 *
1940 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1941 * firmware write protect GPIO, not all flags will take effect immediately;
1942 * some flags require a subsequent hard reset to take effect. Check the
1943 * returned flags bits to see what actually happened.
1944 *
1945 * If mask=0, simply returns the current flags state.
1946 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001947#define EC_CMD_FLASH_PROTECT 0x0015
Caveh Jalali024ffe32023-01-30 14:35:19 -08001948#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001949
1950/* Flags for flash protection */
1951/* RO flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001952#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001953/*
1954 * RO flash code protected now. If this bit is set, at-boot status cannot
1955 * be changed.
1956 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001957#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001958/* Entire flash code protected now, until reboot. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001959#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001960/* Flash write protect GPIO is asserted now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001961#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001962/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001963#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001964/*
1965 * Error - flash protection is in inconsistent state. At least one bank of
1966 * flash which should be protected is not protected. Usually fixed by
1967 * re-requesting the desired flags, or by a hard reset if that fails.
1968 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001969#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001970/* Entire flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001971#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001972/* RW flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001973#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001974/* RW flash code protected now. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001975#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001976/* Rollback information flash region protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001977#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001978/* Rollback information flash region protected now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001979#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001980/* Error - Unknown error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001981#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001982
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001983/**
1984 * struct ec_params_flash_protect - Parameters for the flash protect command.
1985 * @mask: Bits in flags to apply.
1986 * @flags: New flags to apply.
1987 */
1988struct ec_params_flash_protect {
1989 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001990 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001991} __ec_align4;
1992
Simon Glassd3870a22023-11-09 08:43:30 -07001993enum flash_protect_action {
1994 FLASH_PROTECT_ASYNC = 0,
1995 FLASH_PROTECT_GET_RESULT = 1,
1996};
1997
1998/* Version 2 of the command is "asynchronous". */
1999struct ec_params_flash_protect_v2 {
2000 uint8_t action; /**< enum flash_protect_action */
2001 uint8_t reserved[3]; /**< padding for alignment */
2002 uint32_t mask;
2003 uint32_t flags;
2004} __ec_align4;
2005
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002006/**
2007 * struct ec_response_flash_protect - Response to the flash protect command.
2008 * @flags: Current value of flash protect flags.
2009 * @valid_flags: Flags which are valid on this platform. This allows the
2010 * caller to distinguish between flags which aren't set vs. flags
2011 * which can't be set on this platform.
2012 * @writable_flags: Flags which can be changed given the current protection
2013 * state.
2014 */
2015struct ec_response_flash_protect {
2016 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002017 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002018 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002019} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002020
2021/*
2022 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
2023 * write protect. These commands may be reused with version > 0.
2024 */
2025
2026/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002027#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002028#define EC_VER_FLASH_REGION_INFO 1
2029
2030enum ec_flash_region {
2031 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08002032 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002033 /*
2034 * Region which holds active RW image. 'Active' is different from
2035 * 'running'. Active means 'scheduled-to-run'. Since RO image always
2036 * scheduled to run, active/non-active applies only to RW images (for
2037 * the same reason 'update' applies only to RW images. It's a state of
2038 * an image on a flash. Running image can be RO, RW_A, RW_B but active
2039 * image can only be RW_A or RW_B. In recovery mode, an active RW image
2040 * doesn't enter 'running' state but it's still active on a flash.
2041 */
2042 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002043 /*
2044 * Region which should be write-protected in the factory (a superset of
2045 * EC_FLASH_REGION_RO)
2046 */
2047 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002048 /* Region which holds updatable (non-active) RW image */
2049 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08002050 /* Number of regions */
2051 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002052};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002053/*
2054 * 'RW' is vague if there are multiple RW images; we mean the active one,
2055 * so the old constant is deprecated.
2056 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002057#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002058
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002059/**
2060 * struct ec_params_flash_region_info - Parameters for the flash region info
2061 * command.
2062 * @region: Flash region; see EC_FLASH_REGION_*
2063 */
2064struct ec_params_flash_region_info {
2065 uint32_t region;
2066} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002067
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002068struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002069 uint32_t offset;
2070 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002071} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002072
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002073/* Get SPI flash information */
2074#define EC_CMD_FLASH_SPI_INFO 0x0018
2075
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002076struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002077 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
2078 uint8_t jedec[3];
2079
2080 /* Pad byte; currently always contains 0 */
2081 uint8_t reserved0;
2082
2083 /* Manufacturer / device ID from command 0x90 */
2084 uint8_t mfr_dev_id[2];
2085
2086 /* Status registers from command 0x05 and 0x35 */
2087 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002088} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002089
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002090/* Select flash during flash operations */
2091#define EC_CMD_FLASH_SELECT 0x0019
2092
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002093/**
2094 * struct ec_params_flash_select - Parameters for the flash select command.
2095 * @select: 1 to select flash, 0 to deselect flash
2096 */
2097struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002098 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002099} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02002100
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002101/**
2102 * Request random numbers to be generated and returned.
2103 * Can be used to test the random number generator is truly random.
2104 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
2105 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
2106 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002107#define EC_CMD_RAND_NUM 0x001A
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002108#define EC_VER_RAND_NUM 0
2109
2110struct ec_params_rand_num {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002111 uint16_t num_rand_bytes; /**< num random bytes to generate */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002112} __ec_align4;
2113
2114struct ec_response_rand_num {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002115 /**
2116 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
2117 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
2118 */
2119 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
2120} __ec_align1;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002121BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
2122
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002123/**
2124 * Get information about the key used to sign the RW firmware.
2125 * For more details on the fields, see "struct vb21_packed_key".
2126 */
2127#define EC_CMD_RWSIG_INFO 0x001B
2128#define EC_VER_RWSIG_INFO 0
2129
2130#define VBOOT2_KEY_ID_BYTES 20
2131
2132#ifdef CHROMIUM_EC
2133/* Don't force external projects to depend on the vboot headers. */
2134#include "vb21_struct.h"
2135BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
2136#endif
2137
2138struct ec_response_rwsig_info {
2139 /**
2140 * Signature algorithm used by the key
2141 * (enum vb2_signature_algorithm).
2142 */
2143 uint16_t sig_alg;
2144
2145 /**
2146 * Hash digest algorithm used with the key
2147 * (enum vb2_hash_algorithm).
2148 */
2149 uint16_t hash_alg;
2150
2151 /** Key version. */
2152 uint32_t key_version;
2153
2154 /** Key ID (struct vb2_id). */
2155 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2156
2157 uint8_t key_is_valid;
2158
2159 /** Alignment padding. */
2160 uint8_t reserved[3];
2161} __ec_align4;
2162
2163BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2164
2165/**
2166 * Get information about the system, such as reset flags, locked state, etc.
2167 */
2168#define EC_CMD_SYSINFO 0x001C
2169#define EC_VER_SYSINFO 0
2170
2171enum sysinfo_flags {
2172 SYSTEM_IS_LOCKED = BIT(0),
2173 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2174 SYSTEM_JUMP_ENABLED = BIT(2),
2175 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08002176 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2177 /*
2178 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2179 * set and cleared when the system shuts down (not when the host event
2180 * flag is cleared).
2181 */
2182 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002183};
2184
2185struct ec_response_sysinfo {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002186 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002187 uint32_t current_image; /**< enum ec_image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002188 uint32_t flags; /**< enum sysinfo_flags */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002189} __ec_align4;
2190
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002191/*****************************************************************************/
2192/* PWM commands */
2193
2194/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002195#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002196
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002197struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002198 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002199} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002200
2201/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002202#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002203
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002204/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002205struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002206 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002207} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002208
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002209/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002210struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002211 uint32_t rpm;
2212 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002213} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002214
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002215/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002216/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002217#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002218
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002219struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002220 uint8_t percent;
2221 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002222} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002223
2224/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002225/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002226#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002227
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002228struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002229 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002230} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002231
2232/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002233#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002234
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002235/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002236struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002237 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002238} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002239
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002240/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002241struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002242 uint32_t percent;
2243 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002244} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002245
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002246#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002247/* 16 bit duty cycle, 0xffff = 100% */
2248#define EC_PWM_MAX_DUTY 0xffff
2249
2250enum ec_pwm_type {
2251 /* All types, indexed by board-specific enum pwm_channel */
2252 EC_PWM_TYPE_GENERIC = 0,
2253 /* Keyboard backlight */
2254 EC_PWM_TYPE_KB_LIGHT,
2255 /* Display backlight */
2256 EC_PWM_TYPE_DISPLAY_LIGHT,
2257 EC_PWM_TYPE_COUNT,
2258};
2259
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002260struct ec_params_pwm_set_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002261 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2262 uint8_t pwm_type; /* ec_pwm_type */
2263 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002264} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002265
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002266#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002267
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002268struct ec_params_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002269 uint8_t pwm_type; /* ec_pwm_type */
2270 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002271} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002272
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002273struct ec_response_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002274 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002275} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002276
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002277/*****************************************************************************/
2278/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002279 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002280 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2281 * into a subcommand. We'll make separate structs for subcommands with
2282 * different input args, so that we know how much to expect.
2283 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002284#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002285
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002286struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002287 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002288} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002289
Duncan Laurie433432b2013-06-03 10:38:22 -07002290#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002291
2292/*
2293 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002294 * host command, but the alignment is the same regardless. Keep it that way.
2295 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002296struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002297 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002298 int32_t google_ramp_up;
2299 int32_t google_ramp_down;
2300 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002301 int32_t s0_tick_delay[2]; /* AC=0/1 */
2302 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie93e24442014-01-06 12:30:52 -08002303 int32_t s0s3_ramp_down;
2304 int32_t s3_sleep_for;
2305 int32_t s3_ramp_up;
2306 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002307
2308 /* Oscillation */
2309 uint8_t new_s0;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002310 uint8_t osc_min[2]; /* AC=0/1 */
2311 uint8_t osc_max[2]; /* AC=0/1 */
2312 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002313
2314 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002315 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2316 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2317 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002318
2319 /* Battery level thresholds */
2320 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2321
2322 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002323 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2324 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie433432b2013-06-03 10:38:22 -07002325
2326 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002327 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002328} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002329
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002330struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002331 /* Timing */
2332 int32_t google_ramp_up;
2333 int32_t google_ramp_down;
2334 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002335 int32_t s0_tick_delay[2]; /* AC=0/1 */
2336 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002337 int32_t s0s3_ramp_down;
2338 int32_t s3_sleep_for;
2339 int32_t s3_ramp_up;
2340 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002341 int32_t s5_ramp_up;
2342 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002343 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002344 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002345 int32_t tap_display_time;
2346
2347 /* Tap-for-battery params */
2348 uint8_t tap_pct_red;
2349 uint8_t tap_pct_green;
2350 uint8_t tap_seg_min_on;
2351 uint8_t tap_seg_max_on;
2352 uint8_t tap_seg_osc;
2353 uint8_t tap_idx[3];
2354
2355 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002356 uint8_t osc_min[2]; /* AC=0/1 */
2357 uint8_t osc_max[2]; /* AC=0/1 */
2358 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002359
2360 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002361 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2362 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2363 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002364
2365 /* Battery level thresholds */
2366 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2367
2368 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002369 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2370 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002371
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002372 /* s5: single color pulse on inhibited power-up */
2373 uint8_t s5_idx;
2374
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002375 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002376 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002377} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002378
Duncan Laurieeb316852015-12-01 18:51:18 -08002379/* Lightbar command params v2
2380 * crbug.com/467716
2381 *
2382 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2383 * logical groups to make it more manageable ( < 120 bytes).
2384 *
2385 * NOTE: Each of these groups must be less than 120 bytes.
2386 */
2387
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002388struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002389 /* Timing */
2390 int32_t google_ramp_up;
2391 int32_t google_ramp_down;
2392 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002393 int32_t s0_tick_delay[2]; /* AC=0/1 */
2394 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002395 int32_t s0s3_ramp_down;
2396 int32_t s3_sleep_for;
2397 int32_t s3_ramp_up;
2398 int32_t s3_ramp_down;
2399 int32_t s5_ramp_up;
2400 int32_t s5_ramp_down;
2401 int32_t tap_tick_delay;
2402 int32_t tap_gate_delay;
2403 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002404} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002405
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002406struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002407 /* Tap-for-battery params */
2408 uint8_t tap_pct_red;
2409 uint8_t tap_pct_green;
2410 uint8_t tap_seg_min_on;
2411 uint8_t tap_seg_max_on;
2412 uint8_t tap_seg_osc;
2413 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002414} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002415
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002416struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002417 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002418 uint8_t osc_min[2]; /* AC=0/1 */
2419 uint8_t osc_max[2]; /* AC=0/1 */
2420 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002421} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002422
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002423struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002424 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002425 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2426 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2427 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002428} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002429
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002430struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002431 /* Battery level thresholds */
2432 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002433} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002434
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002435struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002436 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002437 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2438 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurieeb316852015-12-01 18:51:18 -08002439
2440 /* s5: single color pulse on inhibited power-up */
2441 uint8_t s5_idx;
2442
2443 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002444 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002445} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002446
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002447/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002448#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002449struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002450 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002451 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002452} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002453
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002454struct ec_params_lightbar {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002455 uint8_t cmd; /* Command (see enum lightbar_command) */
Duncan Laurie433432b2013-06-03 10:38:22 -07002456 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002457 /*
2458 * The following commands have no args:
2459 *
2460 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2461 * version, get_brightness, get_demo, suspend, resume,
2462 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2463 * get_params_v2_bright, get_params_v2_thlds,
2464 * get_params_v2_colors
2465 *
2466 * Don't use an empty struct, because C++ hates that.
2467 */
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 num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002471 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002472
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002473 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002474 uint8_t ctrl, reg, value;
2475 } reg;
2476
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002477 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002478 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002479 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002480
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002481 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002482 uint8_t led;
2483 } get_rgb;
2484
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002485 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002486 uint8_t enable;
2487 } manual_suspend_ctrl;
2488
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002489 struct lightbar_params_v0 set_params_v0;
2490 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002491
2492 struct lightbar_params_v2_timing set_v2par_timing;
2493 struct lightbar_params_v2_tap set_v2par_tap;
2494 struct lightbar_params_v2_oscillation set_v2par_osc;
2495 struct lightbar_params_v2_brightness set_v2par_bright;
2496 struct lightbar_params_v2_thresholds set_v2par_thlds;
2497 struct lightbar_params_v2_colors set_v2par_colors;
2498
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002499 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002500 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002501} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002502
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002503struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002504 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002505 struct __ec_todo_unpacked {
2506 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002507 uint8_t reg;
2508 uint8_t ic0;
2509 uint8_t ic1;
2510 } vals[23];
2511 } dump;
2512
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002513 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002514 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002515 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002516
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002517 struct lightbar_params_v0 get_params_v0;
2518 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002519
Duncan Laurieeb316852015-12-01 18:51:18 -08002520 struct lightbar_params_v2_timing get_params_v2_timing;
2521 struct lightbar_params_v2_tap get_params_v2_tap;
2522 struct lightbar_params_v2_oscillation get_params_v2_osc;
2523 struct lightbar_params_v2_brightness get_params_v2_bright;
2524 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2525 struct lightbar_params_v2_colors get_params_v2_colors;
2526
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002527 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002528 uint32_t num;
2529 uint32_t flags;
2530 } version;
2531
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002532 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002533 uint8_t red, green, blue;
2534 } get_rgb;
2535
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002536 /*
2537 * The following commands have no response:
2538 *
2539 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2540 * set_params_v0, set_params_v1, set_program,
2541 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2542 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2543 * set_v2par_thlds, set_v2par_colors
2544 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002545 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002546} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002547
2548/* Lightbar commands */
2549enum lightbar_command {
2550 LIGHTBAR_CMD_DUMP = 0,
2551 LIGHTBAR_CMD_OFF = 1,
2552 LIGHTBAR_CMD_ON = 2,
2553 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002554 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002555 LIGHTBAR_CMD_SEQ = 5,
2556 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002557 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002558 LIGHTBAR_CMD_GET_SEQ = 8,
2559 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002560 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2561 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002562 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002563 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2564 LIGHTBAR_CMD_GET_RGB = 14,
2565 LIGHTBAR_CMD_GET_DEMO = 15,
2566 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2567 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002568 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002569 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2570 LIGHTBAR_CMD_SUSPEND = 20,
2571 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002572 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2573 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2574 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2575 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2576 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2577 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2578 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2579 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2580 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2581 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2582 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2583 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002584 LIGHTBAR_NUM_CMDS,
Duncan Laurie433432b2013-06-03 10:38:22 -07002585};
2586
2587/*****************************************************************************/
2588/* LED control commands */
2589
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002590#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002591
Bill Richardsone221aad2013-06-12 10:50:41 -07002592enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002593 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002594 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002595 /*
2596 * LED to indicate system power state (on or in suspend).
2597 * May be on power button or on C-panel.
2598 */
2599 EC_LED_ID_POWER_LED,
2600 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002601 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002602 /* LED to indicate left side */
2603 EC_LED_ID_LEFT_LED,
2604 /* LED to indicate right side */
2605 EC_LED_ID_RIGHT_LED,
2606 /* LED to indicate recovery mode with HW_REINIT */
2607 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2608 /* LED to indicate sysrq debug mode. */
2609 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002610
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002611 EC_LED_ID_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002612};
Duncan Laurie433432b2013-06-03 10:38:22 -07002613
Bill Richardsone221aad2013-06-12 10:50:41 -07002614/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002615#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002616#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002617
2618enum ec_led_colors {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002619 EC_LED_COLOR_INVALID = -1,
Bill Richardsone221aad2013-06-12 10:50:41 -07002620 EC_LED_COLOR_RED = 0,
2621 EC_LED_COLOR_GREEN,
2622 EC_LED_COLOR_BLUE,
2623 EC_LED_COLOR_YELLOW,
2624 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002625 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002626
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002627 EC_LED_COLOR_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002628};
2629
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002630struct ec_params_led_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002631 uint8_t led_id; /* Which LED to control */
2632 uint8_t flags; /* Control flags */
Bill Richardsone221aad2013-06-12 10:50:41 -07002633
2634 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002635} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002636
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002637struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002638 /*
2639 * Available brightness value range.
2640 *
2641 * Range 0 means color channel not present.
2642 * Range 1 means on/off control.
2643 * Other values means the LED is control by PWM.
2644 */
2645 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002646} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002647
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002648/*****************************************************************************/
2649/* Verified boot commands */
2650
2651/*
2652 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2653 * reused for other purposes with version > 0.
2654 */
2655
2656/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002657#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002658
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002659struct ec_params_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002660 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2661 uint8_t hash_type; /* enum ec_vboot_hash_type */
2662 uint8_t nonce_size; /* Nonce size; may be 0 */
2663 uint8_t reserved0; /* Reserved; set 0 */
2664 uint32_t offset; /* Offset in flash to hash */
2665 uint32_t size; /* Number of bytes to hash */
2666 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002667} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002668
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002669struct ec_response_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002670 uint8_t status; /* enum ec_vboot_hash_status */
2671 uint8_t hash_type; /* enum ec_vboot_hash_type */
2672 uint8_t digest_size; /* Size of hash digest in bytes */
2673 uint8_t reserved0; /* Ignore; will be 0 */
2674 uint32_t offset; /* Offset in flash which was hashed */
2675 uint32_t size; /* Number of bytes hashed */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002676 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002677} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002678
2679enum ec_vboot_hash_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002680 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2681 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2682 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2683 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002684};
2685
2686enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002687 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002688};
2689
2690enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002691 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2692 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2693 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002694};
2695
Duncan Laurie433432b2013-06-03 10:38:22 -07002696/*
2697 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2698 * If one of these is specified, the EC will automatically update offset and
2699 * size to the correct values for the specified image (RO or RW).
2700 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002701#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2702#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2703#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002705/*
2706 * 'RW' is vague if there are multiple RW images; we mean the active one,
2707 * so the old constant is deprecated.
2708 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002709#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002710
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002711/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002712/*
2713 * Motion sense commands. We'll make separate structs for sub-commands with
2714 * different input args, so that we know how much to expect.
2715 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002716#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002717
2718/* Motion sense commands */
2719enum motionsense_command {
2720 /*
2721 * Dump command returns all motion sensor data including motion sense
2722 * module flags and individual sensor flags.
2723 */
2724 MOTIONSENSE_CMD_DUMP = 0,
2725
2726 /*
2727 * Info command returns data describing the details of a given sensor,
2728 * including enum motionsensor_type, enum motionsensor_location, and
2729 * enum motionsensor_chip.
2730 */
2731 MOTIONSENSE_CMD_INFO = 1,
2732
2733 /*
2734 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002735 * in milliseconds.
2736 * It is per sensor, the EC run sample task at the minimum of all
2737 * sensors EC_RATE.
2738 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2739 * to collect all the sensor samples.
2740 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2741 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002742 */
2743 MOTIONSENSE_CMD_EC_RATE = 2,
2744
2745 /*
2746 * Sensor ODR command is a setter/getter command for the output data
2747 * rate of a specific motion sensor in millihertz.
2748 */
2749 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2750
2751 /*
2752 * Sensor range command is a setter/getter command for the range of
2753 * a specified motion sensor in +/-G's or +/- deg/s.
2754 */
2755 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2756
2757 /*
2758 * Setter/getter command for the keyboard wake angle. When the lid
2759 * angle is greater than this value, keyboard wake is disabled in S3,
2760 * and when the lid angle goes less than this value, keyboard wake is
2761 * enabled. Note, the lid angle measurement is an approximate,
2762 * un-calibrated value, hence the wake angle isn't exact.
2763 */
2764 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2765
Duncan Laurieeb316852015-12-01 18:51:18 -08002766 /*
2767 * Returns a single sensor data.
2768 */
2769 MOTIONSENSE_CMD_DATA = 6,
2770
2771 /*
2772 * Return sensor fifo info.
2773 */
2774 MOTIONSENSE_CMD_FIFO_INFO = 7,
2775
2776 /*
2777 * Insert a flush element in the fifo and return sensor fifo info.
2778 * The host can use that element to synchronize its operation.
2779 */
2780 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2781
2782 /*
2783 * Return a portion of the fifo.
2784 */
2785 MOTIONSENSE_CMD_FIFO_READ = 9,
2786
2787 /*
2788 * Perform low level calibration.
2789 * On sensors that support it, ask to do offset calibration.
2790 */
2791 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2792
2793 /*
2794 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002795 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002796 * The offsets can be calculated by the host, or via
2797 * PERFORM_CALIB command.
2798 */
2799 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2800
2801 /*
2802 * List available activities for a MOTION sensor.
2803 * Indicates if they are enabled or disabled.
2804 */
2805 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2806
2807 /*
2808 * Activity management
2809 * Enable/Disable activity recognition.
2810 */
2811 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2812
2813 /*
2814 * Lid Angle
2815 */
2816 MOTIONSENSE_CMD_LID_ANGLE = 14,
2817
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002818 /*
2819 * Allow the FIFO to trigger interrupt via MKBP events.
2820 * By default the FIFO does not send interrupt to process the FIFO
2821 * until the AP is ready or it is coming from a wakeup sensor.
2822 */
2823 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2824
2825 /*
2826 * Spoof the readings of the sensors. The spoofed readings can be set
2827 * to arbitrary values, or will lock to the last read actual values.
2828 */
2829 MOTIONSENSE_CMD_SPOOF = 16,
2830
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002831 /* Set lid angle for tablet mode detection. */
2832 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2833
2834 /*
2835 * Sensor Scale command is a setter/getter command for the calibration
2836 * scale.
2837 */
2838 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2839
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002840 /*
2841 * Read the current online calibration values (if available).
2842 */
2843 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2844
Yidi Lin42f79592020-09-21 18:04:10 +08002845 /*
2846 * Activity management
2847 * Retrieve current status of given activity.
2848 */
2849 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2850
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002851 /* Number of motionsense sub-commands. */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002852 MOTIONSENSE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002853};
2854
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002855/* List of motion sensor types. */
2856enum motionsensor_type {
2857 MOTIONSENSE_TYPE_ACCEL = 0,
2858 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002859 MOTIONSENSE_TYPE_MAG = 2,
2860 MOTIONSENSE_TYPE_PROX = 3,
2861 MOTIONSENSE_TYPE_LIGHT = 4,
2862 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002863 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002864 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002865 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002866 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002867};
2868
2869/* List of motion sensor locations. */
2870enum motionsensor_location {
2871 MOTIONSENSE_LOC_BASE = 0,
2872 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002873 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002874 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002875};
2876
2877/* List of motion sensor chips. */
2878enum motionsensor_chip {
2879 MOTIONSENSE_CHIP_KXCJ9 = 0,
2880 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002881 MOTIONSENSE_CHIP_BMI160 = 2,
2882 MOTIONSENSE_CHIP_SI1141 = 3,
2883 MOTIONSENSE_CHIP_SI1142 = 4,
2884 MOTIONSENSE_CHIP_SI1143 = 5,
2885 MOTIONSENSE_CHIP_KX022 = 6,
2886 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002887 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002888 MOTIONSENSE_CHIP_BMP280 = 9,
2889 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002890 MOTIONSENSE_CHIP_BH1730 = 11,
2891 MOTIONSENSE_CHIP_GPIO = 12,
2892 MOTIONSENSE_CHIP_LIS2DH = 13,
2893 MOTIONSENSE_CHIP_LSM6DSM = 14,
2894 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002895 MOTIONSENSE_CHIP_LIS2MDL = 16,
2896 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2897 MOTIONSENSE_CHIP_LSM6DSO = 18,
2898 MOTIONSENSE_CHIP_LNG2DM = 19,
2899 MOTIONSENSE_CHIP_TCS3400 = 20,
2900 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2901 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002902 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002903 MOTIONSENSE_CHIP_BMI260 = 24,
2904 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002905 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002906 MOTIONSENSE_CHIP_BMA422 = 27,
2907 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002908 MOTIONSENSE_CHIP_BMI220 = 29,
2909 MOTIONSENSE_CHIP_CM32183 = 30,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05002910 MOTIONSENSE_CHIP_VEML3328 = 31,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002911 MOTIONSENSE_CHIP_MAX,
2912};
2913
2914/* List of orientation positions */
2915enum motionsensor_orientation {
2916 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2917 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2918 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2919 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2920 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002921};
2922
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002923struct ec_response_activity_data {
2924 uint8_t activity; /* motionsensor_activity */
2925 uint8_t state;
2926} __ec_todo_packed;
2927
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002928struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002929 /* Flags for each sensor. */
2930 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002931 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002932 uint8_t sensor_num;
2933 /* Each sensor is up to 3-axis. */
2934 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002935 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002936 /* for sensors using unsigned data */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002937 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002938 struct __ec_todo_packed {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002939 uint16_t reserved;
2940 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002941 };
2942 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002943 struct ec_response_activity_data activity_data;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002944 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002945 };
2946 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002947} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002948
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002949/* Response to AP reporting calibration data for a given sensor. */
2950struct ec_response_online_calibration_data {
2951 /** The calibration values. */
2952 int16_t data[3];
2953};
2954
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002955/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002956struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002957 /* Size of the fifo */
2958 uint16_t size;
2959 /* Amount of space used in the fifo */
2960 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002961 /* Timestamp recorded in us.
2962 * aka accurate timestamp when host event was triggered.
2963 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002964 uint32_t timestamp;
2965 /* Total amount of vector lost */
2966 uint16_t total_lost;
2967 /* Lost events since the last fifo_info, per sensors */
2968 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002969} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002970
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002971struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002972 uint32_t number_data;
2973 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002974} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002975
2976/* List supported activity recognition */
2977enum motionsensor_activity {
2978 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2979 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2980 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002981 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002982 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002983};
2984
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002985struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002986 uint8_t sensor_num;
2987 uint8_t activity; /* one of enum motionsensor_activity */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002988 uint8_t enable; /* 1: enable, 0: disable */
Duncan Laurieeb316852015-12-01 18:51:18 -08002989 uint8_t reserved;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002990 uint16_t parameters[4]; /* activity dependent parameters */
2991} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002992
2993/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002994#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002995
2996/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002997#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002998
2999/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003000 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08003001 * data contains time stamp
3002 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003003#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
3004#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
3005#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
3006#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
3007#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08003008
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003009#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
3010
Duncan Laurieeb316852015-12-01 18:51:18 -08003011/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003012 * Send this value for the data element to only perform a read. If you
3013 * send any other value, the EC will interpret it as data to set and will
3014 * return the actual value set.
3015 */
3016#define EC_MOTION_SENSE_NO_VALUE -1
3017
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003018#define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
Duncan Laurieeb316852015-12-01 18:51:18 -08003019
3020/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
3021/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003022#define MOTION_SENSE_SET_OFFSET BIT(0)
3023
3024/* Default Scale value, factor 1. */
3025#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08003026
3027#define LID_ANGLE_UNRELIABLE 500
3028
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003029enum motionsense_spoof_mode {
3030 /* Disable spoof mode. */
3031 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
3032
3033 /* Enable spoof mode, but use provided component values. */
3034 MOTIONSENSE_SPOOF_MODE_CUSTOM,
3035
3036 /* Enable spoof mode, but use the current sensor values. */
3037 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
3038
3039 /* Query the current spoof mode status for the sensor. */
3040 MOTIONSENSE_SPOOF_MODE_QUERY,
3041};
3042
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003043struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003044 uint8_t cmd;
3045 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003046 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003047 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003048 /*
3049 * Maximal number of sensor the host is expecting.
3050 * 0 means the host is only interested in the number
3051 * of sensors controlled by the EC.
3052 */
3053 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003054 } dump;
3055
3056 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08003057 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003058 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003059 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003060 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08003061 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08003062 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003063 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08003064 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003065
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003066 /*
3067 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
3068 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003069 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003070 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003071 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003072
3073 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003074 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
3075 * Allow entering/exiting the calibration mode.
3076 */
3077 struct __ec_todo_unpacked {
3078 uint8_t sensor_num;
3079 uint8_t enable;
3080 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003081
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003082 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08003083 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
3084 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003085 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003086 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003087 uint8_t sensor_num;
3088
3089 /* Rounding flag, true for round-up, false for down. */
3090 uint8_t roundup;
3091
3092 uint16_t reserved;
3093
3094 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
3095 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08003096 } ec_rate, sensor_odr, sensor_range;
3097
3098 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003099 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003100 uint8_t sensor_num;
3101
3102 /*
3103 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3104 * the calibration information in the EC.
3105 * If unset, just retrieve calibration information.
3106 */
3107 uint16_t flags;
3108
3109 /*
3110 * Temperature at calibration, in units of 0.01 C
3111 * 0x8000: invalid / unknown.
3112 * 0x0: 0C
3113 * 0x7fff: +327.67C
3114 */
3115 int16_t temp;
3116
3117 /*
3118 * Offset for calibration.
3119 * Unit:
3120 * Accelerometer: 1/1024 g
3121 * Gyro: 1/1024 deg/s
3122 * Compass: 1/16 uT
3123 */
3124 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003125 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08003126
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003127 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3128 struct __ec_todo_packed {
3129 uint8_t sensor_num;
3130
3131 /*
3132 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3133 * the calibration information in the EC.
3134 * If unset, just retrieve calibration information.
3135 */
3136 uint16_t flags;
3137
3138 /*
3139 * Temperature at calibration, in units of 0.01 C
3140 * 0x8000: invalid / unknown.
3141 * 0x0: 0C
3142 * 0x7fff: +327.67C
3143 */
3144 int16_t temp;
3145
3146 /*
3147 * Scale for calibration:
3148 * By default scale is 1, it is encoded on 16bits:
3149 * 1 = BIT(15)
3150 * ~2 = 0xFFFF
3151 * ~0 = 0.
3152 */
3153 uint16_t scale[3];
3154 } sensor_scale;
3155
Duncan Laurieeb316852015-12-01 18:51:18 -08003156 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003157 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08003158
3159 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003160 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003161 /*
3162 * Number of expected vector to return.
3163 * EC may return less or 0 if none available.
3164 */
3165 uint32_t max_data_vector;
3166 } fifo_read;
3167
Yidi Lin42f79592020-09-21 18:04:10 +08003168 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08003169 struct ec_motion_sense_activity set_activity;
3170
3171 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003172 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003173
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003174 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3175 struct __ec_todo_unpacked {
3176 /*
3177 * 1: enable, 0 disable fifo,
3178 * EC_MOTION_SENSE_NO_VALUE return value.
3179 */
3180 int8_t enable;
3181 } fifo_int_enable;
3182
3183 /* Used for MOTIONSENSE_CMD_SPOOF */
3184 struct __ec_todo_packed {
3185 uint8_t sensor_id;
3186
3187 /* See enum motionsense_spoof_mode. */
3188 uint8_t spoof_enable;
3189
3190 /* Ignored, used for alignment. */
3191 uint8_t reserved;
3192
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003193 union {
3194 /* Individual component values to spoof. */
3195 int16_t components[3];
3196
3197 /* Used when spoofing an activity */
3198 struct {
3199 /* enum motionsensor_activity */
3200 uint8_t activity_num;
3201
3202 /* spoof activity state */
3203 uint8_t activity_state;
3204 };
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003205 } __ec_todo_packed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003206 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003207
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003208 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3209 struct __ec_todo_unpacked {
3210 /*
3211 * Lid angle threshold for switching between tablet and
3212 * clamshell mode.
3213 */
3214 int16_t lid_angle;
3215
3216 /*
3217 * Hysteresis degree to prevent fluctuations between
3218 * clamshell and tablet mode if lid angle keeps
3219 * changing around the threshold. Lid motion driver will
3220 * use lid_angle + hys_degree to trigger tablet mode and
3221 * lid_angle - hys_degree to trigger clamshell mode.
3222 */
3223 int16_t hys_degree;
3224 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003225
3226 /*
3227 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3228 * Allow reading a single sensor's online calibration value.
3229 */
3230 struct __ec_todo_unpacked {
3231 uint8_t sensor_num;
3232 } online_calib_read;
3233
Yidi Lin42f79592020-09-21 18:04:10 +08003234 /*
3235 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3236 */
3237 struct __ec_todo_unpacked {
3238 uint8_t sensor_num;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003239 uint8_t activity; /* enum motionsensor_activity */
Yidi Lin42f79592020-09-21 18:04:10 +08003240 } get_activity;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003241 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003242} __ec_todo_packed;
3243
Jett Rinkba2edaf2020-01-14 11:49:06 -07003244enum motion_sense_cmd_info_flags {
3245 /* The sensor supports online calibration */
3246 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3247};
3248
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003249struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003250 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003251 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003252 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003253 /* Flags representing the motion sensor module. */
3254 uint8_t module_flags;
3255
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003256 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003257 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003258
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003259 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003260 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003261 * for holding all the data.
3262 */
3263 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003264 } dump;
3265
3266 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003267 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003268 /* Should be element of enum motionsensor_type. */
3269 uint8_t type;
3270
3271 /* Should be element of enum motionsensor_location. */
3272 uint8_t location;
3273
3274 /* Should be element of enum motionsensor_chip. */
3275 uint8_t chip;
3276 } info;
3277
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003278 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3279 struct __ec_todo_unpacked {
3280 /* Should be element of enum motionsensor_type. */
3281 uint8_t type;
3282
3283 /* Should be element of enum motionsensor_location. */
3284 uint8_t location;
3285
3286 /* Should be element of enum motionsensor_chip. */
3287 uint8_t chip;
3288
3289 /* Minimum sensor sampling frequency */
3290 uint32_t min_frequency;
3291
3292 /* Maximum sensor sampling frequency */
3293 uint32_t max_frequency;
3294
3295 /* Max number of sensor events that could be in fifo */
3296 uint32_t fifo_max_event_count;
3297 } info_3;
3298
Jett Rinkba2edaf2020-01-14 11:49:06 -07003299 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3300 struct __ec_align4 {
3301 /* Should be element of enum motionsensor_type. */
3302 uint8_t type;
3303
3304 /* Should be element of enum motionsensor_location. */
3305 uint8_t location;
3306
3307 /* Should be element of enum motionsensor_chip. */
3308 uint8_t chip;
3309
3310 /* Minimum sensor sampling frequency */
3311 uint32_t min_frequency;
3312
3313 /* Maximum sensor sampling frequency */
3314 uint32_t max_frequency;
3315
3316 /* Max number of sensor events that could be in fifo */
3317 uint32_t fifo_max_event_count;
3318
3319 /*
3320 * Should be elements of
3321 * enum motion_sense_cmd_info_flags
3322 */
3323 uint32_t flags;
3324 } info_4;
3325
Duncan Laurieeb316852015-12-01 18:51:18 -08003326 /* Used for MOTIONSENSE_CMD_DATA */
3327 struct ec_response_motion_sensor_data data;
3328
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003329 /*
3330 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003331 * MOTIONSENSE_CMD_SENSOR_RANGE,
3332 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3333 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3334 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003335 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003336 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003337 /* Current value of the parameter queried. */
3338 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003339 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Caveh Jalali024ffe32023-01-30 14:35:19 -08003340 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003341
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003342 /*
3343 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3344 * PERFORM_CALIB.
3345 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003346 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003347 int16_t temp;
3348 int16_t offset[3];
3349 } sensor_offset, perform_calib;
3350
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003351 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003352 struct __ec_todo_unpacked {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003353 int16_t temp;
3354 uint16_t scale[3];
3355 } sensor_scale;
3356
Duncan Laurieeb316852015-12-01 18:51:18 -08003357 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3358
3359 struct ec_response_motion_sense_fifo_data fifo_read;
3360
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003361 struct ec_response_online_calibration_data online_calib_read;
3362
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003363 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003364 uint16_t reserved;
3365 uint32_t enabled;
3366 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003367 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003368
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003369 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003370
Duncan Laurieeb316852015-12-01 18:51:18 -08003371 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003372 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003373 /*
3374 * Angle between 0 and 360 degree if available,
3375 * LID_ANGLE_UNRELIABLE otherwise.
3376 */
3377 uint16_t value;
3378 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003379
3380 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3381 struct __ec_todo_unpacked {
3382 /*
3383 * Lid angle threshold for switching between tablet and
3384 * clamshell mode.
3385 */
3386 uint16_t lid_angle;
3387
3388 /* Hysteresis degree. */
3389 uint16_t hys_degree;
3390 } tablet_mode_threshold;
3391
Yidi Lin42f79592020-09-21 18:04:10 +08003392 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3393 struct __ec_todo_unpacked {
3394 uint8_t state;
3395 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003396 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003397} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003398
3399/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003400/* Force lid open command */
3401
3402/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003403#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003404
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003405struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003406 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003407} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003408
3409/*****************************************************************************/
3410/* Configure the behavior of the power button */
3411#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3412
3413enum ec_config_power_button_flags {
3414 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003415 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003416};
3417
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003418struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003419 /* See enum ec_config_power_button_flags */
3420 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003421} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003422
3423/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003424/* USB charging control commands */
3425
3426/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003427#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003428
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003429enum usb_charge_mode {
3430 /* Disable USB port. */
3431 USB_CHARGE_MODE_DISABLED,
3432 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3433 USB_CHARGE_MODE_SDP2,
3434 /* Set USB port to Charging Downstream Port, BC 1.2. */
3435 USB_CHARGE_MODE_CDP,
3436 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3437 USB_CHARGE_MODE_DCP_SHORT,
3438 /* Enable USB port (for dumb ports). */
3439 USB_CHARGE_MODE_ENABLED,
3440 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3441 USB_CHARGE_MODE_DEFAULT,
3442
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003443 USB_CHARGE_MODE_COUNT,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003444};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003446enum usb_suspend_charge {
3447 /* Enable charging in suspend */
3448 USB_ALLOW_SUSPEND_CHARGE,
3449 /* Disable charging in suspend */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003450 USB_DISALLOW_SUSPEND_CHARGE,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003451};
3452
3453struct ec_params_usb_charge_set_mode {
3454 uint8_t usb_port_id;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003455 uint8_t mode : 7; /* enum usb_charge_mode */
3456 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003457} __ec_align1;
3458
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003459/*****************************************************************************/
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003460/* Tablet mode commands */
3461
3462/* Set tablet mode */
3463#define EC_CMD_SET_TABLET_MODE 0x0031
3464
3465enum tablet_mode_override {
3466 TABLET_MODE_DEFAULT,
3467 TABLET_MODE_FORCE_TABLET,
3468 TABLET_MODE_FORCE_CLAMSHELL,
3469};
3470
3471struct ec_params_set_tablet_mode {
3472 uint8_t tablet_mode; /* enum tablet_mode_override */
3473} __ec_align1;
3474
3475/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003476/* Persistent storage for host */
3477
3478/* Maximum bytes that can be read/written in a single command */
3479#define EC_PSTORE_SIZE_MAX 64
3480
3481/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003482#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003483
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003484struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003485 /* Persistent storage size, in bytes */
3486 uint32_t pstore_size;
3487 /* Access size; read/write offset and size must be a multiple of this */
3488 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003489} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003490
3491/*
3492 * Read persistent storage
3493 *
3494 * Response is params.size bytes of data.
3495 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003496#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003497
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003498struct ec_params_pstore_read {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003499 uint32_t offset; /* Byte offset to read */
3500 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003501} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003502
3503/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003504#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003505
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003506struct ec_params_pstore_write {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003507 uint32_t offset; /* Byte offset to write */
3508 uint32_t size; /* Size to write in bytes */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003509 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003510} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003511
3512/*****************************************************************************/
3513/* Real-time clock */
3514
3515/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003516struct ec_params_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
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003520struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003521 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003522} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003523
3524/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003525#define EC_CMD_RTC_GET_VALUE 0x0044
3526#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003527
3528/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003529#define EC_CMD_RTC_SET_VALUE 0x0046
3530#define EC_CMD_RTC_SET_ALARM 0x0047
3531
3532/* Pass as time param to SET_ALARM to clear the current alarm */
3533#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003534
3535/*****************************************************************************/
3536/* Port80 log access */
3537
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003538/* Maximum entries that can be read/written in a single command */
3539#define EC_PORT80_SIZE_MAX 32
3540
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003541/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003542#define EC_CMD_PORT80_LAST_BOOT 0x0048
3543#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003544
3545enum ec_port80_subcmd {
3546 EC_PORT80_GET_INFO = 0,
3547 EC_PORT80_READ_BUFFER,
3548};
3549
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003550struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003551 uint16_t subcmd;
3552 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003553 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003554 uint32_t offset;
3555 uint32_t num_entries;
3556 } read_buffer;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003557 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003558} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003559
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003560struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003561 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003562 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003563 uint32_t writes;
3564 uint32_t history_size;
3565 uint32_t last_boot;
3566 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003567 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003568 uint16_t codes[EC_PORT80_SIZE_MAX];
3569 } data;
3570 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003571} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003572
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003573struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003574 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003575} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003576
3577/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003578/* Temporary secure storage for host verified boot use */
3579
3580/* Number of bytes in a vstore slot */
3581#define EC_VSTORE_SLOT_SIZE 64
3582
3583/* Maximum number of vstore slots */
3584#define EC_VSTORE_SLOT_MAX 32
3585
3586/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003587#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003588struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003589 /* Indicates which slots are locked */
3590 uint32_t slot_locked;
3591 /* Total number of slots available */
3592 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003593} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003594
3595/*
3596 * Read temporary secure storage
3597 *
3598 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3599 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003600#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003601
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003602struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003603 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003604} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003605
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003606struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003607 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003608} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003609
3610/*
3611 * Write temporary secure storage and lock it.
3612 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003613#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003614
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003615struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003616 uint8_t slot; /* Slot to write to */
3617 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003618} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003619
3620/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003621/* Thermal engine commands. Note that there are two implementations. We'll
3622 * reuse the command number, but the data and behavior is incompatible.
3623 * Version 0 is what originally shipped on Link.
3624 * Version 1 separates the CPU thermal limits from the fan control.
3625 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003626
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003627#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3628#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003629
Duncan Laurie93e24442014-01-06 12:30:52 -08003630/* The version 0 structs are opaque. You have to know what they are for
3631 * the get/set commands to make any sense.
3632 */
3633
3634/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003635struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003636 uint8_t sensor_type;
3637 uint8_t threshold_id;
3638 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003639} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003640
Duncan Laurie93e24442014-01-06 12:30:52 -08003641/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003642struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003643 uint8_t sensor_type;
3644 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003645} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003646
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003647struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003648 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003649} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003650
Duncan Laurie93e24442014-01-06 12:30:52 -08003651/* The version 1 structs are visible. */
3652enum ec_temp_thresholds {
3653 EC_TEMP_THRESH_WARN = 0,
3654 EC_TEMP_THRESH_HIGH,
3655 EC_TEMP_THRESH_HALT,
3656
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003657 EC_TEMP_THRESH_COUNT,
Duncan Laurie93e24442014-01-06 12:30:52 -08003658};
3659
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003660/*
3661 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003662 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003663 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003664 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3665 * hysteresis.
3666 * For example,
3667 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3668 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3669 * EC will throttle ap when temperature >= 301 K, and release throttling when
3670 * temperature <= 299 K.
3671 *
3672 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3673 * For example,
3674 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3675 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3676 * EC will throttle ap when temperature >= 301 K, and release throttling when
3677 * temperature <= 294 K.
3678 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003679 * Note that this structure is a sub-structure of
3680 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003681 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003682struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003683 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003684 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003685 uint32_t temp_fan_off; /* no active cooling needed */
3686 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003687} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003688
3689/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003690struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003691 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003692} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003693/* This returns a struct ec_thermal_config */
3694
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003695/*
3696 * Version 1 - set config for one sensor.
3697 * Use read-modify-write for best results!
3698 */
3699struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003700 uint32_t sensor_num;
3701 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003702} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003703/* This returns no data */
3704
3705/****************************************************************************/
3706
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003707/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003708#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003709
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003710/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003711struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003712 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003713} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003714
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003715/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003716#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3717#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003718
3719/*
3720 * The original TMP006 calibration only needed four params, but now we need
3721 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3722 * the params opaque. The v1 "get" response will include the algorithm number
3723 * and how many params it requires. That way we can change the EC code without
3724 * needing to update this file. We can also use a different algorithm on each
3725 * sensor.
3726 */
3727
3728/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003729struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003730 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003731} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003732
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003733/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003734struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003735 float s0;
3736 float b0;
3737 float b1;
3738 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003739} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003740
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003741struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003742 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003743 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003744 float s0;
3745 float b0;
3746 float b1;
3747 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003748} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003749
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003750/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003751struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003752 uint8_t algorithm;
3753 uint8_t num_params;
3754 uint8_t reserved[2];
3755 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003756} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003757
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003758struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003759 uint8_t index;
3760 uint8_t algorithm;
3761 uint8_t num_params;
3762 uint8_t reserved;
3763 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003764} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003765
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003766/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003767#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003768
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003769struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003770 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003771} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003772
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003773struct ec_response_tmp006_get_raw {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003774 int32_t t; /* In 1/100 K */
3775 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003776} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003777
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003778/*****************************************************************************/
3779/* MKBP - Matrix KeyBoard Protocol */
3780
3781/*
3782 * Read key state
3783 *
3784 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3785 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003786 *
3787 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3788 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3789 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003790 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003791#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003792
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003793/*
3794 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3795 */
3796#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003797
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003798struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003799 uint32_t rows;
3800 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003801 /* Formerly "switches", which was 0. */
3802 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003803} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003804
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003805struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003806 uint8_t info_type;
3807 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003808} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003809
3810enum ec_mkbp_info_type {
3811 /*
3812 * Info about the keyboard matrix: number of rows and columns.
3813 *
3814 * Returns struct ec_response_mkbp_info.
3815 */
3816 EC_MKBP_INFO_KBD = 0,
3817
3818 /*
3819 * For buttons and switches, info about which specifically are
3820 * supported. event_type must be set to one of the values in enum
3821 * ec_mkbp_event.
3822 *
3823 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3824 * bitmask indicating which buttons or switches are present. See the
3825 * bit inidices below.
3826 */
3827 EC_MKBP_INFO_SUPPORTED = 1,
3828
3829 /*
3830 * Instantaneous state of buttons and switches.
3831 *
3832 * event_type must be set to one of the values in enum ec_mkbp_event.
3833 *
3834 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3835 * indicating the current state of the keyboard matrix.
3836 *
3837 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3838 * event state.
3839 *
3840 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3841 * state of supported buttons.
3842 *
3843 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3844 * state of supported switches.
3845 */
3846 EC_MKBP_INFO_CURRENT = 2,
3847};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003848
3849/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003850#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003852struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003853 uint8_t col;
3854 uint8_t row;
3855 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003856} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003857
Duncan Laurie433432b2013-06-03 10:38:22 -07003858/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003859#define EC_CMD_MKBP_SET_CONFIG 0x0064
3860#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003861
3862/* flags */
3863enum mkbp_config_flags {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003864 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
Duncan Laurie433432b2013-06-03 10:38:22 -07003865};
3866
3867enum mkbp_config_valid {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003868 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3869 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3870 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3871 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3872 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3873 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3874 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003875};
3876
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003877/*
3878 * Configuration for our key scanning algorithm.
3879 *
3880 * Note that this is used as a sub-structure of
3881 * ec_{params/response}_mkbp_get_config.
3882 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003883struct ec_mkbp_config {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003884 uint32_t valid_mask; /* valid fields */
3885 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3886 uint8_t valid_flags; /* which flags are valid */
3887 uint16_t scan_period_us; /* period between start of scans */
Duncan Laurie433432b2013-06-03 10:38:22 -07003888 /* revert to interrupt mode after no activity for this long */
3889 uint32_t poll_timeout_us;
3890 /*
3891 * minimum post-scan relax time. Once we finish a scan we check
3892 * the time until we are due to start the next one. If this time is
3893 * shorter this field, we use this instead.
3894 */
3895 uint16_t min_post_scan_delay_us;
3896 /* delay between setting up output and waiting for it to settle */
3897 uint16_t output_settle_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003898 uint16_t debounce_down_us; /* time for debounce on key down */
3899 uint16_t debounce_up_us; /* time for debounce on key up */
Duncan Laurie433432b2013-06-03 10:38:22 -07003900 /* maximum depth to allow for fifo (0 = no keyscan output) */
3901 uint8_t fifo_max_depth;
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_params_mkbp_set_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
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003908struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003909 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003910} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003911
3912/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003913#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003914
3915enum ec_keyscan_seq_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003916 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3917 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3918 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3919 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3920 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003921};
3922
3923enum ec_collect_flags {
3924 /*
3925 * Indicates this scan was processed by the EC. Due to timing, some
3926 * scans may be skipped.
3927 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003928 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003929};
3930
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003931struct ec_collect_item {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003932 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003933} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003934
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003935struct ec_params_keyscan_seq_ctrl {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003936 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
Duncan Laurie433432b2013-06-03 10:38:22 -07003937 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003938 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003939 uint8_t active; /* still active */
3940 uint8_t num_items; /* number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003941 /* Current item being presented */
3942 uint8_t cur_item;
3943 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003944 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003945 /*
3946 * Absolute time for this scan, measured from the
3947 * start of the sequence.
3948 */
3949 uint32_t time_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003950 uint8_t scan[0]; /* keyscan data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003951 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003952 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003953 uint8_t start_item; /* First item to return */
3954 uint8_t num_items; /* Number of items to return */
Duncan Laurie433432b2013-06-03 10:38:22 -07003955 } collect;
3956 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003957} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003958
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003959struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003960 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003961 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003962 uint8_t num_items; /* Number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003963 /* Data for each item */
3964 struct ec_collect_item item[0];
3965 } collect;
3966 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003967} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003968
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003969/*
3970 * Get the next pending MKBP event.
3971 *
3972 * Returns EC_RES_UNAVAILABLE if there is no event pending.
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00003973 *
3974 * V0: ec_response_get_next_data
3975 * V1: ec_response_get_next_data_v1. Increased key_matrix size from 13 -> 16.
3976 * V2: Added EC_MKBP_HAS_MORE_EVENTS.
3977 * V3: ec_response_get_next_data_v3. Increased key_matrix size from 16 -> 18.
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003978 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003979#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003980
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003981#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3982
3983/*
3984 * We use the most significant bit of the event type to indicate to the host
3985 * that the EC has more MKBP events available to provide.
3986 */
3987#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3988
3989/* The mask to apply to get the raw event type */
3990#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3991
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003992enum ec_mkbp_event {
3993 /* Keyboard matrix changed. The event data is the new matrix state. */
3994 EC_MKBP_EVENT_KEY_MATRIX = 0,
3995
3996 /* New host event. The event data is 4 bytes of host event flags. */
3997 EC_MKBP_EVENT_HOST_EVENT = 1,
3998
Duncan Laurieeb316852015-12-01 18:51:18 -08003999 /* New Sensor FIFO data. The event data is fifo_info structure. */
4000 EC_MKBP_EVENT_SENSOR_FIFO = 2,
4001
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004002 /* The state of the non-matrixed buttons have changed. */
4003 EC_MKBP_EVENT_BUTTON = 3,
4004
4005 /* The state of the switches have changed. */
4006 EC_MKBP_EVENT_SWITCH = 4,
4007
4008 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
4009 EC_MKBP_EVENT_FINGERPRINT = 5,
4010
4011 /*
4012 * Sysrq event: send emulated sysrq. The event data is sysrq,
4013 * corresponding to the key to be pressed.
4014 */
4015 EC_MKBP_EVENT_SYSRQ = 6,
4016
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004017 /*
4018 * New 64-bit host event.
4019 * The event data is 8 bytes of host event flags.
4020 */
4021 EC_MKBP_EVENT_HOST_EVENT64 = 7,
4022
4023 /* Notify the AP that something happened on CEC */
4024 EC_MKBP_EVENT_CEC_EVENT = 8,
4025
4026 /* Send an incoming CEC message to the AP */
4027 EC_MKBP_EVENT_CEC_MESSAGE = 9,
4028
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004029 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
4030 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
4031
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07004032 /* New online calibration values are available. */
4033 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
4034
Rob Barnes8bc5fa92021-06-28 09:32:28 -06004035 /* Peripheral device charger event */
4036 EC_MKBP_EVENT_PCHG = 12,
4037
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004038 /* Number of MKBP events */
4039 EC_MKBP_EVENT_COUNT,
4040};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004041BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004042
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004043/* clang-format off */
4044#define EC_MKBP_EVENT_TEXT \
4045 { \
4046 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
4047 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
4048 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
4049 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
4050 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
4051 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
4052 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
4053 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
4054 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
4055 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
4056 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
4057 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
4058 [EC_MKBP_EVENT_PCHG] = "PCHG", \
4059 }
4060/* clang-format on */
4061
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004062union __ec_align_offset1 ec_response_get_next_data {
4063 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08004064
4065 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004066 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004067 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08004068
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004069 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08004070 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004071 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08004072 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004073 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08004074
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004075 uint32_t buttons;
4076
4077 uint32_t switches;
4078
4079 uint32_t fp_events;
4080
4081 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004082
4083 /* CEC events from enum mkbp_cec_event */
4084 uint32_t cec_events;
4085};
4086
4087union __ec_align_offset1 ec_response_get_next_data_v1 {
4088 uint8_t key_matrix[16];
4089
4090 /* Unaligned */
4091 uint32_t host_event;
4092 uint64_t host_event64;
4093
4094 struct __ec_todo_unpacked {
4095 /* For aligning the fifo_info */
4096 uint8_t reserved[3];
4097 struct ec_response_motion_sense_fifo_info info;
4098 } sensor_fifo;
4099
4100 uint32_t buttons;
4101
4102 uint32_t switches;
4103
4104 uint32_t fp_events;
4105
4106 uint32_t sysrq;
4107
4108 /* CEC events from enum mkbp_cec_event */
4109 uint32_t cec_events;
4110
4111 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004112};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004113BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004114
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00004115union __ec_align_offset1 ec_response_get_next_data_v3 {
4116 uint8_t key_matrix[18];
4117
4118 /* Unaligned */
4119 uint32_t host_event;
4120 uint64_t host_event64;
4121
4122 struct __ec_todo_unpacked {
4123 /* For aligning the fifo_info */
4124 uint8_t reserved[3];
4125 struct ec_response_motion_sense_fifo_info info;
4126 } sensor_fifo;
4127
4128 uint32_t buttons;
4129
4130 uint32_t switches;
4131
4132 uint32_t fp_events;
4133
4134 uint32_t sysrq;
4135
4136 /* CEC events from enum mkbp_cec_event */
4137 uint32_t cec_events;
4138
4139 uint8_t cec_message[16];
4140};
4141BUILD_ASSERT(sizeof(union ec_response_get_next_data_v3) == 18);
4142
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004143struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004144 uint8_t event_type;
4145 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08004146 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004147} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004148
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004149struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004150 uint8_t event_type;
4151 /* Followed by event data if any */
4152 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004153} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004154
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00004155struct ec_response_get_next_event_v3 {
4156 uint8_t event_type;
4157 /* Followed by event data if any */
4158 union ec_response_get_next_data_v3 data;
4159} __ec_align1;
4160
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004161/* Bit indices for buttons and switches.*/
4162/* Buttons */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004163#define EC_MKBP_POWER_BUTTON 0
4164#define EC_MKBP_VOL_UP 1
4165#define EC_MKBP_VOL_DOWN 2
4166#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004167
4168/* Switches */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004169#define EC_MKBP_LID_OPEN 0
4170#define EC_MKBP_TABLET_MODE 1
4171#define EC_MKBP_BASE_ATTACHED 2
4172#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004173
Gwendal Grignou880b4582016-06-20 08:49:25 -07004174/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004175#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07004176
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004177struct ec_response_keyboard_factory_test {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004178 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004179} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004180
4181/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004182#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
4183#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004184#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
Caveh Jalali024ffe32023-01-30 14:35:19 -08004185#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004186 (((fpe) & 0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004187#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4188#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
Caveh Jalali024ffe32023-01-30 14:35:19 -08004189#define EC_MKBP_FP_MATCH_IDX(fpe) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004190 (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
Caveh Jalali024ffe32023-01-30 14:35:19 -08004191#define EC_MKBP_FP_ENROLL BIT(27)
4192#define EC_MKBP_FP_MATCH BIT(28)
4193#define EC_MKBP_FP_FINGER_DOWN BIT(29)
4194#define EC_MKBP_FP_FINGER_UP BIT(30)
4195#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004196/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004197#define EC_MKBP_FP_ERR_ENROLL_OK 0
4198#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4199#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4200#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4201#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004202/* Can be used to detect if image was usable for enrollment or not. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004203#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004204/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004205#define EC_MKBP_FP_ERR_MATCH_NO 0
4206#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4207#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004208#define EC_MKBP_FP_ERR_MATCH_NO_AUTH_FAIL 8
Caveh Jalali024ffe32023-01-30 14:35:19 -08004209#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4210#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4211#define EC_MKBP_FP_ERR_MATCH_YES 1
4212#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004213#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4214
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004215#define EC_CMD_MKBP_WAKE_MASK 0x0069
4216enum ec_mkbp_event_mask_action {
4217 /* Retrieve the value of a wake mask. */
4218 GET_WAKE_MASK = 0,
4219
4220 /* Set the value of a wake mask. */
4221 SET_WAKE_MASK,
4222};
4223
4224enum ec_mkbp_mask_type {
4225 /*
4226 * These are host events sent via MKBP.
4227 *
4228 * Some examples are:
4229 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4230 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4231 *
4232 * The only things that should be in this mask are:
4233 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4234 */
4235 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4236
4237 /*
4238 * These are MKBP events. Some examples are:
4239 *
4240 * EC_MKBP_EVENT_KEY_MATRIX
4241 * EC_MKBP_EVENT_SWITCH
4242 *
4243 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4244 */
4245 EC_MKBP_EVENT_WAKE_MASK,
4246};
4247
4248struct ec_params_mkbp_event_wake_mask {
4249 /* One of enum ec_mkbp_event_mask_action */
4250 uint8_t action;
4251
4252 /*
4253 * Which MKBP mask are you interested in acting upon? This is one of
4254 * ec_mkbp_mask_type.
4255 */
4256 uint8_t mask_type;
4257
4258 /* If setting a new wake mask, this contains the mask to set. */
4259 uint32_t new_wake_mask;
4260};
4261
4262struct ec_response_mkbp_event_wake_mask {
4263 uint32_t wake_mask;
4264};
4265
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004266/*****************************************************************************/
4267/* Temperature sensor commands */
4268
4269/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004270#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004272struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004273 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004274} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004275
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004276struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004277 char sensor_name[32];
4278 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004279} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004280
4281/*****************************************************************************/
4282
4283/*
4284 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4285 * commands accidentally sent to the wrong interface. See the ACPI section
4286 * below.
4287 */
4288
4289/*****************************************************************************/
4290/* Host event commands */
4291
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004292/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004293/*
4294 * Host event mask params and response structures, shared by all of the host
4295 * event commands below.
4296 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004297struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004298 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004299} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004301struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004302 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004303} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004304
4305/* These all use ec_response_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004306#define EC_CMD_HOST_EVENT_GET_B 0x0087
4307#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4308#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004309#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004310
4311/* These all use ec_params_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004312#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4313#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4314#define EC_CMD_HOST_EVENT_CLEAR 0x008C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004315#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
Caveh Jalali024ffe32023-01-30 14:35:19 -08004316#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004317
Jenny TC1dfc2c32017-12-14 14:24:39 +05304318/*
4319 * Unified host event programming interface - Should be used by newer versions
4320 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004321 *
4322 * EC returns:
4323 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4324 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304325 */
4326
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004327struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304328 /* Action requested by host - one of enum ec_host_event_action. */
4329 uint8_t action;
4330
4331 /*
4332 * Mask type that the host requested the action on - one of
4333 * enum ec_host_event_mask_type.
4334 */
4335 uint8_t mask_type;
4336
4337 /* Set to 0, ignore on read */
4338 uint16_t reserved;
4339
4340 /* Value to be used in case of set operations. */
4341 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004342} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304343
4344/*
4345 * Response structure returned by EC_CMD_HOST_EVENT.
4346 * Update the value on a GET request. Set to 0 on GET/CLEAR
4347 */
4348
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004349struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304350 /* Mask value in case of get operation */
4351 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004352} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304353
4354enum ec_host_event_action {
4355 /*
4356 * params.value is ignored. Value of mask_type populated
4357 * in response.value
4358 */
4359 EC_HOST_EVENT_GET,
4360
4361 /* Bits in params.value are set */
4362 EC_HOST_EVENT_SET,
4363
4364 /* Bits in params.value are cleared */
4365 EC_HOST_EVENT_CLEAR,
4366};
4367
4368enum ec_host_event_mask_type {
4369
4370 /* Main host event copy */
4371 EC_HOST_EVENT_MAIN,
4372
4373 /* Copy B of host events */
4374 EC_HOST_EVENT_B,
4375
4376 /* SCI Mask */
4377 EC_HOST_EVENT_SCI_MASK,
4378
4379 /* SMI Mask */
4380 EC_HOST_EVENT_SMI_MASK,
4381
4382 /* Mask of events that should be always reported in hostevents */
4383 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4384
4385 /* Active wake mask */
4386 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4387
4388 /* Lazy wake mask for S0ix */
4389 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4390
4391 /* Lazy wake mask for S3 */
4392 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4393
4394 /* Lazy wake mask for S5 */
4395 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4396};
4397
Caveh Jalali024ffe32023-01-30 14:35:19 -08004398#define EC_CMD_HOST_EVENT 0x00A4
Jenny TC1dfc2c32017-12-14 14:24:39 +05304399
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004400/*****************************************************************************/
4401/* Switch commands */
4402
4403/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004404#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004405
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004406struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004407 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004408} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004409
4410/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004411#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004412#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004413
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004414/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004415struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004416 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004417} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004418
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004419/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004420struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004421 /* Flags to enable now */
4422 uint8_t now_flags;
4423
4424 /* Which flags to copy from now_flags */
4425 uint8_t now_mask;
4426
4427 /*
4428 * Flags to leave enabled in S3, if they're on at the S0->S3
4429 * transition. (Other flags will be disabled by the S0->S3
4430 * transition.)
4431 */
4432 uint8_t suspend_flags;
4433
4434 /* Which flags to copy from suspend_flags */
4435 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004436} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004437
4438/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004439struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004440 /* Flags to enable now */
4441 uint8_t now_flags;
4442
4443 /* Flags to leave enabled in S3 */
4444 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004445} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004446
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004447/*****************************************************************************/
4448/* GPIO commands. Only available on EC if write protect has been disabled. */
4449
4450/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004451#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004452
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004453struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004454 char name[32];
4455 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004456} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004457
4458/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004459#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004460
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004461/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004462struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004463 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004464} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004465
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004466struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004467 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004468} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004469
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004470/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004471struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004472 uint8_t subcmd;
4473 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004474 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004475 char name[32];
4476 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004477 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004478 uint8_t index;
4479 } get_info;
4480 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004481} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004482
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004483struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004484 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004485 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004486 uint8_t val;
4487 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004488 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004489 uint8_t val;
4490 char name[32];
4491 uint32_t flags;
4492 } get_info;
4493 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004494} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004495
4496enum gpio_get_subcmd {
4497 EC_GPIO_GET_BY_NAME = 0,
4498 EC_GPIO_GET_COUNT = 1,
4499 EC_GPIO_GET_INFO = 2,
4500};
4501
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004502/*****************************************************************************/
4503/* I2C commands. Only available when flash write protect is unlocked. */
4504
Duncan Laurie93e24442014-01-06 12:30:52 -08004505/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004506 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4507 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4508 *
4509 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004510 */
4511
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004512/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004513#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004514
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004515struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004516 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004517 uint8_t read_size; /* Either 8 or 16. */
4518 uint8_t port;
4519 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004520} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004521
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004522struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004523 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004524} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004525
4526/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004527#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004528
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004529struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004530 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004531 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004532 uint8_t write_size; /* Either 8 or 16. */
4533 uint8_t port;
4534 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004535} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004536
4537/*****************************************************************************/
4538/* Charge state commands. Only available when flash write protect unlocked. */
4539
Duncan Laurie93e24442014-01-06 12:30:52 -08004540/* Force charge state machine to stop charging the battery or force it to
4541 * discharge the battery.
4542 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004543#define EC_CMD_CHARGE_CONTROL 0x0096
Simon Glassd3870a22023-11-09 08:43:30 -07004544#define EC_VER_CHARGE_CONTROL 3
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004545
Duncan Laurie93e24442014-01-06 12:30:52 -08004546enum ec_charge_control_mode {
4547 CHARGE_CONTROL_NORMAL = 0,
4548 CHARGE_CONTROL_IDLE,
4549 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004550 /* Add no more entry below. */
4551 CHARGE_CONTROL_COUNT,
4552};
4553
Caveh Jalali024ffe32023-01-30 14:35:19 -08004554#define EC_CHARGE_MODE_TEXT \
4555 { \
4556 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4557 [CHARGE_CONTROL_IDLE] = "IDLE", \
4558 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
Scott Chao18141d8c2021-07-30 10:40:57 +08004559 }
4560
4561enum ec_charge_control_cmd {
4562 EC_CHARGE_CONTROL_CMD_SET = 0,
4563 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004564};
4565
Simon Glassd3870a22023-11-09 08:43:30 -07004566enum ec_charge_control_flag {
4567 EC_CHARGE_CONTROL_FLAG_NO_IDLE = BIT(0),
4568};
4569
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004570struct ec_params_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004571 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004572
4573 /* Below are the fields added in V2. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004574 uint8_t cmd; /* enum ec_charge_control_cmd. */
Simon Glassd3870a22023-11-09 08:43:30 -07004575 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
Scott Chao18141d8c2021-07-30 10:40:57 +08004576 /*
4577 * Lower and upper thresholds for battery sustainer. This struct isn't
4578 * named to avoid tainting foreign projects' name spaces.
4579 *
4580 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4581 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4582 * lower=-1, upper=-1.
4583 */
4584 struct {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004585 int8_t lower; /* Display SoC in percentage. */
4586 int8_t upper; /* Display SoC in percentage. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004587 } sustain_soc;
4588} __ec_align4;
4589
4590/* Added in v2 */
4591struct ec_response_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004592 uint32_t mode; /* enum charge_control_mode */
4593 struct { /* Battery sustainer thresholds */
Scott Chao18141d8c2021-07-30 10:40:57 +08004594 int8_t lower;
4595 int8_t upper;
4596 } sustain_soc;
Simon Glassd3870a22023-11-09 08:43:30 -07004597 uint8_t flags; /* enum ec_charge_control_flag (v3+) */
4598 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004599} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004600
4601/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004602
4603/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004604#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004605
4606/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004607 * Read data from the saved snapshot. If the subcmd parameter is
4608 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4609 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4610 * end of the previous snapshot.
4611 *
4612 * The params are only looked at in version >= 1 of this command. Prior
4613 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004614 *
4615 * Response is null-terminated string. Empty string, if there is no more
4616 * remaining output.
4617 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004618#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004619
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004620enum ec_console_read_subcmd {
4621 CONSOLE_READ_NEXT = 0,
4622 CONSOLE_READ_RECENT,
4623};
Duncan Laurieeb316852015-12-01 18:51:18 -08004624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004625struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004626 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004627} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004628
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00004629/* Print directly to EC console from host. */
4630#define EC_CMD_CONSOLE_PRINT 0x00AC
4631
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004632/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004633
4634/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004635 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004636 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004637 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4638 * EC_RES_SUCCESS if the command was successful.
4639 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004640 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004641#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004642
Caveh Jalali024ffe32023-01-30 14:35:19 -08004643#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004644
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004645struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004646 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004647} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004648
Duncan Laurie433432b2013-06-03 10:38:22 -07004649/*****************************************************************************/
4650/* USB port mux control. */
4651
4652/*
4653 * Switch USB mux or return to automatic switching.
4654 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004655#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004656
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004657struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004658 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004659} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004660
4661/*****************************************************************************/
4662/* LDOs / FETs control. */
4663
4664enum ec_ldo_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004665 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4666 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
Duncan Laurie433432b2013-06-03 10:38:22 -07004667};
4668
4669/*
4670 * Switch on/off a LDO.
4671 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004672#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004673
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004674struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004675 uint8_t index;
4676 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004677} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004678
4679/*
4680 * Get LDO state.
4681 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004682#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004683
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004684struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004685 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004686} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004687
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004688struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004689 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004690} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004691
4692/*****************************************************************************/
4693/* Power info. */
4694
4695/*
4696 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004697 *
4698 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004699 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004700#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004701
Jett Rinkba2edaf2020-01-14 11:49:06 -07004702/*
4703 * v1 of EC_CMD_POWER_INFO
4704 */
4705enum system_power_source {
4706 /*
4707 * Haven't established which power source is used yet,
4708 * or no presence signals are available
4709 */
4710 POWER_SOURCE_UNKNOWN = 0,
4711 /* System is running on battery alone */
4712 POWER_SOURCE_BATTERY = 1,
4713 /* System is running on A/C alone */
4714 POWER_SOURCE_AC = 2,
4715 /* System is running on A/C and battery */
4716 POWER_SOURCE_AC_BATTERY = 3,
4717};
4718
4719struct ec_response_power_info_v1 {
4720 /* enum system_power_source */
4721 uint8_t system_power_source;
4722 /* Battery state-of-charge, 0-100, 0 if not present */
4723 uint8_t battery_soc;
4724 /* AC Adapter 100% rating, Watts */
4725 uint8_t ac_adapter_100pct;
4726 /* AC Adapter 10ms rating, Watts */
4727 uint8_t ac_adapter_10ms;
4728 /* Battery 1C rating, derated */
4729 uint8_t battery_1cd;
4730 /* Rest of Platform average, Watts */
4731 uint8_t rop_avg;
4732 /* Rest of Platform peak, Watts */
4733 uint8_t rop_peak;
4734 /* Nominal charger efficiency, % */
4735 uint8_t nominal_charger_eff;
4736 /* Rest of Platform VR Average Efficiency, % */
4737 uint8_t rop_avg_eff;
4738 /* Rest of Platform VR Peak Efficiency, % */
4739 uint8_t rop_peak_eff;
4740 /* SoC VR Efficiency at Average level, % */
4741 uint8_t soc_avg_eff;
4742 /* SoC VR Efficiency at Peak level, % */
4743 uint8_t soc_peak_eff;
4744 /* Intel-specific items */
4745 struct {
4746 /* Battery's level of DBPT support: 0, 2 */
4747 uint8_t batt_dbpt_support_level;
4748 /*
4749 * Maximum peak power from battery (10ms), Watts
4750 * If DBPT is not supported, this is 0
4751 */
4752 uint8_t batt_dbpt_max_peak_power;
4753 /*
4754 * Sustained peak power from battery, Watts
4755 * If DBPT is not supported, this is 0
4756 */
4757 uint8_t batt_dbpt_sus_peak_power;
4758 } intel;
4759} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004760
4761/*****************************************************************************/
4762/* I2C passthru command */
4763
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004764#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004765
Duncan Laurie433432b2013-06-03 10:38:22 -07004766/* Read data; if not present, message is a write */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004767#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004768
4769/* Mask for address */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004770#define EC_I2C_ADDR_MASK 0x3ff
Duncan Laurie433432b2013-06-03 10:38:22 -07004771
Caveh Jalali024ffe32023-01-30 14:35:19 -08004772#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4773#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004774
4775/* Any error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004776#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
Duncan Laurie433432b2013-06-03 10:38:22 -07004777
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004778struct ec_params_i2c_passthru_msg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004779 uint16_t addr_flags; /* I2C peripheral address and flags */
4780 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004781} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004782
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004783struct ec_params_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004784 uint8_t port; /* I2C port number */
4785 uint8_t num_msgs; /* Number of messages */
Duncan Laurie433432b2013-06-03 10:38:22 -07004786 struct ec_params_i2c_passthru_msg msg[];
4787 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004788} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004789
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004790struct ec_response_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004791 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4792 uint8_t num_msgs; /* Number of messages processed */
4793 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004794} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004795
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004796/*****************************************************************************/
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004797/* AP hang detect */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004798#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004799
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004800#define EC_HANG_DETECT_MIN_TIMEOUT 5
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004801
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004802/* EC hang detect commands */
4803enum ec_hang_detect_cmds {
4804 /* Reload AP hang detect timer. */
4805 EC_HANG_DETECT_CMD_RELOAD = 0x0,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004806
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004807 /* Stop AP hang detect timer. */
4808 EC_HANG_DETECT_CMD_CANCEL = 0x1,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004809
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004810 /* Configure watchdog with given reboot timeout and
4811 * cancel currently running AP hand detect timer.
4812 */
4813 EC_HANG_DETECT_CMD_SET_TIMEOUT = 0x2,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004814
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004815 /* Get last hang status - whether the AP boot was clear or not */
4816 EC_HANG_DETECT_CMD_GET_STATUS = 0x3,
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004817
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004818 /* Clear last hang status. Called when AP is rebooting/shutting down
4819 * gracefully.
4820 */
4821 EC_HANG_DETECT_CMD_CLEAR_STATUS = 0x4
4822};
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004823
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004824struct ec_params_hang_detect {
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004825 uint16_t command; /* enum ec_hang_detect_cmds */
4826 /* Timeout in seconds before generating reboot */
4827 uint16_t reboot_timeout_sec;
4828} __ec_align2;
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004829
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004830/* Status codes that describe whether AP has boot normally or the hang has been
4831 * detected and EC has reset AP
4832 */
4833enum ec_hang_detect_status {
4834 EC_HANG_DETECT_AP_BOOT_NORMAL = 0x0,
4835 EC_HANG_DETECT_AP_BOOT_EC_WDT = 0x1,
4836 EC_HANG_DETECT_AP_BOOT_COUNT,
4837};
4838struct ec_response_hang_detect {
4839 uint8_t status; /* enum ec_hang_detect_status */
4840} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004841/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004842/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004843
4844/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004845 * This is the single catch-all host command to exchange data regarding the
4846 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004847 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004848#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004849
4850/* Subcommands for this host command */
4851enum charge_state_command {
4852 CHARGE_STATE_CMD_GET_STATE,
4853 CHARGE_STATE_CMD_GET_PARAM,
4854 CHARGE_STATE_CMD_SET_PARAM,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004855 CHARGE_STATE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004856};
4857
4858/*
4859 * Known param numbers are defined here. Ranges are reserved for board-specific
4860 * params, which are handled by the particular implementations.
4861 */
4862enum charge_state_params {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004863 /* charger voltage limit */
4864 CS_PARAM_CHG_VOLTAGE,
4865
4866 /* charger current limit */
4867 CS_PARAM_CHG_CURRENT,
4868
4869 /* charger input current limit */
4870 CS_PARAM_CHG_INPUT_CURRENT,
4871
4872 /* charger-specific status */
4873 CS_PARAM_CHG_STATUS,
4874
4875 /* charger-specific options */
4876 CS_PARAM_CHG_OPTION,
4877
4878 /*
4879 * Check if power is limited due to low battery and / or a
4880 * weak external charger. READ ONLY.
4881 */
4882 CS_PARAM_LIMIT_POWER,
4883
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004884 /* How many so far? */
4885 CS_NUM_BASE_PARAMS,
4886
4887 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4888 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4889 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4890
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004891 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4892 CS_PARAM_DEBUG_MIN = 0x20000,
4893 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4894 CS_PARAM_DEBUG_MANUAL_MODE,
4895 CS_PARAM_DEBUG_SEEMS_DEAD,
4896 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05004897 CS_PARAM_DEBUG_BATT_REMOVED, /* Deprecated */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004898 CS_PARAM_DEBUG_MANUAL_CURRENT,
4899 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4900 CS_PARAM_DEBUG_MAX = 0x2ffff,
4901
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004902 /* Other custom param ranges go here... */
4903};
4904
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004905struct ec_params_charge_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004906 uint8_t cmd; /* enum charge_state_command */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004907 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004908 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004909
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004910 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004911 uint32_t param; /* enum charge_state_param */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004912 } get_param;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004913
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004914 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004915 uint32_t param; /* param to set */
4916 uint32_t value; /* value to set */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004917 } set_param;
4918 } __ec_todo_packed;
Caveh Jalali024ffe32023-01-30 14:35:19 -08004919 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004920} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004921
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004922struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004923 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004924 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004925 int ac;
4926 int chg_voltage;
4927 int chg_current;
4928 int chg_input_current;
4929 int batt_state_of_charge;
4930 } get_state;
4931
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004932 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004933 uint32_t value;
4934 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004935
4936 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004937 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004938} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004939
Duncan Laurie433432b2013-06-03 10:38:22 -07004940/*
4941 * Set maximum battery charging current.
4942 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004943#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Tim Van Pattencab60602023-02-24 12:27:04 -07004944#define EC_VER_CHARGE_CURRENT_LIMIT 1
Duncan Laurie433432b2013-06-03 10:38:22 -07004945
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004946struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004947 uint32_t limit; /* in mA */
Caveh Jalali839ada12022-10-31 23:16:48 -07004948} __ec_align4;
Tim Van Pattencab60602023-02-24 12:27:04 -07004949
Caveh Jalali839ada12022-10-31 23:16:48 -07004950struct ec_params_current_limit_v1 {
4951 uint32_t limit; /* in mA */
Tim Van Pattencab60602023-02-24 12:27:04 -07004952 /*
4953 * Battery state of charge is the minimum charge percentage at which
4954 * the battery charge current limit will apply.
4955 * When not set, the limit will apply regardless of state of charge.
4956 */
4957 uint8_t battery_soc; /* battery state of charge, 0-100 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004958} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004959
4960/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004961 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004962 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004963#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004964
Duncan Laurieeb316852015-12-01 18:51:18 -08004965/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004966struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004967 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4968 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004969} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004970
Duncan Laurieeb316852015-12-01 18:51:18 -08004971#define EC_POWER_LIMIT_NONE 0xffff
4972
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004973/*
4974 * Set maximum voltage & current of a dedicated charge port
4975 */
4976#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4977
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004978struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004979 uint16_t current_lim; /* in mA */
4980 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004981} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004982
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08004983/*
4984 * Get and set charging splashscreen variables
4985 */
4986#define EC_CMD_CHARGESPLASH 0x00A5
4987
4988enum ec_chargesplash_cmd {
4989 /* Get the current state variables */
4990 EC_CHARGESPLASH_GET_STATE = 0,
4991
4992 /* Indicate initialization of the display loop */
4993 EC_CHARGESPLASH_DISPLAY_READY,
4994
4995 /* Manually put the EC into the requested state */
4996 EC_CHARGESPLASH_REQUEST,
4997
4998 /* Reset all state variables */
4999 EC_CHARGESPLASH_RESET,
5000
5001 /* Manually trigger a lockout */
5002 EC_CHARGESPLASH_LOCKOUT,
5003};
5004
5005struct __ec_align1 ec_params_chargesplash {
5006 /* enum ec_chargesplash_cmd */
5007 uint8_t cmd;
5008};
5009
5010struct __ec_align1 ec_response_chargesplash {
5011 uint8_t requested;
5012 uint8_t display_initialized;
5013 uint8_t locked_out;
5014};
5015
Duncan Laurieeb316852015-12-01 18:51:18 -08005016/*****************************************************************************/
5017/* Hibernate/Deep Sleep Commands */
5018
5019/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005020#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08005021
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005022struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08005023 /*
5024 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
5025 * current settings without changing them.
5026 */
5027 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005028} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005029
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005030struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08005031 /*
5032 * The current time in seconds in which the system has been in the G3
5033 * state. This value is reset if the EC transitions out of G3.
5034 */
5035 uint32_t time_g3;
5036
5037 /*
5038 * The current time remaining in seconds until the EC should hibernate.
5039 * This value is also reset if the EC transitions out of G3.
5040 */
5041 uint32_t time_remaining;
5042
5043 /*
5044 * The current time in seconds that the EC should wait in G3 before
5045 * hibernating.
5046 */
5047 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005048} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005049
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005050/* Inform the EC when entering a sleep state */
5051#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
5052
5053enum host_sleep_event {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005054 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
5055 HOST_SLEEP_EVENT_S3_RESUME = 2,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005056 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005057 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005058 /* S3 suspend with additional enabled wake sources */
5059 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005060};
5061
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005062struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005063 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005064} __ec_align1;
5065
5066/*
5067 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
5068 * transition failures
5069 */
5070#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
5071
5072/* Disable timeout detection for this sleep transition */
5073#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
5074
5075struct ec_params_host_sleep_event_v1 {
5076 /* The type of sleep being entered or exited. */
5077 uint8_t sleep_event;
5078
5079 /* Padding */
5080 uint8_t reserved;
5081 union {
5082 /* Parameters that apply for suspend messages. */
5083 struct {
5084 /*
5085 * The timeout in milliseconds between when this message
5086 * is received and when the EC will declare sleep
5087 * transition failure if the sleep signal is not
5088 * asserted.
5089 */
5090 uint16_t sleep_timeout_ms;
5091 } suspend_params;
5092
5093 /* No parameters for non-suspend messages. */
5094 };
5095} __ec_align2;
5096
5097/* A timeout occurred when this bit is set */
5098#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
5099
5100/*
5101 * The mask defining which bits correspond to the number of sleep transitions,
5102 * as well as the maximum number of suspend line transitions that will be
5103 * reported back to the host.
5104 */
5105#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
5106
5107struct ec_response_host_sleep_event_v1 {
5108 union {
5109 /* Response fields that apply for resume messages. */
5110 struct {
5111 /*
5112 * The number of sleep power signal transitions that
5113 * occurred since the suspend message. The high bit
5114 * indicates a timeout occurred.
5115 */
5116 uint32_t sleep_transitions;
5117 } resume_response;
5118
5119 /* No response fields for non-resume messages. */
5120 };
5121} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005122
5123/*****************************************************************************/
5124/* Device events */
5125#define EC_CMD_DEVICE_EVENT 0x00AA
5126
5127enum ec_device_event {
5128 EC_DEVICE_EVENT_TRACKPAD,
5129 EC_DEVICE_EVENT_DSP,
5130 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005131 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005132};
5133
5134enum ec_device_event_param {
5135 /* Get and clear pending device events */
5136 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
5137 /* Get device event mask */
5138 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
5139 /* Set device event mask */
5140 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
5141};
5142
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005143#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005144
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005145struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005146 uint32_t event_mask;
5147 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005148} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005150struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005151 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005152} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005153
Duncan Laurie433432b2013-06-03 10:38:22 -07005154/*****************************************************************************/
Caveh Jalali839ada12022-10-31 23:16:48 -07005155/* Get s0ix counter */
5156#define EC_CMD_GET_S0IX_COUNTER 0x00AB
5157
5158/* Flag use to reset the counter */
5159#define EC_S0IX_COUNTER_RESET 0x1
5160
5161struct ec_params_s0ix_cnt {
5162 /* If EC_S0IX_COUNTER_RESET then reset otherwise get the counter */
5163 uint32_t flags;
5164} __ec_align4;
5165
5166struct ec_response_s0ix_cnt {
5167 /* Value of the s0ix_counter */
5168 uint32_t s0ix_counter;
5169} __ec_align4;
5170
5171/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07005172/* Smart battery pass-through */
5173
Caveh Jalali839ada12022-10-31 23:16:48 -07005174/* Get / Set 16-bit smart battery registers - OBSOLETE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005175#define EC_CMD_SB_READ_WORD 0x00B0
5176#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07005177
5178/* Get / Set string smart battery parameters
Caveh Jalali839ada12022-10-31 23:16:48 -07005179 * formatted as SMBUS "block". - OBSOLETE
Duncan Laurie433432b2013-06-03 10:38:22 -07005180 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005181#define EC_CMD_SB_READ_BLOCK 0x00B2
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005182#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07005183
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005184/*****************************************************************************/
5185/* Battery vendor parameters
5186 *
5187 * Get or set vendor-specific parameters in the battery. Implementations may
5188 * differ between boards or batteries. On a set operation, the response
5189 * contains the actual value set, which may be rounded or clipped from the
5190 * requested value.
5191 */
5192
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005193#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005194
5195enum ec_battery_vendor_param_mode {
5196 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5197 BATTERY_VENDOR_PARAM_MODE_SET,
5198};
5199
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005200struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005201 uint32_t param;
5202 uint32_t value;
5203 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005204} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005205
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005206struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005207 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005208} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005209
5210/*****************************************************************************/
5211/*
Caveh Jalali839ada12022-10-31 23:16:48 -07005212 * Smart Battery Firmware Update Command - OBSOLETE
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005213 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005214#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005215
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005216/*
5217 * Entering Verified Boot Mode Command
5218 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5219 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07005220 *
5221 * EC no longer needs to know what mode vboot has entered,
5222 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005223 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005224#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005225
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005226struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005227 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005228} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005229
Caveh Jalali024ffe32023-01-30 14:35:19 -08005230#define VBOOT_MODE_NORMAL 0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005231#define VBOOT_MODE_DEVELOPER 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08005232#define VBOOT_MODE_RECOVERY 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005233
Duncan Laurie433432b2013-06-03 10:38:22 -07005234/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07005235/*
5236 * I2C passthru protection command: Protects I2C tunnels against access on
5237 * certain addresses (board-specific).
5238 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005239#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07005240
5241enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005242 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5243 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5244 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005245};
5246
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005247struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005248 uint8_t subcmd;
Caveh Jalali024ffe32023-01-30 14:35:19 -08005249 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005250} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005251
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005252struct ec_response_i2c_passthru_protect {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005253 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005254} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005255
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005256/*****************************************************************************/
5257/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005258 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005259 *
5260 * These commands are for sending and receiving message via HDMI CEC
5261 */
5262
Simon Glassd3870a22023-11-09 08:43:30 -07005263#define EC_CEC_MAX_PORTS 16
5264
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005265#define MAX_CEC_MSG_LEN 16
5266
Simon Glassd3870a22023-11-09 08:43:30 -07005267/*
5268 * Helper macros for packing/unpacking cec_events.
5269 * bits[27:0] : bitmask of events from enum mkbp_cec_event
5270 * bits[31:28]: port number
5271 */
5272#define EC_MKBP_EVENT_CEC_PACK(events, port) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05005273 (((events) & GENMASK(27, 0)) | (((port) & 0xf) << 28))
5274#define EC_MKBP_EVENT_CEC_GET_EVENTS(event) ((event) & GENMASK(27, 0))
Simon Glassd3870a22023-11-09 08:43:30 -07005275#define EC_MKBP_EVENT_CEC_GET_PORT(event) (((event) >> 28) & 0xf)
5276
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005277/* CEC message from the AP to be written on the CEC bus */
5278#define EC_CMD_CEC_WRITE_MSG 0x00B8
5279
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005280/**
5281 * struct ec_params_cec_write - Message to write to the CEC bus
5282 * @msg: message content to write to the CEC bus
5283 */
5284struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005285 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005286} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005287
Simon Glassd3870a22023-11-09 08:43:30 -07005288/**
5289 * struct ec_params_cec_write_v1 - Message to write to the CEC bus
5290 * @port: CEC port to write the message on
5291 * @msg_len: length of msg in bytes
5292 * @msg: message content to write to the CEC bus
5293 */
5294struct ec_params_cec_write_v1 {
5295 uint8_t port;
5296 uint8_t msg_len;
5297 uint8_t msg[MAX_CEC_MSG_LEN];
5298} __ec_align1;
5299
5300/* CEC message read from a CEC bus reported back to the AP */
5301#define EC_CMD_CEC_READ_MSG 0x00B9
5302
5303/**
5304 * struct ec_params_cec_read - Read a message from the CEC bus
5305 * @port: CEC port to read a message on
5306 */
5307struct ec_params_cec_read {
5308 uint8_t port;
5309} __ec_align1;
5310
5311/**
5312 * struct ec_response_cec_read - Message read from the CEC bus
5313 * @msg_len: length of msg in bytes
5314 * @msg: message content read from the CEC bus
5315 */
5316struct ec_response_cec_read {
5317 uint8_t msg_len;
5318 uint8_t msg[MAX_CEC_MSG_LEN];
5319} __ec_align1;
5320
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005321/* Set various CEC parameters */
5322#define EC_CMD_CEC_SET 0x00BA
5323
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005324/**
5325 * struct ec_params_cec_set - CEC parameters set
5326 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
Simon Glassd3870a22023-11-09 08:43:30 -07005327 * @port: CEC port to set the parameter on
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005328 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5329 * or 1 to enable CEC functionality, in case cmd is
5330 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5331 * address between 0 and 15 or 0xff to unregister
5332 */
5333struct ec_params_cec_set {
Simon Glassd3870a22023-11-09 08:43:30 -07005334 uint8_t cmd : 4; /* enum cec_command */
5335 uint8_t port : 4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005336 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005337} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005338
5339/* Read various CEC parameters */
5340#define EC_CMD_CEC_GET 0x00BB
5341
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005342/**
5343 * struct ec_params_cec_get - CEC parameters get
5344 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
Simon Glassd3870a22023-11-09 08:43:30 -07005345 * @port: CEC port to get the parameter on
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005346 */
5347struct ec_params_cec_get {
Simon Glassd3870a22023-11-09 08:43:30 -07005348 uint8_t cmd : 4; /* enum cec_command */
5349 uint8_t port : 4;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005350} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005351
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005352/**
5353 * struct ec_response_cec_get - CEC parameters get response
5354 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5355 * disabled or 1 if CEC functionality is enabled,
5356 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5357 * configured logical address between 0 and 15 or 0xff if unregistered
5358 */
5359struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005360 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005361} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005362
Simon Glassd3870a22023-11-09 08:43:30 -07005363/* Get the number of CEC ports */
5364#define EC_CMD_CEC_PORT_COUNT 0x00C1
5365
5366/**
5367 * struct ec_response_cec_port_count - CEC port count response
5368 * @port_count: number of CEC ports
5369 */
5370struct ec_response_cec_port_count {
5371 uint8_t port_count;
5372} __ec_align1;
5373
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005374/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005375enum cec_command {
5376 /* CEC reading, writing and events enable */
5377 CEC_CMD_ENABLE,
5378 /* CEC logical address */
5379 CEC_CMD_LOGICAL_ADDRESS,
5380};
5381
5382/* Events from CEC to AP */
5383enum mkbp_cec_event {
5384 /* Outgoing message was acknowledged by a follower */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005385 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005386 /* Outgoing message was not acknowledged */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005387 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Simon Glassd3870a22023-11-09 08:43:30 -07005388 /* Incoming message can be read out by AP */
5389 EC_MKBP_CEC_HAVE_DATA = BIT(2),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005390};
5391
Gwendal Grignou880b4582016-06-20 08:49:25 -07005392/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005393
Jett Rinkba2edaf2020-01-14 11:49:06 -07005394/* Commands for audio codec. */
5395#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005396
Jett Rinkba2edaf2020-01-14 11:49:06 -07005397enum ec_codec_subcmd {
5398 EC_CODEC_GET_CAPABILITIES = 0x0,
5399 EC_CODEC_GET_SHM_ADDR = 0x1,
5400 EC_CODEC_SET_SHM_ADDR = 0x2,
5401 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005402};
5403
Jett Rinkba2edaf2020-01-14 11:49:06 -07005404enum ec_codec_cap {
5405 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5406 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5407 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005408};
5409
Jett Rinkba2edaf2020-01-14 11:49:06 -07005410enum ec_codec_shm_id {
5411 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5412 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5413 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005414};
5415
Jett Rinkba2edaf2020-01-14 11:49:06 -07005416enum ec_codec_shm_type {
5417 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5418 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005419};
5420
Jett Rinkba2edaf2020-01-14 11:49:06 -07005421struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5422 uint8_t shm_id;
5423 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005424};
5425
Jett Rinkba2edaf2020-01-14 11:49:06 -07005426struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5427 uint64_t phys_addr;
5428 uint32_t len;
5429 uint8_t shm_id;
5430 uint8_t reserved[3];
5431};
5432
5433struct __ec_align4 ec_param_ec_codec {
5434 uint8_t cmd; /* enum ec_codec_subcmd */
5435 uint8_t reserved[3];
5436
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005437 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005438 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5439 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005440 };
5441};
5442
Jett Rinkba2edaf2020-01-14 11:49:06 -07005443struct __ec_align4 ec_response_ec_codec_get_capabilities {
5444 uint32_t capabilities;
5445};
5446
5447struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5448 uint64_t phys_addr;
5449 uint32_t len;
5450 uint8_t type;
5451 uint8_t reserved[3];
5452};
5453
5454/*****************************************************************************/
5455
5456/* Commands for DMIC on audio codec. */
5457#define EC_CMD_EC_CODEC_DMIC 0x00BD
5458
5459enum ec_codec_dmic_subcmd {
5460 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5461 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5462 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5463 EC_CODEC_DMIC_SUBCMD_COUNT,
5464};
5465
5466enum ec_codec_dmic_channel {
5467 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5468 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5469 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5470 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5471 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5472 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5473 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5474 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5475 EC_CODEC_DMIC_CHANNEL_COUNT,
5476};
5477
5478struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5479 uint8_t channel; /* enum ec_codec_dmic_channel */
5480 uint8_t gain;
5481 uint8_t reserved[2];
5482};
5483
5484struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5485 uint8_t channel; /* enum ec_codec_dmic_channel */
5486 uint8_t reserved[3];
5487};
5488
5489struct __ec_align4 ec_param_ec_codec_dmic {
5490 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5491 uint8_t reserved[3];
5492
5493 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005494 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5495 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005496 };
5497};
5498
5499struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5500 uint8_t max_gain;
5501};
5502
5503struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5504 uint8_t gain;
5505};
5506
5507/*****************************************************************************/
5508
5509/* Commands for I2S RX on audio codec. */
5510
5511#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5512
5513enum ec_codec_i2s_rx_subcmd {
5514 EC_CODEC_I2S_RX_ENABLE = 0x0,
5515 EC_CODEC_I2S_RX_DISABLE = 0x1,
5516 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5517 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5518 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005519 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005520 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5521};
5522
5523enum ec_codec_i2s_rx_sample_depth {
5524 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5525 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5526 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5527};
5528
5529enum ec_codec_i2s_rx_daifmt {
5530 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5531 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5532 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5533 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5534};
5535
5536struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5537 uint8_t depth;
5538 uint8_t reserved[3];
5539};
5540
5541struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5542 uint8_t left;
5543 uint8_t right;
5544 uint8_t reserved[2];
5545};
5546
5547struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5548 uint8_t daifmt;
5549 uint8_t reserved[3];
5550};
5551
5552struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5553 uint32_t bclk;
5554};
5555
5556struct __ec_align4 ec_param_ec_codec_i2s_rx {
5557 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5558 uint8_t reserved[3];
5559
5560 union {
5561 struct ec_param_ec_codec_i2s_rx_set_sample_depth
Caveh Jalali024ffe32023-01-30 14:35:19 -08005562 set_sample_depth_param;
5563 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5564 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005565 };
5566};
5567
5568/*****************************************************************************/
5569/* Commands for WoV on audio codec. */
5570
5571#define EC_CMD_EC_CODEC_WOV 0x00BF
5572
5573enum ec_codec_wov_subcmd {
5574 EC_CODEC_WOV_SET_LANG = 0x0,
5575 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5576 EC_CODEC_WOV_GET_LANG = 0x2,
5577 EC_CODEC_WOV_ENABLE = 0x3,
5578 EC_CODEC_WOV_DISABLE = 0x4,
5579 EC_CODEC_WOV_READ_AUDIO = 0x5,
5580 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5581 EC_CODEC_WOV_SUBCMD_COUNT,
5582};
5583
5584/*
5585 * @hash is SHA256 of the whole language model.
5586 * @total_len indicates the length of whole language model.
5587 * @offset is the cursor from the beginning of the model.
5588 * @buf is the packet buffer.
5589 * @len denotes how many bytes in the buf.
5590 */
5591struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5592 uint8_t hash[32];
5593 uint32_t total_len;
5594 uint32_t offset;
5595 uint8_t buf[128];
5596 uint32_t len;
5597};
5598
5599struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5600 uint8_t hash[32];
5601 uint32_t total_len;
5602};
5603
5604struct __ec_align4 ec_param_ec_codec_wov {
5605 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5606 uint8_t reserved[3];
5607
5608 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005609 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5610 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005611 };
5612};
5613
5614struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5615 uint8_t hash[32];
5616};
5617
5618struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5619 uint8_t buf[128];
5620 uint32_t len;
5621};
5622
5623struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5624 uint32_t offset;
5625 uint32_t len;
5626};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005627
5628/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005629/* Commands for PoE PSE controller */
5630
5631#define EC_CMD_PSE 0x00C0
5632
5633enum ec_pse_subcmd {
5634 EC_PSE_STATUS = 0x0,
5635 EC_PSE_ENABLE = 0x1,
5636 EC_PSE_DISABLE = 0x2,
5637 EC_PSE_SUBCMD_COUNT,
5638};
5639
5640struct __ec_align1 ec_params_pse {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005641 uint8_t cmd; /* enum ec_pse_subcmd */
5642 uint8_t port; /* PSE port */
Yidi Lin42f79592020-09-21 18:04:10 +08005643};
5644
5645enum ec_pse_status {
5646 EC_PSE_STATUS_DISABLED = 0x0,
5647 EC_PSE_STATUS_ENABLED = 0x1,
5648 EC_PSE_STATUS_POWERED = 0x2,
5649};
5650
5651struct __ec_align1 ec_response_pse_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005652 uint8_t status; /* enum ec_pse_status */
Yidi Lin42f79592020-09-21 18:04:10 +08005653};
5654
5655/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005656/* System commands */
5657
5658/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005659 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5660 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005661 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005662#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005663
5664/* Command */
5665enum ec_reboot_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005666 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5667 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5668 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005669 /* (command 3 was jump to RW-B) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005670 EC_REBOOT_COLD = 4, /* Cold-reboot */
5671 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5672 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005673 /*
5674 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5675 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5676 */
5677 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005678 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5679 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005680};
5681
5682/* Flags for ec_params_reboot_ec.reboot_flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005683#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5684#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5685#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5686#define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005687
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005688struct ec_params_reboot_ec {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005689 uint8_t cmd; /* enum ec_reboot_cmd */
5690 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005691} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005692
Duncan Laurie433432b2013-06-03 10:38:22 -07005693/*
5694 * Get information on last EC panic.
5695 *
5696 * Returns variable-length platform-dependent panic information. See panic.h
5697 * for details.
5698 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005699#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005700
Simon Glassd3870a22023-11-09 08:43:30 -07005701struct ec_params_get_panic_info_v1 {
5702 /* Do not modify PANIC_DATA_FLAG_OLD_HOSTCMD when reading panic info */
5703 uint8_t preserve_old_hostcmd_flag;
5704} __ec_align1;
5705
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005706/*****************************************************************************/
5707/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005708 * Special commands
5709 *
5710 * These do not follow the normal rules for commands. See each command for
5711 * details.
5712 */
5713
5714/*
5715 * Reboot NOW
5716 *
5717 * This command will work even when the EC LPC interface is busy, because the
5718 * reboot command is processed at interrupt level. Note that when the EC
5719 * reboots, the host will reboot too, so there is no response to this command.
5720 *
5721 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5722 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005723#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005724
5725/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005726 * Resend last response (not supported on LPC).
5727 *
5728 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5729 * there was no previous command, or the previous command's response was too
5730 * big to save.
5731 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005732#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005733
5734/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005735 * This header byte on a command indicate version 0. Any header byte less
5736 * than this means that we are talking to an old EC which doesn't support
5737 * versioning. In that case, we assume version 0.
5738 *
5739 * Header bytes greater than this indicate a later version. For example,
5740 * EC_CMD_VERSION0 + 1 means we are using version 1.
5741 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005742 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005743 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005744#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005745
Caveh Jalali839ada12022-10-31 23:16:48 -07005746/*
5747 * Memory Dump Commands
5748 *
5749 * Since the HOSTCMD response size is limited, depending on the
5750 * protocol, retrieving a memory dump is split into 3 commands.
5751 *
5752 * 1. EC_CMD_MEMORY_DUMP_GET_METADATA returns the number of memory dump entries,
5753 * and the total dump size.
5754 * 2. EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO returns the address and size for a given
5755 * memory dump entry index.
5756 * 3. EC_CMD_MEMORY_DUMP_READ_MEMORY returns the actual memory at a given
5757 * address. The address and size must be within the bounds of the given
5758 * memory dump entry index. Each response is limited to the max response size
5759 * of the host protocol, so this may need to be called repeatedly to retrieve
5760 * the entire memory dump entry.
5761 *
5762 * Memory entries may overlap and may be out of order.
5763 * The host should check for overlaps to optimize transfer rate.
5764 */
5765#define EC_CMD_MEMORY_DUMP_GET_METADATA 0x00DD
5766struct ec_response_memory_dump_get_metadata {
5767 uint16_t memory_dump_entry_count;
5768 uint32_t memory_dump_total_size;
5769} __ec_align4;
5770
5771#define EC_CMD_MEMORY_DUMP_GET_ENTRY_INFO 0x00DE
5772struct ec_params_memory_dump_get_entry_info {
5773 uint16_t memory_dump_entry_index;
5774} __ec_align4;
5775
5776struct ec_response_memory_dump_get_entry_info {
5777 uint32_t address;
5778 uint32_t size;
5779} __ec_align4;
5780
5781#define EC_CMD_MEMORY_DUMP_READ_MEMORY 0x00DF
5782
5783struct ec_params_memory_dump_read_memory {
5784 uint16_t memory_dump_entry_index;
5785 uint32_t address;
5786 uint32_t size;
5787} __ec_align4;
5788
5789/*
5790 * EC_CMD_MEMORY_DUMP_READ_MEMORY response buffer is written directly into
5791 * host_cmd_handler_args.response and host_cmd_handler_args.response_size.
5792 */
5793
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005794/*****************************************************************************/
5795/*
5796 * PD commands
5797 *
5798 * These commands are for PD MCU communication.
5799 */
5800
5801/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005802#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005803#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005804
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005805enum pd_charge_state {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005806 /* Don't change charge state */
5807 PD_CHARGE_NO_CHANGE = 0,
5808
5809 /* No charging allowed */
5810 PD_CHARGE_NONE,
5811
5812 /* 5V charging only */
5813 PD_CHARGE_5V,
5814
5815 /* Charge at max voltage */
5816 PD_CHARGE_MAX,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005817};
5818
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005819/* Status of EC being sent to PD */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005820#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005821
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005822struct ec_params_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005823 /* EC status */
5824 uint8_t status;
5825
5826 /* battery state of charge */
5827 int8_t batt_soc;
5828
5829 /* charging state (from enum pd_charge_state) */
5830 uint8_t charge_state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005831} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005832
5833/* Status of PD being sent back to EC */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005834#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5835#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005836#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005837#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5838#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5839#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5840#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
5841#define PD_STATUS_EC_INT_ACTIVE \
5842 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005843struct ec_response_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005844 /* input current limit */
5845 uint32_t curr_lim_ma;
5846
5847 /* PD MCU status */
5848 uint16_t status;
5849
5850 /* active charging port */
5851 int8_t active_charge_port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005852} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005853
5854/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005855#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005856
5857/* PD MCU host event status bits */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005858#define PD_EVENT_UPDATE_DEVICE BIT(0)
5859#define PD_EVENT_POWER_CHANGE BIT(1)
5860#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5861#define PD_EVENT_DATA_SWAP BIT(3)
5862#define PD_EVENT_TYPEC BIT(4)
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00005863#define PD_EVENT_PPM BIT(5)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005864
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005865struct ec_response_host_event_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005866 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005867} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005868
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005869/*
5870 * Set USB type-C port role and muxes
5871 *
5872 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5873 *
5874 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5875 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005876#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005877
5878enum usb_pd_control_role {
5879 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5880 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5881 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5882 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5883 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005884 USB_PD_CTRL_ROLE_FREEZE = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005885 USB_PD_CTRL_ROLE_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005886};
5887
5888enum usb_pd_control_mux {
5889 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5890 USB_PD_CTRL_MUX_NONE = 1,
5891 USB_PD_CTRL_MUX_USB = 2,
5892 USB_PD_CTRL_MUX_DP = 3,
5893 USB_PD_CTRL_MUX_DOCK = 4,
5894 USB_PD_CTRL_MUX_AUTO = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005895 USB_PD_CTRL_MUX_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005896};
5897
Duncan Laurieeb316852015-12-01 18:51:18 -08005898enum usb_pd_control_swap {
5899 USB_PD_CTRL_SWAP_NONE = 0,
5900 USB_PD_CTRL_SWAP_DATA = 1,
5901 USB_PD_CTRL_SWAP_POWER = 2,
5902 USB_PD_CTRL_SWAP_VCONN = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005903 USB_PD_CTRL_SWAP_COUNT,
Duncan Laurieeb316852015-12-01 18:51:18 -08005904};
5905
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005906struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005907 uint8_t port;
5908 uint8_t role;
5909 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005910 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005911} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005912
Caveh Jalali024ffe32023-01-30 14:35:19 -08005913#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5914#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005915#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005916
Caveh Jalali024ffe32023-01-30 14:35:19 -08005917#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5918#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5919#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5920#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5921#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5922#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005923/* Partner unconstrained power */
5924#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
Duncan Laurieeb316852015-12-01 18:51:18 -08005925
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005926struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005927 uint8_t enabled;
5928 uint8_t role;
5929 uint8_t polarity;
5930 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005931} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005932
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005933struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005934 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005935 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005936 uint8_t polarity;
5937 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005938} __ec_align1;
5939
Jett Rinkba2edaf2020-01-14 11:49:06 -07005940/* Possible port partner connections based on CC line states */
5941enum pd_cc_states {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005942 PD_CC_NONE = 0, /* No port partner attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005943
5944 /* From DFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005945 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
5946 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5947 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5948 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005949
5950 /* From UFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005951 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
5952 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005953};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005954
Jett Rinkba2edaf2020-01-14 11:49:06 -07005955/* Active/Passive Cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005956#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005957/* Optical/Non-optical cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005958#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005959/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005960#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005961/* Active Link Uni-Direction */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005962#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Caveh Jalali839ada12022-10-31 23:16:48 -07005963/* Retimer/Redriver cable */
5964#define USB_PD_CTRL_RETIMER_CABLE BIT(4)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005965
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005966struct ec_response_usb_pd_control_v2 {
5967 uint8_t enabled;
5968 uint8_t role;
5969 uint8_t polarity;
5970 char state[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08005971 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5972 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
5973 uint8_t reserved; /* Reserved for future use */
5974 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5975 uint8_t cable_speed; /* TBT_SS_* cable speed */
5976 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005977} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005978
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005979#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005980
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005981/* Maximum number of PD ports on a device, num_ports will be <= this */
5982#define EC_USB_PD_MAX_PORTS 8
5983
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005984struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005985 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005986} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005987
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005988#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005989
5990#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005991struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005992 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005993} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005994
5995enum usb_chg_type {
5996 USB_CHG_TYPE_NONE,
5997 USB_CHG_TYPE_PD,
5998 USB_CHG_TYPE_C,
5999 USB_CHG_TYPE_PROPRIETARY,
6000 USB_CHG_TYPE_BC12_DCP,
6001 USB_CHG_TYPE_BC12_CDP,
6002 USB_CHG_TYPE_BC12_SDP,
6003 USB_CHG_TYPE_OTHER,
6004 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08006005 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006006 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006007};
6008enum usb_power_roles {
6009 USB_PD_PORT_POWER_DISCONNECTED,
6010 USB_PD_PORT_POWER_SOURCE,
6011 USB_PD_PORT_POWER_SINK,
6012 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
6013};
6014
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006015struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006016 uint16_t voltage_max;
6017 uint16_t voltage_now;
6018 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08006019 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006020} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006021
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006022struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006023 uint8_t role;
6024 uint8_t type;
6025 uint8_t dualrole;
6026 uint8_t reserved1;
6027 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006028 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006029} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006030
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006031/*
6032 * This command will return the number of USB PD charge port + the number
6033 * of dedicated port present.
6034 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
6035 */
6036#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006037struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006038 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006039} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006040
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006041/*
6042 * This command enable/disable dynamic PDO selection.
6043 */
6044#define EC_CMD_USB_PD_DPS_CONTROL 0x0106
6045
6046struct ec_params_usb_pd_dps_control {
6047 uint8_t enable;
6048} __ec_align1;
6049
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006050/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006051#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006052
6053enum usb_pd_fw_update_cmds {
6054 USB_PD_FW_REBOOT,
6055 USB_PD_FW_FLASH_ERASE,
6056 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006057 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006058};
6059
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006060struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006061 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006062 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006063 uint8_t port;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006064
6065 /* Size to write in bytes */
6066 uint32_t size;
6067
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006068 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006069} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006070
6071/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006072#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006073/* RW hash is first 20 bytes of SHA-256 of RW section */
6074#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006075struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006076 uint16_t dev_id;
6077 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006078
6079 /*
6080 * Reserved for alignment of current_image
6081 * TODO(rspangler) but it's not aligned!
6082 * Should have been reserved[2].
6083 */
6084 uint8_t reserved;
6085
6086 /* One of ec_image */
6087 uint32_t current_image;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006088} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006089
6090/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006091#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006092
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006093struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006094 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006095} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006096
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006097/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006098#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006099struct ec_params_usb_pd_discovery_entry {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006100 uint16_t vid; /* USB-IF VID */
6101 uint16_t pid; /* USB-IF PID */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006102 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006103} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006104
6105/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006106#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006107
6108/* Negative port parameters have special meaning */
6109enum usb_pd_override_ports {
Simon Glassd3870a22023-11-09 08:43:30 -07006110 /*
6111 * DONT_CHARGE is for all ports. Thus it's persistent across plug-in
6112 * or plug-out.
6113 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006114 OVERRIDE_DONT_CHARGE = -2,
6115 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07006116 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006117};
6118
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006119struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006120 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006121} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006122
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006123/*
6124 * Read (and delete) one entry of PD event log.
6125 * TODO(crbug.com/751742): Make this host command more generic to accommodate
6126 * future non-PD logs that use the same internal EC event_log.
6127 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006128#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006129
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006130struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006131 uint32_t timestamp; /* relative timestamp in milliseconds */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006132 uint8_t type; /* event type : see PD_EVENT_xx below */
6133 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
6134 uint16_t data; /* type-defined data payload */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006135 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006136} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006137
6138/* The timestamp is the microsecond counter shifted to get about a ms. */
6139#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
6140
Caveh Jalali024ffe32023-01-30 14:35:19 -08006141#define PD_LOG_SIZE_MASK 0x1f
6142#define PD_LOG_PORT_MASK 0xe0
6143#define PD_LOG_PORT_SHIFT 5
6144#define PD_LOG_PORT_SIZE(port, size) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006145 (((port) << PD_LOG_PORT_SHIFT) | ((size) & PD_LOG_SIZE_MASK))
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006146#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006147#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006148
6149/* PD event log : entry types */
6150/* PD MCU events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006151#define PD_EVENT_MCU_BASE 0x00
6152#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
6153#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006154/* Reserved for custom board event */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006155#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006156/* PD generic accessory events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006157#define PD_EVENT_ACC_BASE 0x20
6158#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
6159#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006160/* PD power supply events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006161#define PD_EVENT_PS_BASE 0x40
6162#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006163/* PD video dongles events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006164#define PD_EVENT_VIDEO_BASE 0x60
6165#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
6166#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006167/* Returned in the "type" field, when there is no entry available */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006168#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006169
6170/*
6171 * PD_EVENT_MCU_CHARGE event definition :
6172 * the payload is "struct usb_chg_measures"
6173 * the data field contains the port state flags as defined below :
6174 */
6175/* Port partner is a dual role device */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006176#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006177/* Port is the pending override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006178#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006179/* Port is the override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006180#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006181/* Charger type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006182#define CHARGE_FLAGS_TYPE_SHIFT 3
6183#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006184/* Power delivery role */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006185#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006186
6187/*
6188 * PD_EVENT_PS_FAULT data field flags definition :
6189 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006190#define PS_FAULT_OCP 1
6191#define PS_FAULT_FAST_OCP 2
6192#define PS_FAULT_OVP 3
6193#define PS_FAULT_DISCH 4
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006194
6195/*
6196 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
6197 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006198struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006199 uint8_t major;
6200 uint8_t minor;
6201 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006202} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006203
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006204struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006205 uint8_t family[2];
6206 uint8_t chipid[2];
6207 struct mcdp_version irom;
6208 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006209} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006210
6211/* struct mcdp_info field decoding */
6212#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
6213#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
6214
6215/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006216#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006217struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006218 uint16_t svid_idx; /* SVID index to get */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006219 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006220} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006221
Caveh Jalali839ada12022-10-31 23:16:48 -07006222#define VDO_MAX_SIZE 7
6223/* Max number of VDM data objects without VDM header */
6224#define VDO_MAX_OBJECTS (VDO_MAX_SIZE - 1)
6225
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006226struct ec_params_usb_pd_get_mode_response {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006227 uint16_t svid; /* SVID */
6228 uint16_t opos; /* Object Position */
Caveh Jalali839ada12022-10-31 23:16:48 -07006229 uint32_t vdo[VDO_MAX_OBJECTS]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006230} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006231
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006232#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006233
6234enum pd_mode_cmd {
6235 PD_EXIT_MODE = 0,
6236 PD_ENTER_MODE = 1,
6237 /* Not a command. Do NOT remove. */
6238 PD_MODE_CMD_COUNT,
6239};
6240
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006241struct ec_params_usb_pd_set_mode_request {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006242 uint32_t cmd; /* enum pd_mode_cmd */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006243 uint16_t svid; /* SVID to set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006244 uint8_t opos; /* Object Position */
6245 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006246} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006247
6248/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006249#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006250
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006251struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006252 uint8_t type; /* event type : see PD_EVENT_xx above */
6253 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006254} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006255
Gwendal Grignou880b4582016-06-20 08:49:25 -07006256/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006257#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07006258
6259enum ec_pd_control_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006260 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6261 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6262 PD_RESET, /* Force reset the PD chip */
6263 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6264 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006265};
6266
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006267struct ec_params_pd_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006268 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006269 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006270} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07006271
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006272/* Get info about USB-C SS muxes */
6273#define EC_CMD_USB_PD_MUX_INFO 0x011A
6274
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006275struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006276 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006277} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006278
6279/* Flags representing mux state */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006280#define USB_PD_MUX_NONE 0 /* Open switch */
6281#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6282#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6283#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6284#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6285#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6286#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6287#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6288#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006289#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006290#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006291
6292/* USB-C Dock connected */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006293#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006294
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006295struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006296 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006297} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006298
Caveh Jalali024ffe32023-01-30 14:35:19 -08006299#define EC_CMD_PD_CHIP_INFO 0x011B
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006301struct ec_params_pd_chip_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006302 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006303 /*
6304 * Fetch the live chip info or hard-coded + cached chip info
6305 * 0: hardcoded value for VID/PID, cached value for FW version
6306 * 1: live chip value for VID/PID/FW Version
6307 */
6308 uint8_t live;
6309} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006310
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006311struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006312 uint16_t vendor_id;
6313 uint16_t product_id;
6314 uint16_t device_id;
6315 union {
6316 uint8_t fw_version_string[8];
6317 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006318 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006319} __ec_align2;
6320
6321struct ec_response_pd_chip_info_v1 {
6322 uint16_t vendor_id;
6323 uint16_t product_id;
6324 uint16_t device_id;
6325 union {
6326 uint8_t fw_version_string[8];
6327 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006328 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006329 union {
6330 uint8_t min_req_fw_version_string[8];
6331 uint64_t min_req_fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006332 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006333} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006334
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00006335/** Indicates the chip should NOT receive a firmware update, if set. This is
6336 * useful when multiple ports are serviced by a single chip, to avoid
6337 * performing redundant updates. The host command implementation shall ensure
6338 * only one port out of each physical chip has FW updates active.
6339 */
6340#define USB_PD_CHIP_INFO_FWUP_FLAG_NO_UPDATE BIT(0)
6341
6342/** Maximum length of a project name embedded in a PDC FW image. This length
6343 * does NOT include a NUL-terminator.
6344 */
6345#define USB_PD_CHIP_INFO_PROJECT_NAME_LEN 12
6346struct ec_response_pd_chip_info_v2 {
6347 uint16_t vendor_id;
6348 uint16_t product_id;
6349 uint16_t device_id;
6350 union {
6351 uint8_t fw_version_string[8];
6352 uint64_t fw_version_number;
6353 } __ec_align2;
6354 union {
6355 uint8_t min_req_fw_version_string[8];
6356 uint64_t min_req_fw_version_number;
6357 } __ec_align2;
6358 /** Flag to control the FW update process for this chip. */
6359 uint16_t fw_update_flags;
6360 /** Project name string associated with the chip's FW. Add an extra
6361 * byte for a NUL-terminator.
6362 */
6363 char fw_name_str[USB_PD_CHIP_INFO_PROJECT_NAME_LEN + 1];
6364} __ec_align2;
6365
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006366/* Run RW signature verification and get status */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006367#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006368
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006369struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006370 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006371} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006372
6373/* For controlling RWSIG task */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006374#define EC_CMD_RWSIG_ACTION 0x011D
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006375
6376enum rwsig_action {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006377 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6378 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006379};
6380
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006381struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006382 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006383} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006384
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006385/* Run verification on a slot */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006386#define EC_CMD_EFS_VERIFY 0x011E
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006387
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006388struct ec_params_efs_verify {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006389 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006390} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006391
6392/*
6393 * Retrieve info from Cros Board Info store. Response is based on the data
6394 * type. Integers return a uint32. Strings return a string, using the response
6395 * size to determine how big it is.
6396 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006397#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006398/*
6399 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6400 * hardware write-protect enabled.
6401 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006402#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006403
Daisuke Nojirif984a052018-02-15 12:38:15 -08006404enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006405 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006406 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6407 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06006408 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006409 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6410 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6411 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6412 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08006413 /* Second Source Factory Cache */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006414 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6415 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006416 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */
Simon Glassd3870a22023-11-09 08:43:30 -07006417
6418 /*
6419 * A uint32_t field reserved for controlling common features at runtime.
6420 * It shouldn't be used at board-level. See union ec_common_control for
6421 * the bit definitions.
6422 */
6423 CBI_TAG_COMMON_CONTROL = 11,
6424
6425 /* struct board_batt_params */
6426 CBI_TAG_BATTERY_CONFIG = 12,
6427 /* CBI_TAG_BATTERY_CONFIG_1 ~ 15 will use 13 ~ 27. */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006428 CBI_TAG_BATTERY_CONFIG_15 = 27,
Simon Glassd3870a22023-11-09 08:43:30 -07006429
6430 /* Last entry */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006431 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006432};
6433
Simon Glassd3870a22023-11-09 08:43:30 -07006434union ec_common_control {
6435 struct {
Pavan Holla8d6625a2024-04-18 14:19:51 +00006436 uint32_t ucsi_enabled : 1;
Simon Glassd3870a22023-11-09 08:43:30 -07006437 };
6438 uint32_t raw_value;
6439};
6440
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006441/*
6442 * Flags to control read operation
6443 *
6444 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6445 * write was successful without reboot.
6446 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006447#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006448
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006449struct ec_params_get_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006450 uint32_t tag; /* enum cbi_data_tag */
6451 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006452} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006453
6454/*
6455 * Flags to control write behavior.
6456 *
6457 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6458 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006459 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006460 * will be initialized to zero first.
6461 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006462#define CBI_SET_NO_SYNC BIT(0)
6463#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006464
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006465struct ec_params_set_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006466 uint32_t tag; /* enum cbi_data_tag */
6467 uint32_t flag; /* CBI_SET_* */
6468 uint32_t size; /* Data size */
6469 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006470} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006471
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006472/*
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00006473 * Retrieve binary from CrOS Board Info primary memory source.
6474 */
6475#define EC_CMD_CBI_BIN_READ 0x0504
6476/*
6477 * Write binary into CrOS Board Info temporary buffer and then commit it to
6478 * permanent storage once complete. Write fails if the board has hardware
6479 * write-protect enabled.
6480 */
6481#define EC_CMD_CBI_BIN_WRITE 0x0505
6482
6483/*
6484 * CBI binary read/write flags
6485 * The default write behavior is to always append any data to the buffer.
6486 * If 'CLEAR' flag is set, buffer is cleared then data is appended.
6487 * If 'WRITE' flag is set, data is appended then buffer is written to memory.
6488 */
6489#define EC_CBI_BIN_BUFFER_CLEAR BIT(0)
6490#define EC_CBI_BIN_BUFFER_WRITE BIT(1)
6491
6492struct ec_params_get_cbi_bin {
6493 uint32_t offset; /* Data offset */
6494 uint32_t size; /* Data size */
6495} __ec_align4;
6496
6497struct ec_params_set_cbi_bin {
6498 uint32_t offset; /* Data offset */
6499 uint32_t size; /* Data size */
6500 uint8_t flags; /* bit field for EC_CBI_BIN_COMMIT_FLAG_* */
6501 uint8_t data[]; /* For string and raw data */
6502} __ec_align1;
6503
6504/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006505 * Information about resets of the AP by the EC and the EC's own uptime.
6506 */
6507#define EC_CMD_GET_UPTIME_INFO 0x0121
6508
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006509/* EC reset causes */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006510#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6511#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6512#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6513#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6514#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6515#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6516#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6517#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6518#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6519#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6520#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6521#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6522#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006523/* Some reset flags preserved from previous boot */
6524#define EC_RESET_FLAG_PRESERVED BIT(13)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006525#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6526#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6527#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6528#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006529/* AP experienced a watchdog reset */
6530#define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6531/* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6532#define EC_RESET_FLAG_STAY_IN_RO BIT(19)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006533#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6534#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6535#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006536
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006537/*
6538 * Reason codes used by the AP after a shutdown to figure out why it was reset
6539 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6540 * compatibility:
6541 * - New entries must be inserted prior to the _COUNT field
6542 * - If an existing entry is no longer in service, it must be replaced with a
6543 * RESERVED entry instead.
6544 * - The semantic meaning of an entry should not change.
6545 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6546 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006547enum chipset_shutdown_reason {
6548 /*
6549 * Beginning of reset reasons.
6550 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006551 CHIPSET_RESET_BEGIN = 0,
6552 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6553 /* Custom reason defined by a board.c or baseboard.c file */
6554 CHIPSET_RESET_BOARD_CUSTOM,
6555 /* Believe that the AP has hung */
6556 CHIPSET_RESET_HANG_REBOOT,
6557 /* Reset by EC console command */
6558 CHIPSET_RESET_CONSOLE_CMD,
6559 /* Reset by EC host command */
6560 CHIPSET_RESET_HOST_CMD,
6561 /* Keyboard module reset key combination */
6562 CHIPSET_RESET_KB_SYSRESET,
6563 /* Keyboard module warm reboot */
6564 CHIPSET_RESET_KB_WARM_REBOOT,
6565 /* Debug module warm reboot */
6566 CHIPSET_RESET_DBG_WARM_REBOOT,
6567 /* I cannot self-terminate. You must lower me into the steel. */
6568 CHIPSET_RESET_AP_REQ,
6569 /* Reset as side-effect of startup sequence */
6570 CHIPSET_RESET_INIT,
6571 /* EC detected an AP watchdog event. */
6572 CHIPSET_RESET_AP_WATCHDOG,
6573
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006574 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006575
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006576 /*
6577 * Beginning of shutdown reasons.
6578 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006579 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6580 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6581 /* Forcing a shutdown as part of EC initialization */
6582 CHIPSET_SHUTDOWN_INIT,
6583 /* Custom reason on a per-board basis. */
6584 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6585 /* This is a reason to inhibit startup, not cause shut down. */
6586 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6587 /* A power_wait_signal is being asserted */
6588 CHIPSET_SHUTDOWN_WAIT,
6589 /* Critical battery level. */
6590 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6591 /* Because you told me to. */
6592 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6593 /* Forcing a shutdown to effect entry to G3. */
6594 CHIPSET_SHUTDOWN_G3,
6595 /* Force shutdown due to over-temperature. */
6596 CHIPSET_SHUTDOWN_THERMAL,
6597 /* Force a chipset shutdown from the power button through EC */
6598 CHIPSET_SHUTDOWN_BUTTON,
6599
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006600 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006601};
6602
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006603struct ec_response_uptime_info {
6604 /*
6605 * Number of milliseconds since the last EC boot. Sysjump resets
6606 * typically do not restart the EC's time_since_boot epoch.
6607 *
6608 * WARNING: The EC's sense of time is much less accurate than the AP's
6609 * sense of time, in both phase and frequency. This timebase is similar
6610 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6611 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006612 uint32_t time_since_ec_boot_ms;
6613
6614 /*
6615 * Number of times the AP was reset by the EC since the last EC boot.
6616 * Note that the AP may be held in reset by the EC during the initial
6617 * boot sequence, such that the very first AP boot may count as more
6618 * than one here.
6619 */
6620 uint32_t ap_resets_since_ec_boot;
6621
6622 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006623 * The set of flags which describe the EC's most recent reset.
6624 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006625 */
6626 uint32_t ec_reset_flags;
6627
6628 /* Empty log entries have both the cause and timestamp set to zero. */
6629 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006630 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006631 uint16_t reset_cause;
6632
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006633 /* Reserved for protocol growth. */
6634 uint16_t reserved;
6635
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006636 /*
6637 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006638 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6639 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006640 */
6641 uint32_t reset_time_ms;
6642 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006643} __ec_align4;
6644
6645/*
6646 * Add entropy to the device secret (stored in the rollback region).
6647 *
6648 * Depending on the chip, the operation may take a long time (e.g. to erase
6649 * flash), so the commands are asynchronous.
6650 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006651#define EC_CMD_ADD_ENTROPY 0x0122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006652
6653enum add_entropy_action {
6654 /* Add entropy to the current secret. */
6655 ADD_ENTROPY_ASYNC = 0,
6656 /*
6657 * Add entropy, and also make sure that the previous secret is erased.
6658 * (this can be implemented by adding entropy multiple times until
6659 * all rolback blocks have been overwritten).
6660 */
6661 ADD_ENTROPY_RESET_ASYNC = 1,
6662 /* Read back result from the previous operation. */
6663 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006664};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006665
6666struct ec_params_rollback_add_entropy {
6667 uint8_t action;
6668} __ec_align1;
6669
6670/*
6671 * Perform a single read of a given ADC channel.
6672 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006673#define EC_CMD_ADC_READ 0x0123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006674
6675struct ec_params_adc_read {
6676 uint8_t adc_channel;
6677} __ec_align1;
6678
6679struct ec_response_adc_read {
6680 int32_t adc_value;
6681} __ec_align4;
6682
6683/*
6684 * Read back rollback info
6685 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006686#define EC_CMD_ROLLBACK_INFO 0x0124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006687
6688struct ec_response_rollback_info {
6689 int32_t id; /* Incrementing number to indicate which region to use. */
6690 int32_t rollback_min_version;
6691 int32_t rw_rollback_version;
6692} __ec_align4;
6693
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006694/* Issue AP reset */
6695#define EC_CMD_AP_RESET 0x0125
6696
6697/*****************************************************************************/
6698/* Locate peripheral chips
6699 *
6700 * Return values:
6701 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6702 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6703 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6704 */
6705#define EC_CMD_LOCATE_CHIP 0x0126
6706
6707enum ec_chip_type {
6708 EC_CHIP_TYPE_CBI_EEPROM = 0,
6709 EC_CHIP_TYPE_TCPC = 1,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006710 EC_CHIP_TYPE_PDC = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006711 EC_CHIP_TYPE_COUNT,
6712 EC_CHIP_TYPE_MAX = 0xFF,
6713};
6714
6715enum ec_bus_type {
6716 EC_BUS_TYPE_I2C = 0,
6717 EC_BUS_TYPE_EMBEDDED = 1,
6718 EC_BUS_TYPE_COUNT,
6719 EC_BUS_TYPE_MAX = 0xFF,
6720};
6721
6722struct ec_i2c_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006723 uint16_t port; /* Physical port for device */
6724 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006725};
6726
6727struct ec_params_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006728 uint8_t type; /* enum ec_chip_type */
6729 uint8_t index; /* Specifies one instance of chip type */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006730 /* Used for type specific parameters in future */
6731 union {
6732 uint16_t reserved;
6733 };
6734} __ec_align2;
6735
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006736struct ec_response_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006737 uint8_t bus_type; /* enum ec_bus_type */
6738 uint8_t reserved; /* Aligning the following union to 2 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006739 union {
6740 struct ec_i2c_info i2c_info;
6741 };
6742} __ec_align2;
6743
Jett Rinkba2edaf2020-01-14 11:49:06 -07006744/*
6745 * Reboot AP on G3
6746 *
6747 * This command is used for validation purpose, where the AP needs to be
6748 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006749 * wake events.
6750 * - With command version 0:
6751 * AP reboots immediately from G3
6752 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6753 * - With command version 1:
6754 * AP reboots after the user specified delay
6755 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006756 */
6757#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6758
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006759struct ec_params_reboot_ap_on_g3_v1 {
6760 /* configurable delay in seconds in G3 state */
6761 uint32_t reboot_ap_at_g3_delay;
6762} __ec_align4;
6763
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006764/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006765/* Get PD port capabilities
6766 *
6767 * Returns the following static *capabilities* of the given port:
6768 * 1) Power role: source, sink, or dual. It is not anticipated that
6769 * future CrOS devices would ever be only a source, so the options are
6770 * sink or dual.
6771 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6772 * believe any CrOS device would support Try.SNK, so this would be source
6773 * or none).
6774 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6775 * for CrOS devices.
6776 */
6777#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6778
6779enum ec_pd_power_role_caps {
6780 EC_PD_POWER_ROLE_SOURCE = 0,
6781 EC_PD_POWER_ROLE_SINK = 1,
6782 EC_PD_POWER_ROLE_DUAL = 2,
6783};
6784
6785enum ec_pd_try_power_role_caps {
6786 EC_PD_TRY_POWER_ROLE_NONE = 0,
6787 EC_PD_TRY_POWER_ROLE_SINK = 1,
6788 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6789};
6790
6791enum ec_pd_data_role_caps {
6792 EC_PD_DATA_ROLE_DFP = 0,
6793 EC_PD_DATA_ROLE_UFP = 1,
6794 EC_PD_DATA_ROLE_DUAL = 2,
6795};
6796
6797/* From: power_manager/power_supply_properties.proto */
6798enum ec_pd_port_location {
6799 /* The location of the port is unknown, or there's only one port. */
6800 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6801
6802 /*
6803 * Various positions on the device. The first word describes the side of
6804 * the device where the port is located while the second clarifies the
6805 * position. For example, LEFT_BACK means the farthest-back port on the
6806 * left side, while BACK_LEFT means the leftmost port on the back of the
6807 * device.
6808 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006809 EC_PD_PORT_LOCATION_LEFT = 1,
6810 EC_PD_PORT_LOCATION_RIGHT = 2,
6811 EC_PD_PORT_LOCATION_BACK = 3,
6812 EC_PD_PORT_LOCATION_FRONT = 4,
6813 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6814 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006815 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006816 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6817 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6818 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006819};
6820
6821struct ec_params_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006822 uint8_t port; /* Which port to interrogate */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006823} __ec_align1;
6824
6825struct ec_response_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006826 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6827 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6828 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6829 uint8_t pd_port_location; /* enum ec_pd_port_location */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006830} __ec_align1;
6831
6832/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006833/*
6834 * Button press simulation
6835 *
6836 * This command is used to simulate a button press.
6837 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6838 * Time duration for which button needs to be pressed is an optional parameter.
6839 *
6840 * NOTE: This is only available on unlocked devices for testing purposes only.
6841 */
6842#define EC_CMD_BUTTON 0x0129
6843
6844struct ec_params_button {
6845 /* Button mask aligned to enum keyboard_button_type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006846 uint32_t btn_mask;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006847
6848 /* Duration in milliseconds button needs to be pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006849 uint32_t press_ms;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006850} __ec_align1;
6851
6852enum keyboard_button_type {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006853 KEYBOARD_BUTTON_POWER = 0,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006854 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006855 KEYBOARD_BUTTON_VOLUME_UP = 2,
6856 KEYBOARD_BUTTON_RECOVERY = 3,
6857 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6858 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6859 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6860 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6861 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6862 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6863 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6864 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006865
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006866 KEYBOARD_BUTTON_COUNT,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006867};
Yidi Lin42f79592020-09-21 18:04:10 +08006868
Rajat Jainc0495722020-04-02 23:58:35 -07006869/*****************************************************************************/
6870/*
6871 * "Get the Keyboard Config". An EC implementing this command is expected to be
6872 * vivaldi capable, i.e. can send action codes for the top row keys.
6873 * Additionally, capability to send function codes for the same keys is
6874 * optional and acceptable.
6875 *
6876 * Note: If the top row can generate both function and action codes by
6877 * using a dedicated Fn key, it does not matter whether the key sends
6878 * "function" or "action" codes by default. In both cases, the response
6879 * for this command will look the same.
6880 */
6881#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6882
6883/* Possible values for the top row keys */
6884enum action_key {
6885 TK_ABSENT = 0,
6886 TK_BACK = 1,
6887 TK_FORWARD = 2,
6888 TK_REFRESH = 3,
6889 TK_FULLSCREEN = 4,
6890 TK_OVERVIEW = 5,
6891 TK_BRIGHTNESS_DOWN = 6,
6892 TK_BRIGHTNESS_UP = 7,
6893 TK_VOL_MUTE = 8,
6894 TK_VOL_DOWN = 9,
6895 TK_VOL_UP = 10,
6896 TK_SNAPSHOT = 11,
6897 TK_PRIVACY_SCRN_TOGGLE = 12,
6898 TK_KBD_BKLIGHT_DOWN = 13,
6899 TK_KBD_BKLIGHT_UP = 14,
6900 TK_PLAY_PAUSE = 15,
6901 TK_NEXT_TRACK = 16,
6902 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006903 TK_KBD_BKLIGHT_TOGGLE = 18,
6904 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006905 TK_MENU = 20,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006906 TK_DICTATE = 21,
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00006907 TK_ACCESSIBILITY = 22,
6908 TK_DONOTDISTURB = 23,
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006909
6910 TK_COUNT
Rajat Jainc0495722020-04-02 23:58:35 -07006911};
6912
6913/*
6914 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6915 * If this needs to change, please create a new version of the command.
6916 */
6917#define MAX_TOP_ROW_KEYS 15
6918#define MIN_TOP_ROW_KEYS 10
6919
6920/*
6921 * Is the keyboard capable of sending function keys *in addition to*
6922 * action keys. This is possible for e.g. if the keyboard has a
6923 * dedicated Fn key.
6924 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006925#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
Rajat Jainc0495722020-04-02 23:58:35 -07006926/*
6927 * Whether the keyboard has a dedicated numeric keyboard.
6928 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006929#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
Rajat Jainc0495722020-04-02 23:58:35 -07006930/*
6931 * Whether the keyboard has a screenlock key.
6932 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006933#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
Rajat Jainc0495722020-04-02 23:58:35 -07006934
Aseda Aboagyeabc38122024-04-15 15:39:55 -05006935/*
6936 * Whether the keyboard has an assistant key.
6937 */
6938#define KEYBD_CAP_ASSISTANT_KEY BIT(3)
6939
Rajat Jainc0495722020-04-02 23:58:35 -07006940struct ec_response_keybd_config {
6941 /*
6942 * Number of top row keys, excluding Esc and Screenlock.
6943 * If this is 0, all Vivaldi keyboard code is disabled.
6944 * (i.e. does not expose any tables to the kernel).
6945 */
6946 uint8_t num_top_row_keys;
6947
6948 /*
6949 * The action keys in the top row, in order from left to right.
6950 * The values are filled from enum action_key. Esc and Screenlock
6951 * keys are not considered part of top row keys.
6952 */
6953 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6954
6955 /* Capability flags */
6956 uint8_t capabilities;
6957
6958} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006959
Yidi Lin42f79592020-09-21 18:04:10 +08006960/*
6961 * Configure smart discharge
6962 */
6963#define EC_CMD_SMART_DISCHARGE 0x012B
6964
Caveh Jalali024ffe32023-01-30 14:35:19 -08006965#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
Yidi Lin42f79592020-09-21 18:04:10 +08006966
6967/* Discharge rates when the system is in cutoff or hibernation. */
6968struct discharge_rate {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006969 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6970 uint16_t hibern; /* Discharge rate (uA) in hibernation */
Yidi Lin42f79592020-09-21 18:04:10 +08006971};
6972
6973struct smart_discharge_zone {
6974 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6975 int cutoff;
6976 /* When the capacity (mAh) is below this, EC stays up. */
6977 int stayup;
6978};
6979
6980struct ec_params_smart_discharge {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006981 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
Yidi Lin42f79592020-09-21 18:04:10 +08006982 /*
6983 * Desired hours for the battery to survive before reaching 0%. Set to
6984 * zero to disable smart discharging. That is, the system hibernates as
6985 * soon as the G3 idle timer expires.
6986 */
6987 uint16_t hours_to_zero;
6988 /* Set both to zero to keep the current rates. */
6989 struct discharge_rate drate;
6990};
6991
6992struct ec_response_smart_discharge {
6993 uint16_t hours_to_zero;
6994 struct discharge_rate drate;
6995 struct smart_discharge_zone dzone;
6996};
6997
6998/*****************************************************************************/
6999/* Voltage regulator controls */
7000
7001/*
7002 * Get basic info of voltage regulator for given index.
7003 *
7004 * Returns the regulator name and supported voltage list in mV.
7005 */
7006#define EC_CMD_REGULATOR_GET_INFO 0x012C
7007
7008/* Maximum length of regulator name */
7009#define EC_REGULATOR_NAME_MAX_LEN 16
7010
7011/* Maximum length of the supported voltage list. */
7012#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
7013
7014struct ec_params_regulator_get_info {
7015 uint32_t index;
7016} __ec_align4;
7017
7018struct ec_response_regulator_get_info {
7019 char name[EC_REGULATOR_NAME_MAX_LEN];
7020 uint16_t num_voltages;
7021 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
7022} __ec_align2;
7023
7024/*
7025 * Configure the regulator as enabled / disabled.
7026 */
7027#define EC_CMD_REGULATOR_ENABLE 0x012D
7028
7029struct ec_params_regulator_enable {
7030 uint32_t index;
7031 uint8_t enable;
7032} __ec_align4;
7033
7034/*
7035 * Query if the regulator is enabled.
7036 *
7037 * Returns 1 if the regulator is enabled, 0 if not.
7038 */
7039#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
7040
7041struct ec_params_regulator_is_enabled {
7042 uint32_t index;
7043} __ec_align4;
7044
7045struct ec_response_regulator_is_enabled {
7046 uint8_t enabled;
7047} __ec_align1;
7048
7049/*
7050 * Set voltage for the voltage regulator within the range specified.
7051 *
7052 * The driver should select the voltage in range closest to min_mv.
7053 *
7054 * Also note that this might be called before the regulator is enabled, and the
7055 * setting should be in effect after the regulator is enabled.
7056 */
7057#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
7058
7059struct ec_params_regulator_set_voltage {
7060 uint32_t index;
7061 uint32_t min_mv;
7062 uint32_t max_mv;
7063} __ec_align4;
7064
7065/*
7066 * Get the currently configured voltage for the voltage regulator.
7067 *
7068 * Note that this might be called before the regulator is enabled, and this
7069 * should return the configured output voltage if the regulator is enabled.
7070 */
7071#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
7072
7073struct ec_params_regulator_get_voltage {
7074 uint32_t index;
7075} __ec_align4;
7076
7077struct ec_response_regulator_get_voltage {
7078 uint32_t voltage_mv;
7079} __ec_align4;
7080
7081/*
7082 * Gather all discovery information for the given port and partner type.
7083 *
7084 * Note that if discovery has not yet completed, only the currently completed
7085 * responses will be filled in. If the discovery data structures are changed
7086 * in the process of the command running, BUSY will be returned.
7087 *
7088 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
7089 * contain, while the number of SVIDs here is selected to fit within the PROTO2
7090 * maximum parameter size.
7091 */
7092#define EC_CMD_TYPEC_DISCOVERY 0x0131
7093
7094enum typec_partner_type {
7095 TYPEC_PARTNER_SOP = 0,
7096 TYPEC_PARTNER_SOP_PRIME = 1,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007097 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
Yidi Lin42f79592020-09-21 18:04:10 +08007098};
7099
7100struct ec_params_typec_discovery {
7101 uint8_t port;
7102 uint8_t partner_type; /* enum typec_partner_type */
7103} __ec_align1;
7104
7105struct svid_mode_info {
7106 uint16_t svid;
Caveh Jalali024ffe32023-01-30 14:35:19 -08007107 uint16_t mode_count; /* Number of modes partner sent */
Caveh Jalali839ada12022-10-31 23:16:48 -07007108 uint32_t mode_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08007109};
7110
7111struct ec_response_typec_discovery {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007112 uint8_t identity_count; /* Number of identity VDOs partner sent */
7113 uint8_t svid_count; /* Number of SVIDs partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08007114 uint16_t reserved;
Caveh Jalali839ada12022-10-31 23:16:48 -07007115 uint32_t discovery_vdo[VDO_MAX_OBJECTS];
Yidi Lin42f79592020-09-21 18:04:10 +08007116 struct svid_mode_info svids[0];
7117} __ec_align1;
7118
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007119/* USB Type-C commands for AP-controlled device policy. */
7120#define EC_CMD_TYPEC_CONTROL 0x0132
7121
7122enum typec_control_command {
7123 TYPEC_CONTROL_COMMAND_EXIT_MODES,
7124 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007125 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007126 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007127 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007128 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
7129 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007130};
7131
7132/* Modes (USB or alternate) that a type-C port may enter. */
7133enum typec_mode {
7134 TYPEC_MODE_DP,
7135 TYPEC_MODE_TBT,
7136 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007137};
7138
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007139/* Replies the AP may specify to the TBT EnterMode command as a UFP */
7140enum typec_tbt_ufp_reply {
7141 TYPEC_TBT_UFP_REPLY_NAK,
7142 TYPEC_TBT_UFP_REPLY_ACK,
7143};
7144
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007145#define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
7146
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007147struct typec_usb_mux_set {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007148 /* Index of the mux to set in the chain */
7149 uint8_t mux_index;
7150
7151 /* USB_PD_MUX_*-encoded USB mux state to set */
7152 uint8_t mux_flags;
7153} __ec_align1;
7154
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007155struct typec_vdm_req {
7156 /* VDM data, including VDM header */
7157 uint32_t vdm_data[VDO_MAX_SIZE];
7158 /* Number of 32-bit fields filled in */
7159 uint8_t vdm_data_objects;
7160 /* Partner to address - see enum typec_partner_type */
7161 uint8_t partner_type;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007162} __ec_align1;
7163
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007164struct ec_params_typec_control {
7165 uint8_t port;
Caveh Jalali024ffe32023-01-30 14:35:19 -08007166 uint8_t command; /* enum typec_control_command */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007167 uint16_t reserved;
7168
7169 /*
7170 * This section will be interpreted based on |command|. Define a
7171 * placeholder structure to avoid having to increase the size and bump
7172 * the command version when adding new sub-commands.
7173 */
7174 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007175 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007176 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007177 /* Used for ENTER_MODE - enum typec_mode */
7178 uint8_t mode_to_enter;
7179 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
7180 uint8_t tbt_ufp_reply;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007181 /* Used for USB_MUX_SET */
7182 struct typec_usb_mux_set mux_params;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007183 /* Used for BIST_SHARE_MODE */
7184 uint8_t bist_share_mode;
7185 /* Used for VMD_REQ */
7186 struct typec_vdm_req vdm_req_params;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007187 uint8_t placeholder[128];
7188 };
7189} __ec_align1;
7190
7191/*
7192 * Gather all status information for a port.
7193 *
7194 * Note: this covers many of the return fields from the deprecated
7195 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
7196 * discovery data. The "enum pd_cc_states" is defined with the deprecated
7197 * EC_CMD_USB_PD_CONTROL command.
7198 *
7199 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007200 */
7201#define EC_CMD_TYPEC_STATUS 0x0133
7202
7203/*
7204 * Power role.
7205 *
7206 * Note this is also used for PD header creation, and values align to those in
7207 * the Power Delivery Specification Revision 3.0 (See
7208 * 6.2.1.1.4 Port Power Role).
7209 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007210enum pd_power_role {
7211 PD_ROLE_SINK = 0,
7212 PD_ROLE_SOURCE = 1,
7213};
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007214
7215/*
7216 * Data role.
7217 *
7218 * Note this is also used for PD header creation, and the first two values
7219 * align to those in the Power Delivery Specification Revision 3.0 (See
7220 * 6.2.1.1.6 Port Data Role).
7221 */
7222enum pd_data_role {
7223 PD_ROLE_UFP = 0,
7224 PD_ROLE_DFP = 1,
7225 PD_ROLE_DISCONNECTED = 2,
7226};
7227
7228enum pd_vconn_role {
7229 PD_ROLE_VCONN_OFF = 0,
7230 PD_ROLE_VCONN_SRC = 1,
7231};
7232
7233/*
7234 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
7235 * regardless of whether a debug accessory is connected.
7236 */
7237enum tcpc_cc_polarity {
7238 /*
7239 * _CCx: is used to indicate the polarity while not connected to
7240 * a Debug Accessory. Only one CC line will assert a resistor and
7241 * the other will be open.
7242 */
7243 POLARITY_CC1 = 0,
7244 POLARITY_CC2 = 1,
7245
7246 /*
7247 * _CCx_DTS is used to indicate the polarity while connected to a
7248 * SRC Debug Accessory. Assert resistors on both lines.
7249 */
7250 POLARITY_CC1_DTS = 2,
7251 POLARITY_CC2_DTS = 3,
7252
7253 /*
7254 * The current TCPC code relies on these specific POLARITY values.
7255 * Adding in a check to verify if the list grows for any reason
7256 * that this will give a hint that other places need to be
7257 * adjusted.
7258 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007259 POLARITY_COUNT,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007260};
7261
Caveh Jalali024ffe32023-01-30 14:35:19 -08007262#define MODE_DP_PIN_A BIT(0)
7263#define MODE_DP_PIN_B BIT(1)
7264#define MODE_DP_PIN_C BIT(2)
7265#define MODE_DP_PIN_D BIT(3)
7266#define MODE_DP_PIN_E BIT(4)
7267#define MODE_DP_PIN_F BIT(5)
7268#define MODE_DP_PIN_ALL GENMASK(5, 0)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007269
Caveh Jalali024ffe32023-01-30 14:35:19 -08007270#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
7271#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
7272#define PD_STATUS_EVENT_HARD_RESET BIT(2)
7273#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
7274#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
7275#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007276#define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
7277#define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
7278#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007279#define PD_STATUS_EVENT_COUNT 9
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007280
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007281/*
7282 * Encode and decode for BCD revision response
7283 *
7284 * Note: the major revision set is written assuming that the value given is the
7285 * Specification Revision from the PD header, which currently only maps to PD
7286 * 1.0-3.0 with the major revision being one greater than the binary value.
7287 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007288#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
7289#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
7290#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007291
7292/*
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007293 * Encode revision from partner RMDO
7294 *
7295 * Unlike the specification revision given in the PD header, specification and
7296 * version information returned in the revision message data object (RMDO) is
7297 * not offset.
7298 */
7299#define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
7300#define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
7301#define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
7302#define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
7303
7304/*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007305 * Decode helpers for Source and Sink Capability PDOs
7306 *
7307 * Note: The Power Delivery Specification should be considered the ultimate
7308 * source of truth on the decoding of these PDOs
7309 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007310#define PDO_TYPE_FIXED (0 << 30)
7311#define PDO_TYPE_BATTERY (1 << 30)
7312#define PDO_TYPE_VARIABLE (2 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007313#define PDO_TYPE_AUGMENTED (3 << 30)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007314#define PDO_TYPE_MASK (3 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007315
7316/*
7317 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
7318 *
7319 * <31:30> : Fixed Supply
7320 * <29> : Dual-Role Power
7321 * <28> : SNK/SRC dependent
7322 * <27> : Unconstrained Power
7323 * <26> : USB Communications Capable
7324 * <25> : Dual-Role Data
7325 * <24:20> : SNK/SRC dependent
7326 * <19:10> : Voltage in 50mV Units
7327 * <9:0> : Maximum Current in 10mA units
7328 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007329#define PDO_FIXED_DUAL_ROLE BIT(29)
7330#define PDO_FIXED_UNCONSTRAINED BIT(27)
7331#define PDO_FIXED_COMM_CAP BIT(26)
7332#define PDO_FIXED_DATA_SWAP BIT(25)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007333#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007334#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7335#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007336
7337/*
7338 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
7339 *
7340 * <31:30> : Battery
7341 * <29:20> : Maximum Voltage in 50mV units
7342 * <19:10> : Minimum Voltage in 50mV units
7343 * <9:0> : Maximum Allowable Power in 250mW units
7344 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007345#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7346#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7347#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007348
7349/*
7350 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7351 *
7352 * <31:30> : Variable Supply (non-Battery)
7353 * <29:20> : Maximum Voltage in 50mV units
7354 * <19:10> : Minimum Voltage in 50mV units
7355 * <9:0> : Operational Current in 10mA units
7356 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007357#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7358#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7359#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007360
7361/*
7362 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7363 *
7364 * Note this type is reserved in PD 2.0, and only one type of APDO is
7365 * supported as of the cited version.
7366 *
7367 * <31:30> : Augmented Power Data Object
7368 * <29:28> : Programmable Power Supply
7369 * <27> : PPS Power Limited
7370 * <26:25> : Reserved
7371 * <24:17> : Maximum Voltage in 100mV increments
7372 * <16> : Reserved
7373 * <15:8> : Minimum Voltage in 100mV increments
7374 * <7> : Reserved
7375 * <6:0> : Maximum Current in 50mA increments
7376 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007377#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7378#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7379#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007380
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007381struct ec_params_typec_status {
7382 uint8_t port;
7383} __ec_align1;
7384
Caveh Jalali839ada12022-10-31 23:16:48 -07007385/*
7386 * ec_response_typec_status is deprecated. Use ec_response_typec_status_v1.
7387 * If you need to support old ECs who speak only v0, use
7388 * ec_response_typec_status_v0 instead. They're binary-compatible.
7389 */
7390struct ec_response_typec_status /* DEPRECATED */ {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007391 uint8_t pd_enabled; /* PD communication enabled - bool */
7392 uint8_t dev_connected; /* Device connected - bool */
7393 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7394 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007395
Caveh Jalali024ffe32023-01-30 14:35:19 -08007396 uint8_t power_role; /* enum pd_power_role */
7397 uint8_t data_role; /* enum pd_data_role */
7398 uint8_t vconn_role; /* enum pd_vconn_role */
7399 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007400
Caveh Jalali024ffe32023-01-30 14:35:19 -08007401 uint8_t polarity; /* enum tcpc_cc_polarity */
7402 uint8_t cc_state; /* enum pd_cc_states */
7403 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7404 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007405
Caveh Jalali024ffe32023-01-30 14:35:19 -08007406 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007407
Caveh Jalali024ffe32023-01-30 14:35:19 -08007408 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007409
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007410 /*
7411 * BCD PD revisions for partners
7412 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007413 * The format has the PD major revision in the upper nibble, and the PD
7414 * minor revision in the next nibble. The following two nibbles hold the
7415 * major and minor specification version. If a partner does not support
7416 * the Revision message, only the major revision will be given.
7417 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007418 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007419 * PD revision/version will be 0 if no PD device is connected.
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007420 */
7421 uint16_t sop_revision;
7422 uint16_t sop_prime_revision;
7423
Caveh Jalali024ffe32023-01-30 14:35:19 -08007424 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007425
Caveh Jalali024ffe32023-01-30 14:35:19 -08007426 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007427} __ec_align1;
7428
Caveh Jalali839ada12022-10-31 23:16:48 -07007429struct cros_ec_typec_status {
7430 uint8_t pd_enabled; /* PD communication enabled - bool */
7431 uint8_t dev_connected; /* Device connected - bool */
7432 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7433 uint8_t source_cap_count; /* Number of Source Cap PDOs */
7434
7435 uint8_t power_role; /* enum pd_power_role */
7436 uint8_t data_role; /* enum pd_data_role */
7437 uint8_t vconn_role; /* enum pd_vconn_role */
7438 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
7439
7440 uint8_t polarity; /* enum tcpc_cc_polarity */
7441 uint8_t cc_state; /* enum pd_cc_states */
7442 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7443 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
7444
7445 char tc_state[32]; /* TC state name */
7446
7447 uint32_t events; /* PD_STATUS_EVENT bitmask */
7448
7449 /*
7450 * BCD PD revisions for partners
7451 *
7452 * The format has the PD major revision in the upper nibble, and the PD
7453 * minor revision in the next nibble. The following two nibbles hold the
7454 * major and minor specification version. If a partner does not support
7455 * the Revision message, only the major revision will be given.
7456 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
7457 *
7458 * PD revision/version will be 0 if no PD device is connected.
7459 */
7460 uint16_t sop_revision;
7461 uint16_t sop_prime_revision;
7462} __ec_align1;
7463
7464struct ec_response_typec_status_v0 {
7465 struct cros_ec_typec_status typec_status;
7466 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
7467 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
7468} __ec_align1;
7469
7470struct ec_response_typec_status_v1 {
7471 struct cros_ec_typec_status typec_status;
7472 uint32_t source_cap_pdos[11]; /* Max 11 PDOs can be present */
7473 uint32_t sink_cap_pdos[11]; /* Max 11 PDOs can be present */
7474} __ec_align1;
7475
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007476/**
7477 * Get the number of peripheral charge ports
7478 */
7479#define EC_CMD_PCHG_COUNT 0x0134
7480
7481#define EC_PCHG_MAX_PORTS 8
7482
7483struct ec_response_pchg_count {
7484 uint8_t port_count;
7485} __ec_align1;
7486
7487/**
7488 * Get the status of a peripheral charge port
7489 */
7490#define EC_CMD_PCHG 0x0135
7491
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007492/* For v1 and v2 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007493struct ec_params_pchg {
7494 uint8_t port;
7495} __ec_align1;
7496
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007497struct ec_params_pchg_v3 {
7498 uint8_t port;
7499 /* Below are new in v3. */
7500 uint8_t reserved1;
7501 uint8_t reserved2;
7502 uint8_t reserved3;
7503 /* Errors acked by the host (thus to be cleared) */
7504 uint32_t error;
7505} __ec_align1;
7506
7507/* For v1 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007508struct ec_response_pchg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007509 uint32_t error; /* enum pchg_error */
7510 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007511 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007512 uint8_t unused0;
7513 uint8_t unused1;
7514 /* Fields added in version 1 */
7515 uint32_t fw_version;
7516 uint32_t dropped_event_count;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007517} __ec_align4;
7518
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007519/* For v2 and v3 */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007520struct ec_response_pchg_v2 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007521 uint32_t error; /* enum pchg_error */
7522 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007523 uint8_t battery_percentage;
7524 uint8_t unused0;
7525 uint8_t unused1;
7526 /* Fields added in version 1 */
7527 uint32_t fw_version;
7528 uint32_t dropped_event_count;
7529 /* Fields added in version 2 */
7530 uint32_t dropped_host_event_count;
7531} __ec_align4;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007532
7533enum pchg_state {
7534 /* Charger is reset and not initialized. */
7535 PCHG_STATE_RESET = 0,
7536 /* Charger is initialized or disabled. */
7537 PCHG_STATE_INITIALIZED,
7538 /* Charger is enabled and ready to detect a device. */
7539 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007540 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007541 PCHG_STATE_DETECTED,
7542 /* Device is being charged. */
7543 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007544 /* Device is fully charged. It implies DETECTED (& not charging). */
7545 PCHG_STATE_FULL,
7546 /* In download (a.k.a. firmware update) mode */
7547 PCHG_STATE_DOWNLOAD,
7548 /* In download mode. Ready for receiving data. */
7549 PCHG_STATE_DOWNLOADING,
7550 /* Device is ready for data communication. */
7551 PCHG_STATE_CONNECTED,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007552 /* Charger is in Built-In Self Test mode. */
7553 PCHG_STATE_BIST,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007554 /* Put no more entry below */
7555 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007556};
7557
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007558/* clang-format off */
7559#define EC_PCHG_STATE_TEXT \
7560 { \
7561 [PCHG_STATE_RESET] = "RESET", \
7562 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7563 [PCHG_STATE_ENABLED] = "ENABLED", \
7564 [PCHG_STATE_DETECTED] = "DETECTED", \
7565 [PCHG_STATE_CHARGING] = "CHARGING", \
7566 [PCHG_STATE_FULL] = "FULL", \
7567 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7568 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7569 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7570 [PCHG_STATE_BIST] = "BIST", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007571 }
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007572/* clang-format on */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007573
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007574/**
7575 * Update firmware of peripheral chip
7576 */
7577#define EC_CMD_PCHG_UPDATE 0x0136
7578
7579/* Port number is encoded in bit[28:31]. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007580#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007581/* Utility macros for converting MKBP event <-> port number. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007582#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7583#define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007584/* Utility macro for extracting event bits. */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007585#define EC_MKBP_PCHG_EVENT_MASK(e) \
7586 ((e) & GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007587
Caveh Jalali024ffe32023-01-30 14:35:19 -08007588#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7589#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7590#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7591#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7592#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007593
7594enum ec_pchg_update_cmd {
7595 /* Reset chip to normal mode. */
7596 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7597 /* Reset and put a chip in update (a.k.a. download) mode. */
7598 EC_PCHG_UPDATE_CMD_OPEN,
7599 /* Write a block of data containing FW image. */
7600 EC_PCHG_UPDATE_CMD_WRITE,
7601 /* Close update session. */
7602 EC_PCHG_UPDATE_CMD_CLOSE,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007603 /* Reset chip (without mode change). */
7604 EC_PCHG_UPDATE_CMD_RESET,
7605 /* Enable pass-through mode. */
7606 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007607 /* End of commands */
7608 EC_PCHG_UPDATE_CMD_COUNT,
7609};
7610
7611struct ec_params_pchg_update {
7612 /* PCHG port number */
7613 uint8_t port;
7614 /* enum ec_pchg_update_cmd */
7615 uint8_t cmd;
7616 /* Padding */
7617 uint8_t reserved0;
7618 uint8_t reserved1;
7619 /* Version of new firmware */
7620 uint32_t version;
7621 /* CRC32 of new firmware */
7622 uint32_t crc32;
7623 /* Address in chip memory where <data> is written to */
7624 uint32_t addr;
7625 /* Size of <data> */
7626 uint32_t size;
7627 /* Partial data of new firmware */
7628 uint8_t data[];
7629} __ec_align4;
7630
Caveh Jalali024ffe32023-01-30 14:35:19 -08007631BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7632 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007633
7634struct ec_response_pchg_update {
7635 /* Block size */
7636 uint32_t block_size;
7637} __ec_align4;
7638
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007639#define EC_CMD_DISPLAY_SOC 0x0137
7640
7641struct ec_response_display_soc {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007642 /* Display charge in 10ths of a % (1000=100.0%) */
7643 int16_t display_soc;
7644 /* Full factor in 10ths of a % (1000=100.0%) */
7645 int16_t full_factor;
7646 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7647 int16_t shutdown_soc;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007648} __ec_align2;
7649
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007650#define EC_CMD_SET_BASE_STATE 0x0138
7651
7652struct ec_params_set_base_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007653 uint8_t cmd; /* enum ec_set_base_state_cmd */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007654} __ec_align1;
7655
7656enum ec_set_base_state_cmd {
7657 EC_SET_BASE_STATE_DETACH = 0,
7658 EC_SET_BASE_STATE_ATTACH,
7659 EC_SET_BASE_STATE_RESET,
7660};
7661
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007662#define EC_CMD_I2C_CONTROL 0x0139
7663
7664/* Subcommands for I2C control */
7665
7666enum ec_i2c_control_command {
7667 EC_I2C_CONTROL_GET_SPEED,
7668 EC_I2C_CONTROL_SET_SPEED,
7669};
7670
7671#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7672
7673struct ec_params_i2c_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007674 uint8_t port; /* I2C port number */
7675 uint8_t cmd; /* enum ec_i2c_control_command */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007676 union {
7677 uint16_t speed_khz;
7678 } cmd_params;
7679} __ec_align_size1;
7680
7681struct ec_response_i2c_control {
7682 union {
7683 uint16_t speed_khz;
7684 } cmd_response;
7685} __ec_align_size1;
7686
Caveh Jalali024ffe32023-01-30 14:35:19 -08007687#define EC_CMD_RGBKBD_SET_COLOR 0x013A
7688#define EC_CMD_RGBKBD 0x013B
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007689
Caveh Jalali024ffe32023-01-30 14:35:19 -08007690#define EC_RGBKBD_MAX_KEY_COUNT 128
7691#define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7692#define EC_RGBKBD_MAX_SCALE 0xFF
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007693
7694enum rgbkbd_state {
7695 /* RGB keyboard is reset and not initialized. */
7696 RGBKBD_STATE_RESET = 0,
7697 /* RGB keyboard is initialized but not enabled. */
7698 RGBKBD_STATE_INITIALIZED,
7699 /* RGB keyboard is disabled. */
7700 RGBKBD_STATE_DISABLED,
7701 /* RGB keyboard is enabled and ready to receive a command. */
7702 RGBKBD_STATE_ENABLED,
7703
7704 /* Put no more entry below */
7705 RGBKBD_STATE_COUNT,
7706};
7707
7708enum ec_rgbkbd_subcmd {
7709 EC_RGBKBD_SUBCMD_CLEAR = 1,
7710 EC_RGBKBD_SUBCMD_DEMO = 2,
7711 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007712 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007713 EC_RGBKBD_SUBCMD_COUNT
7714};
7715
7716enum ec_rgbkbd_demo {
7717 EC_RGBKBD_DEMO_OFF = 0,
7718 EC_RGBKBD_DEMO_FLOW = 1,
7719 EC_RGBKBD_DEMO_DOT = 2,
7720 EC_RGBKBD_DEMO_COUNT,
7721};
7722
7723BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7724
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007725enum ec_rgbkbd_type {
7726 EC_RGBKBD_TYPE_UNKNOWN = 0,
7727 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7728 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7729 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7730 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7731 EC_RGBKBD_TYPE_COUNT,
7732};
7733
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007734struct ec_rgbkbd_set_scale {
7735 uint8_t key;
7736 struct rgb_s scale;
7737};
7738
7739struct ec_params_rgbkbd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007740 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007741 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007742 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7743 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007744 struct ec_rgbkbd_set_scale set_scale;
7745 };
7746} __ec_align1;
7747
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007748struct ec_response_rgbkbd {
7749 /*
7750 * RGBKBD type supported by the device.
7751 */
7752
7753 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7754} __ec_align1;
7755
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007756struct ec_params_rgbkbd_set_color {
7757 /* Specifies the starting key ID whose color is being changed. */
7758 uint8_t start_key;
7759 /* Specifies # of elements in <color>. */
7760 uint8_t length;
7761 /* RGB color data array of length up to MAX_KEY_COUNT. */
7762 struct rgb_s color[];
7763} __ec_align1;
7764
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007765/*
7766 * Gather the response to the most recent VDM REQ from the AP, as well
7767 * as popping the oldest VDM:Attention from the DPM queue
7768 */
7769#define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7770
7771struct ec_params_typec_vdm_response {
7772 uint8_t port;
7773} __ec_align1;
7774
7775struct ec_response_typec_vdm_response {
7776 /* Number of 32-bit fields filled in */
7777 uint8_t vdm_data_objects;
7778 /* Partner to address - see enum typec_partner_type */
7779 uint8_t partner_type;
7780 /* enum ec_status describing VDM response */
7781 uint16_t vdm_response_err;
7782 /* VDM data, including VDM header */
7783 uint32_t vdm_response[VDO_MAX_SIZE];
7784 /* Number of 32-bit Attention fields filled in */
7785 uint8_t vdm_attention_objects;
7786 /* Number of remaining messages to consume */
7787 uint8_t vdm_attention_left;
7788 /* Reserved */
7789 uint16_t reserved1;
7790 /* VDM:Attention contents */
7791 uint32_t vdm_attention[2];
7792} __ec_align1;
7793
Simon Glassd3870a22023-11-09 08:43:30 -07007794/*
7795 * Get an active battery config from the EC.
7796 */
7797#define EC_CMD_BATTERY_CONFIG 0x013D
7798
7799/* Version of struct batt_conf_header and its internals. */
7800#define EC_BATTERY_CONFIG_STRUCT_VERSION 0x00
7801
7802/* Number of writes needed to invoke battery cutoff command */
7803#define SHIP_MODE_WRITES 2
7804
7805struct ship_mode_info {
7806 uint8_t reg_addr;
7807 uint8_t reserved;
7808 uint16_t reg_data[SHIP_MODE_WRITES];
7809} __packed __aligned(2);
7810
7811struct sleep_mode_info {
7812 uint8_t reg_addr;
7813 uint8_t reserved;
7814 uint16_t reg_data;
7815} __packed __aligned(2);
7816
7817struct fet_info {
7818 uint8_t reg_addr;
7819 uint8_t reserved;
7820 uint16_t reg_mask;
7821 uint16_t disconnect_val;
7822 uint16_t cfet_mask; /* CHG FET status mask */
7823 uint16_t cfet_off_val;
7824} __packed __aligned(2);
7825
7826enum fuel_gauge_flags {
7827 /*
7828 * Write Block Support. If enabled, we use a i2c write block command
7829 * instead of a 16-bit write. The effective difference is the i2c
7830 * transaction will prefix the length (2).
7831 */
7832 FUEL_GAUGE_FLAG_WRITE_BLOCK = BIT(0),
7833 /* Sleep command support. fuel_gauge_info.sleep_mode must be defined. */
7834 FUEL_GAUGE_FLAG_SLEEP_MODE = BIT(1),
7835 /*
7836 * Manufacturer access command support. If enabled, FET status is read
7837 * from the OperationStatus (0x54) register using the
7838 * ManufacturerBlockAccess (0x44).
7839 */
7840 FUEL_GAUGE_FLAG_MFGACC = BIT(2),
7841 /*
7842 * SMB block protocol support in manufacturer access command. If
7843 * enabled, FET status is read from the OperationStatus (0x54) register
7844 * using the ManufacturerBlockAccess (0x44).
7845 */
7846 FUEL_GAUGE_FLAG_MFGACC_SMB_BLOCK = BIT(3),
7847};
7848
7849struct fuel_gauge_info {
7850 uint32_t flags;
7851 uint32_t board_flags;
7852 struct ship_mode_info ship_mode;
7853 struct sleep_mode_info sleep_mode;
7854 struct fet_info fet;
7855} __packed __aligned(4);
7856
7857/* Battery constants */
7858struct battery_info {
7859 /* Operation voltage in mV */
7860 uint16_t voltage_max;
7861 uint16_t voltage_normal;
7862 uint16_t voltage_min;
7863 /* (TODO(chromium:756700): add desired_charging_current */
7864 /**
7865 * Pre-charge to fast charge threshold in mV,
7866 * default to voltage_min if not specified.
7867 * This option is only available on isl923x and rt946x.
7868 */
7869 uint16_t precharge_voltage;
7870 /* Pre-charge current in mA */
7871 uint16_t precharge_current;
7872 /* Working temperature ranges in degrees C */
7873 int8_t start_charging_min_c;
7874 int8_t start_charging_max_c;
7875 int8_t charging_min_c;
7876 int8_t charging_max_c;
7877 int8_t discharging_min_c;
7878 int8_t discharging_max_c;
7879 /* Used only if CONFIG_BATTERY_VENDOR_PARAM is defined. */
7880 uint8_t vendor_param_start;
7881 uint8_t reserved;
7882} __packed __aligned(2);
7883
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007884/*
Simon Glassd3870a22023-11-09 08:43:30 -07007885 * The 'config' of a battery.
7886 */
7887struct board_batt_params {
7888 struct fuel_gauge_info fuel_gauge;
7889 struct battery_info batt_info;
7890} __packed __aligned(4);
7891
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007892/*
7893 * The SBS defines a string object as a block of chars, 32 byte maximum, where
7894 * the first byte indicates the number of chars in the block (excluding the
7895 * first byte).
7896 *
7897 * Thus, the actual string length (i.e. the value strlen returns) is limited to
7898 * 31 (=SBS_MAX_STR_SIZE).
7899 *
7900 * SBS_MAX_STR_OBJ_SIZE can be used as the size of a buffer for an SBS string
7901 * object but also as a buffer for a c-lang string because the null terminating
7902 * char also takes one byte.
7903 */
7904#define SBS_MAX_STR_SIZE 31
7905#define SBS_MAX_STR_OBJ_SIZE (SBS_MAX_STR_SIZE + 1)
Simon Glassd3870a22023-11-09 08:43:30 -07007906
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007907/*
Simon Glassd3870a22023-11-09 08:43:30 -07007908 * Header describing a battery config stored in CBI. Only struct_version has
7909 * size and position independent of struct_version. The rest varies as
7910 * struct_version changes.
7911 *
7912 * Version 0
7913 * Layout:
7914 * +-------------+
7915 * | header |
7916 * +-------------+
7917 * | | ^
7918 * | manuf_name | | manuf_name_size
7919 * | | v
7920 * +-------------+
7921 * | device_name | ^
7922 * | | | device_name_size
7923 * | | v
7924 * +-------------+
7925 * | config | ^
7926 * | | |
7927 * | | | cbi data size
7928 * | | | - (header_size+manuf_name_size+device_name_size)
7929 * | | |
7930 * | | v
7931 * +-------------+
7932 * Note:
7933 * - manuf_name and device_name are not null-terminated.
7934 * - The config isn't aligned. It should be copied to struct board_batt_params
7935 * before its contents are accessed.
7936 */
7937struct batt_conf_header {
7938 /* Version independent field. It's always here as a uint8_t. */
7939 uint8_t struct_version;
7940 /* Version 0 members */
7941 uint8_t manuf_name_size;
7942 uint8_t device_name_size;
7943 uint8_t reserved;
7944 /* manuf_name, device_name, board_batt_params follow after this. */
7945} __packed;
7946
Aseda Aboagyeabc38122024-04-15 15:39:55 -05007947#define BATT_CONF_MAX_SIZE \
7948 (sizeof(struct batt_conf_header) + SBS_MAX_STR_OBJ_SIZE * 2 + \
Simon Glassd3870a22023-11-09 08:43:30 -07007949 sizeof(struct board_batt_params))
7950
7951/*
7952 * Record the current AP firmware state. This is used to help testing, such as
7953 * with FAFT (Fully-Automated Firmware Test), which likes to know which firmware
7954 * screen is currently displayed.
7955 */
7956
7957#define EC_CMD_AP_FW_STATE 0x013E
7958
7959struct ec_params_ap_fw_state {
7960 /*
7961 * Value which indicates the state. This is not decoded by the EC, so
7962 * its meaning is entirely outside this code base.
7963 */
7964 uint32_t state;
7965} __ec_align1;
7966
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00007967/*
7968 * UCSI OPM-PPM commands
7969 *
7970 * These commands are used for communication between OPM and PPM.
7971 * Only UCSI3.0 is tested.
7972 */
7973
7974#define EC_CMD_UCSI_PPM_SET 0x0140
7975
7976/* The data size is stored in the host command protocol header. */
7977struct ec_params_ucsi_ppm_set {
7978 uint16_t offset;
7979 uint8_t data[];
7980} __ec_align2;
7981
7982#define EC_CMD_UCSI_PPM_GET 0x0141
7983
7984/* For 'GET' sub-commands, data will be returned as a raw payload. */
7985struct ec_params_ucsi_ppm_get {
7986 uint16_t offset;
7987 uint8_t size;
7988} __ec_align2;
7989
7990#define EC_CMD_SET_ALARM_SLP_S0_DBG 0x0142
7991
7992/* RTC params and response structures */
7993struct ec_params_set_alarm_slp_s0_dbg {
7994 uint32_t time;
7995} __ec_align2;
7996
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007997/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007998/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007999
8000/*****************************************************************************/
8001/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008002 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08008003 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008004#define EC_CMD_CR51_BASE 0x0300
8005#define EC_CMD_CR51_LAST 0x03FF
8006
8007/*****************************************************************************/
8008/* Fingerprint MCU commands: range 0x0400-0x040x */
8009
Simon Glassd3870a22023-11-09 08:43:30 -07008010/*
8011 * Fingerprint SPI sensor passthru command
8012 *
8013 * This command was used for prototyping and it's now deprecated.
8014 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008015#define EC_CMD_FP_PASSTHRU 0x0400
8016
8017#define EC_FP_FLAG_NOT_COMPLETE 0x1
8018
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008019struct ec_params_fp_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08008020 uint16_t len; /* Number of bytes to write then read */
8021 uint16_t flags; /* EC_FP_FLAG_xxx */
8022 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008023} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008024
8025/* Configure the Fingerprint MCU behavior */
8026#define EC_CMD_FP_MODE 0x0402
8027
8028/* Put the sensor in its lowest power mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008029#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008030/* Wait to see a finger on the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008031#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008032/* Poll until the finger has left the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008033#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008034/* Capture the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008035#define FP_MODE_CAPTURE BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008036/* Finger enrollment session on-going */
8037#define FP_MODE_ENROLL_SESSION BIT(4)
8038/* Enroll the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008039#define FP_MODE_ENROLL_IMAGE BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008040/* Try to match the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008041#define FP_MODE_MATCH BIT(6)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008042/* Reset and re-initialize the sensor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008043#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08008044/* Sensor maintenance for dead pixels. */
8045#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008046/* special value: don't change anything just read back current mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008047#define FP_MODE_DONT_CHANGE BIT(31)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008048
Caveh Jalali024ffe32023-01-30 14:35:19 -08008049#define FP_VALID_MODES \
8050 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
8051 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
8052 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
8053 FP_MODE_DONT_CHANGE)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008054
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008055/* Capture types defined in bits [30..28] */
8056#define FP_MODE_CAPTURE_TYPE_SHIFT 28
Caveh Jalali024ffe32023-01-30 14:35:19 -08008057#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08008058/**
8059 * enum fp_capture_type - Specifies the "mode" when capturing images.
8060 *
8061 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
8062 * image (produces 'frame_size' bytes)
8063 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
8064 * bpp bits)
8065 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
8066 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
8067 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
8068 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
8069 * @FP_CAPTURE_TYPE_MAX: End of enum
8070 *
8071 * @note This enum must remain ordered, if you add new values you must ensure
8072 * that FP_CAPTURE_TYPE_MAX is still the last one.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008073 */
8074enum fp_capture_type {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008075 FP_CAPTURE_VENDOR_FORMAT = 0,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008076 FP_CAPTURE_SIMPLE_IMAGE = 1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008077 FP_CAPTURE_PATTERN0 = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008078 FP_CAPTURE_PATTERN1 = 3,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008079 FP_CAPTURE_QUALITY_TEST = 4,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008080 FP_CAPTURE_RESET_TEST = 5,
8081 FP_CAPTURE_TYPE_MAX,
8082};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008083/* Extracts the capture type from the sensor 'mode' word */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008084#define FP_CAPTURE_TYPE(mode) \
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008085 (((mode) & FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008086
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008087struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008088 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008089} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008090
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008091struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008092 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008093} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008094
8095/* Retrieve Fingerprint sensor information */
8096#define EC_CMD_FP_INFO 0x0403
8097
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008098/* Number of dead pixels detected on the last maintenance */
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008099#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008100/* Unknown number of dead pixels detected on the last maintenance */
8101#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008102/* No interrupt from the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008103#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008104/* SPI communication error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008105#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008106/* Invalid sensor Hardware ID */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008107#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008108/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008109#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008110
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008111struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008112 /* Sensor identification */
8113 uint32_t vendor_id;
8114 uint32_t product_id;
8115 uint32_t model_id;
8116 uint32_t version;
8117 /* Image frame characteristics */
8118 uint32_t frame_size;
8119 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
8120 uint16_t width;
8121 uint16_t height;
8122 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008123 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008124} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008126struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008127 /* Sensor identification */
8128 uint32_t vendor_id;
8129 uint32_t product_id;
8130 uint32_t model_id;
8131 uint32_t version;
8132 /* Image frame characteristics */
8133 uint32_t frame_size;
8134 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
8135 uint16_t width;
8136 uint16_t height;
8137 uint16_t bpp;
8138 uint16_t errors; /* see FP_ERROR_ flags above */
8139 /* Template/finger current information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008140 uint32_t template_size; /* max template size in bytes */
8141 uint16_t template_max; /* maximum number of fingers/templates */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008142 uint16_t template_valid; /* number of valid fingers/templates */
8143 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008144 uint32_t template_version; /* version of the template format */
8145} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008146
8147/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008148#define EC_CMD_FP_FRAME 0x0404
8149
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008150/* constants defining the 'offset' field which also contains the frame index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008151#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008152/* Frame buffer where the captured image is stored */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008153#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008154/* First frame buffer holding a template */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008155#define FP_FRAME_INDEX_TEMPLATE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008156#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08008157#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008158
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008159/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07008160#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008161
8162/* Constants for encryption parameters */
8163#define FP_CONTEXT_NONCE_BYTES 12
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00008164#define FP_CONTEXT_USERID_BYTES 32
8165#define FP_CONTEXT_USERID_WORDS (FP_CONTEXT_USERID_BYTES / sizeof(uint32_t))
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008166#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07008167#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008168#define FP_CONTEXT_TPM_BYTES 32
8169
Jett Rinkba2edaf2020-01-14 11:49:06 -07008170/* Constants for positive match parameters. */
8171#define FP_POSITIVE_MATCH_SALT_BYTES 16
8172
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008173struct ec_fp_template_encryption_metadata {
8174 /*
8175 * Version of the structure format (N=3).
8176 */
8177 uint16_t struct_version;
8178 /* Reserved bytes, set to 0. */
8179 uint16_t reserved;
8180 /*
8181 * The salt is *only* ever used for key derivation. The nonce is unique,
8182 * a different one is used for every message.
8183 */
8184 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07008185 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008186 uint8_t tag[FP_CONTEXT_TAG_BYTES];
8187};
8188
8189struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008190 /*
8191 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
8192 * in the high nibble, and the real offset within the frame in
8193 * FP_FRAME_OFFSET_MASK.
8194 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008195 uint32_t offset;
8196 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008197} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008198
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008199/* Load a template into the MCU */
8200#define EC_CMD_FP_TEMPLATE 0x0405
8201
8202/* Flag in the 'size' field indicating that the full template has been sent */
8203#define FP_TEMPLATE_COMMIT 0x80000000
8204
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008205struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008206 uint32_t offset;
8207 uint32_t size;
8208 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008209} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008210
8211/* Clear the current fingerprint user context and set a new one */
8212#define EC_CMD_FP_CONTEXT 0x0406
8213
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008214struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008215 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008216} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008217
Jett Rinkba2edaf2020-01-14 11:49:06 -07008218enum fp_context_action {
8219 FP_CONTEXT_ASYNC = 0,
8220 FP_CONTEXT_GET_RESULT = 1,
8221};
8222
8223/* Version 1 of the command is "asynchronous". */
8224struct ec_params_fp_context_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08008225 uint8_t action; /**< enum fp_context_action */
8226 uint8_t reserved[3]; /**< padding for alignment */
Jett Rinkba2edaf2020-01-14 11:49:06 -07008227 uint32_t userid[FP_CONTEXT_USERID_WORDS];
8228} __ec_align4;
8229
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008230#define EC_CMD_FP_STATS 0x0407
8231
Caveh Jalali024ffe32023-01-30 14:35:19 -08008232#define FPSTATS_CAPTURE_INV BIT(0)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008233#define FPSTATS_MATCHING_INV BIT(1)
8234
8235struct ec_response_fp_stats {
8236 uint32_t capture_time_us;
8237 uint32_t matching_time_us;
8238 uint32_t overall_time_us;
8239 struct {
8240 uint32_t lo;
8241 uint32_t hi;
8242 } overall_t0;
8243 uint8_t timestamps_invalid;
8244 int8_t template_matched;
8245} __ec_align2;
8246
8247#define EC_CMD_FP_SEED 0x0408
8248struct ec_params_fp_seed {
8249 /*
8250 * Version of the structure format (N=3).
8251 */
8252 uint16_t struct_version;
8253 /* Reserved bytes, set to 0. */
8254 uint16_t reserved;
8255 /* Seed from the TPM. */
8256 uint8_t seed[FP_CONTEXT_TPM_BYTES];
8257} __ec_align4;
8258
8259#define EC_CMD_FP_ENC_STATUS 0x0409
8260
8261/* FP TPM seed has been set or not */
8262#define FP_ENC_STATUS_SEED_SET BIT(0)
Simon Glassd3870a22023-11-09 08:43:30 -07008263/* FP using nonce context or not */
8264#define FP_CONTEXT_STATUS_NONCE_CONTEXT_SET BIT(1)
8265/* FP match had been processed or not */
8266#define FP_CONTEXT_STATUS_MATCH_PROCESSED_SET BIT(2)
8267/* FP auth_nonce had been set or not*/
8268#define FP_CONTEXT_AUTH_NONCE_SET BIT(3)
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008269/* FP user_id had been set or not*/
8270#define FP_CONTEXT_USER_ID_SET BIT(4)
8271/* FP templates are unlocked for nonce context or not */
8272#define FP_CONTEXT_TEMPLATE_UNLOCKED_SET BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008273
8274struct ec_response_fp_encryption_status {
8275 /* Used bits in encryption engine status */
8276 uint32_t valid_flags;
8277 /* Encryption engine status */
8278 uint32_t status;
8279} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008280
Jett Rinkba2edaf2020-01-14 11:49:06 -07008281#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
8282struct ec_params_fp_read_match_secret {
8283 uint16_t fgr;
8284} __ec_align4;
8285
8286/* The positive match secret has the length of the SHA256 digest. */
8287#define FP_POSITIVE_MATCH_SECRET_BYTES 32
8288struct ec_response_fp_read_match_secret {
8289 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8290} __ec_align4;
8291
Simon Glassd3870a22023-11-09 08:43:30 -07008292#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN 32
8293
8294struct fp_elliptic_curve_public_key {
8295 uint8_t x[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8296 uint8_t y[FP_ELLIPTIC_CURVE_PUBLIC_KEY_POINT_LEN];
8297} __ec_align4;
8298
8299#define FP_AES_KEY_ENC_METADATA_VERSION 1
8300#define FP_AES_KEY_NONCE_BYTES 12
8301#define FP_AES_KEY_ENCRYPTION_SALT_BYTES 16
8302#define FP_AES_KEY_TAG_BYTES 16
8303
8304struct fp_auth_command_encryption_metadata {
8305 /* Version of the structure format */
8306 uint16_t struct_version;
8307 /* Reserved bytes, set to 0. */
8308 uint16_t reserved;
8309 /*
8310 * The salt is *only* ever used for key derivation. The nonce is unique,
8311 * a different one is used for every message.
8312 */
8313 uint8_t nonce[FP_AES_KEY_NONCE_BYTES];
8314 uint8_t encryption_salt[FP_AES_KEY_ENCRYPTION_SALT_BYTES];
8315 uint8_t tag[FP_AES_KEY_TAG_BYTES];
8316} __ec_align4;
8317
8318#define FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN 32
8319#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8320
8321struct fp_encrypted_private_key {
8322 struct fp_auth_command_encryption_metadata info;
8323 uint8_t data[FP_ELLIPTIC_CURVE_PRIVATE_KEY_LEN];
8324} __ec_align4;
8325
8326#define EC_CMD_FP_ESTABLISH_PAIRING_KEY_KEYGEN 0x0410
8327
8328struct ec_response_fp_establish_pairing_key_keygen {
8329 struct fp_elliptic_curve_public_key pubkey;
8330 struct fp_encrypted_private_key encrypted_private_key;
8331} __ec_align4;
8332
8333#define FP_PAIRING_KEY_LEN 32
8334
8335struct ec_fp_encrypted_pairing_key {
8336 struct fp_auth_command_encryption_metadata info;
8337 uint8_t data[FP_PAIRING_KEY_LEN];
8338} __ec_align4;
8339
8340#define EC_CMD_FP_ESTABLISH_PAIRING_KEY_WRAP 0x0411
8341
8342struct ec_params_fp_establish_pairing_key_wrap {
8343 struct fp_elliptic_curve_public_key peers_pubkey;
8344 struct fp_encrypted_private_key encrypted_private_key;
8345} __ec_align4;
8346
8347struct ec_response_fp_establish_pairing_key_wrap {
8348 struct ec_fp_encrypted_pairing_key encrypted_pairing_key;
8349} __ec_align4;
8350
8351#define EC_CMD_FP_LOAD_PAIRING_KEY 0x0412
8352
8353typedef struct ec_response_fp_establish_pairing_key_wrap
8354 ec_params_fp_load_pairing_key;
8355
8356#define FP_CK_AUTH_NONCE_LEN 32
8357
8358#define EC_CMD_FP_GENERATE_NONCE 0x0413
8359struct ec_response_fp_generate_nonce {
8360 uint8_t nonce[FP_CK_AUTH_NONCE_LEN];
8361} __ec_align4;
8362
8363#define FP_CONTEXT_USERID_LEN 32
8364#define FP_CONTEXT_USERID_IV_LEN 16
8365#define FP_CONTEXT_KEY_LEN 32
8366
8367#define EC_CMD_FP_NONCE_CONTEXT 0x0414
8368struct ec_params_fp_nonce_context {
8369 uint8_t gsc_nonce[FP_CK_AUTH_NONCE_LEN];
8370 uint8_t enc_user_id[FP_CONTEXT_USERID_LEN];
8371 uint8_t enc_user_id_iv[FP_CONTEXT_USERID_IV_LEN];
8372} __ec_align4;
8373
8374#define FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN 16
8375
8376#define EC_CMD_FP_READ_MATCH_SECRET_WITH_PUBKEY 0x0415
8377
8378struct ec_params_fp_read_match_secret_with_pubkey {
8379 uint16_t fgr;
8380 uint16_t reserved;
8381 struct fp_elliptic_curve_public_key pubkey;
8382} __ec_align4;
8383
8384struct ec_response_fp_read_match_secret_with_pubkey {
8385 struct fp_elliptic_curve_public_key pubkey;
8386 uint8_t iv[FP_ELLIPTIC_CURVE_PUBLIC_KEY_IV_LEN];
8387 uint8_t enc_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
8388} __ec_align4;
8389
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008390/* Unlock the fpsensor template with the current nonce context */
8391#define EC_CMD_FP_UNLOCK_TEMPLATE 0x0417
Simon Glassd3870a22023-11-09 08:43:30 -07008392
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008393struct ec_params_fp_unlock_template {
8394 uint16_t fgr_num;
Simon Glassd3870a22023-11-09 08:43:30 -07008395} __ec_align4;
8396
Aseda Aboagye37cea5a2024-06-08 03:37:53 +00008397/*
8398 * Migrate a legacy FP template (here, legacy refers to being generated in a
8399 * raw user_id context instead of a nonce context) by wiping its match secret
8400 * salt and treating it as a newly-enrolled template.
8401 * The legacy FP template needs to be uploaded by FP_TEMPLATE command first
8402 * without committing, then this command will commit it.
8403 */
8404#define EC_CMD_FP_MIGRATE_TEMPLATE_TO_NONCE_CONTEXT 0x0418
8405
8406struct ec_params_fp_migrate_template_to_nonce_context {
8407 /* The context userid used to encrypt this template when it was created.
8408 */
8409 uint32_t userid[FP_CONTEXT_USERID_WORDS];
8410};
8411
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008412/*****************************************************************************/
8413/* Touchpad MCU commands: range 0x0500-0x05FF */
8414
8415/* Perform touchpad self test */
8416#define EC_CMD_TP_SELF_TEST 0x0500
8417
8418/* Get number of frame types, and the size of each type */
8419#define EC_CMD_TP_FRAME_INFO 0x0501
8420
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008421struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008422 uint32_t n_frames;
8423 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008424} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008425
8426/* Create a snapshot of current frame readings */
8427#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
8428
8429/* Read the frame */
8430#define EC_CMD_TP_FRAME_GET 0x0503
8431
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008432struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008433 uint32_t frame_index;
8434 uint32_t offset;
8435 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008436} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08008437
8438/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008439/* EC-EC communication commands: range 0x0600-0x06FF */
8440
8441#define EC_COMM_TEXT_MAX 8
8442
8443/*
8444 * Get battery static information, i.e. information that never changes, or
8445 * very infrequently.
8446 */
8447#define EC_CMD_BATTERY_GET_STATIC 0x0600
8448
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008449/**
8450 * struct ec_params_battery_static_info - Battery static info parameters
8451 * @index: Battery index.
8452 */
8453struct ec_params_battery_static_info {
8454 uint8_t index;
8455} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008456
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008457/**
8458 * struct ec_response_battery_static_info - Battery static info response
8459 * @design_capacity: Battery Design Capacity (mAh)
8460 * @design_voltage: Battery Design Voltage (mV)
8461 * @manufacturer: Battery Manufacturer String
8462 * @model: Battery Model Number String
8463 * @serial: Battery Serial Number String
8464 * @type: Battery Type String
8465 * @cycle_count: Battery Cycle Count
8466 */
8467struct ec_response_battery_static_info {
8468 uint16_t design_capacity;
8469 uint16_t design_voltage;
8470 char manufacturer[EC_COMM_TEXT_MAX];
8471 char model[EC_COMM_TEXT_MAX];
8472 char serial[EC_COMM_TEXT_MAX];
8473 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008474 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008475 uint32_t cycle_count;
8476} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008477
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08008478/**
8479 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
8480 * Equivalent to struct ec_response_battery_static_info, but with longer
8481 * strings.
8482 * @design_capacity: battery design capacity (in mAh)
8483 * @design_voltage: battery design voltage (in mV)
8484 * @cycle_count: battery cycle count
8485 * @manufacturer_ext: battery manufacturer string
8486 * @model_ext: battery model string
8487 * @serial_ext: battery serial number string
8488 * @type_ext: battery type string
8489 */
8490struct ec_response_battery_static_info_v1 {
8491 uint16_t design_capacity;
8492 uint16_t design_voltage;
8493 uint32_t cycle_count;
8494 char manufacturer_ext[12];
8495 char model_ext[12];
8496 char serial_ext[12];
8497 char type_ext[12];
8498} __ec_align4;
8499
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008500/**
8501 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
8502 *
8503 * Equivalent to struct ec_response_battery_static_info, but with strings
8504 * further lengthened (relative to v1) to accommodate the maximum string length
8505 * permitted by the Smart Battery Data Specification revision 1.1 and fields
8506 * renamed to better match that specification.
8507 *
8508 * @design_capacity: battery design capacity (in mAh)
8509 * @design_voltage: battery design voltage (in mV)
8510 * @cycle_count: battery cycle count
8511 * @manufacturer: battery manufacturer string
8512 * @device_name: battery model string
8513 * @serial: battery serial number string
8514 * @chemistry: battery type string
8515 */
8516struct ec_response_battery_static_info_v2 {
8517 uint16_t design_capacity;
8518 uint16_t design_voltage;
8519 uint32_t cycle_count;
Aseda Aboagyeabc38122024-04-15 15:39:55 -05008520 char manufacturer[SBS_MAX_STR_OBJ_SIZE];
8521 char device_name[SBS_MAX_STR_OBJ_SIZE];
8522 char serial[SBS_MAX_STR_OBJ_SIZE];
8523 char chemistry[SBS_MAX_STR_OBJ_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008524} __ec_align4;
8525
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008526/*
8527 * Get battery dynamic information, i.e. information that is likely to change
8528 * every time it is read.
8529 */
8530#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
8531
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008532/**
8533 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
8534 * @index: Battery index.
8535 */
8536struct ec_params_battery_dynamic_info {
8537 uint8_t index;
8538} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008539
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008540/**
8541 * struct ec_response_battery_dynamic_info - Battery dynamic info response
8542 * @actual_voltage: Battery voltage (mV)
8543 * @actual_current: Battery current (mA); negative=discharging
8544 * @remaining_capacity: Remaining capacity (mAh)
8545 * @full_capacity: Capacity (mAh, might change occasionally)
8546 * @flags: Flags, see EC_BATT_FLAG_*
8547 * @desired_voltage: Charging voltage desired by battery (mV)
8548 * @desired_current: Charging current desired by battery (mA)
8549 */
8550struct ec_response_battery_dynamic_info {
8551 int16_t actual_voltage;
8552 int16_t actual_current;
8553 int16_t remaining_capacity;
8554 int16_t full_capacity;
8555 int16_t flags;
8556 int16_t desired_voltage;
8557 int16_t desired_current;
8558} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008559
8560/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06008561 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008562 */
8563#define EC_CMD_CHARGER_CONTROL 0x0602
8564
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008565/**
8566 * struct ec_params_charger_control - Charger control parameters
8567 * @max_current: Charger current (mA). Positive to allow base to draw up to
8568 * max_current and (possibly) charge battery, negative to request current
8569 * from base (OTG).
8570 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
8571 * >= 0.
8572 * @allow_charging: Allow base battery charging (only makes sense if
8573 * max_current > 0).
8574 */
8575struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008576 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008577 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008578 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008579} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008580
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08008581/* Get ACK from the USB-C SS muxes */
8582#define EC_CMD_USB_PD_MUX_ACK 0x0603
8583
8584struct ec_params_usb_pd_mux_ack {
8585 uint8_t port; /* USB-C port number */
8586} __ec_align1;
8587
Caveh Jalali6bd733b2023-01-30 17:06:31 -08008588/* Get boot time */
8589#define EC_CMD_GET_BOOT_TIME 0x0604
8590
8591enum boot_time_param {
8592 ARAIL = 0,
8593 RSMRST,
8594 ESPIRST,
8595 PLTRST_LOW,
8596 PLTRST_HIGH,
8597 EC_CUR_TIME,
8598 RESET_CNT,
8599};
8600
8601struct ec_response_get_boot_time {
8602 uint64_t timestamp[RESET_CNT];
8603 uint16_t cnt;
8604} __ec_align4;
8605
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06008606/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08008607/*
8608 * Reserve a range of host commands for board-specific, experimental, or
8609 * special purpose features. These can be (re)used without updating this file.
8610 *
8611 * CAUTION: Don't go nuts with this. Shipping products should document ALL
8612 * their EC commands for easier development, testing, debugging, and support.
8613 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008614 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
8615 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
8616 *
Duncan Laurieeb316852015-12-01 18:51:18 -08008617 * In your experimental code, you may want to do something like this:
8618 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008619 * #define EC_CMD_MAGIC_FOO 0x0000
8620 * #define EC_CMD_MAGIC_BAR 0x0001
8621 * #define EC_CMD_MAGIC_HEY 0x0002
8622 *
8623 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
8624 * EC_VER_MASK(0);
8625 *
8626 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
8627 * EC_VER_MASK(0);
8628 *
8629 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
8630 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08008631 */
8632#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
8633#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
8634
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008635/*
8636 * Given the private host command offset, calculate the true private host
8637 * command value.
8638 */
8639#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
8640 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
8641
Duncan Laurie93e24442014-01-06 12:30:52 -08008642/*****************************************************************************/
8643/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07008644 * Passthru commands
8645 *
8646 * Some platforms have sub-processors chained to each other. For example.
8647 *
8648 * AP <--> EC <--> PD MCU
8649 *
8650 * The top 2 bits of the command number are used to indicate which device the
8651 * command is intended for. Device 0 is always the device receiving the
8652 * command; other device mapping is board-specific.
8653 *
8654 * When a device receives a command to be passed to a sub-processor, it passes
8655 * it on with the device number set back to 0. This allows the sub-processor
8656 * to remain blissfully unaware of whether the command originated on the next
8657 * device up the chain, or was passed through from the AP.
8658 *
8659 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
8660 * AP sends command 0x4002 to the EC
8661 * EC sends command 0x0002 to the PD MCU
8662 * EC forwards PD MCU response back to the AP
8663 */
8664
8665/* Offset and max command number for sub-device n */
8666#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
8667#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
8668
8669/*****************************************************************************/
8670/*
Duncan Laurie93e24442014-01-06 12:30:52 -08008671 * Deprecated constants. These constants have been renamed for clarity. The
8672 * meaning and size has not changed. Programs that use the old names should
8673 * switch to the new names soon, as the old names may not be carried forward
8674 * forever.
8675 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08008676#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
8677#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
8678#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
Duncan Laurie93e24442014-01-06 12:30:52 -08008679
Caveh Jalali024ffe32023-01-30 14:35:19 -08008680#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07008681
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08008682#ifdef __cplusplus
8683}
8684#endif
8685
Caveh Jalali024ffe32023-01-30 14:35:19 -08008686#endif /* __CROS_EC_EC_COMMANDS_H */