blob: 26c82eab7d3402ffa04530b6e1bca4b6a9e4c832 [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001/* SPDX-License-Identifier: BSD-3-Clause */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002
3/* Host communication command constants for Chrome EC */
4
Duncan Laurieeb316852015-12-01 18:51:18 -08005#ifndef __CROS_EC_EC_COMMANDS_H
6#define __CROS_EC_EC_COMMANDS_H
Stefan Reinauerd6682e82013-02-21 15:39:35 -08007
Patrick Georgi0f6187a2017-07-28 15:57:23 +02008#if !defined(__ACPI__) && !defined(__KERNEL__)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07009#include <stdint.h>
10#endif
11
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070012#ifdef CHROMIUM_EC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080013/*
14 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
15 * It is used to not include macros that may cause conflicts in foreign
16 * projects (refer to crbug.com/984623).
17 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070018
Duncan Laurie67f26cc2017-06-29 23:17:22 -070019/*
20 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
21 * generates more efficient code for accessing request/response structures on
22 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
23 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -070024#include "common.h"
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080025#include "compile_time_macros.h"
26
27#else
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080028/* If BUILD_ASSERT isn't already defined, make it a no-op */
29#ifndef BUILD_ASSERT
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080030#define BUILD_ASSERT(_cond)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080031#endif /* !BUILD_ASSERT */
Caveh Jalali024ffe32023-01-30 14:35:19 -080032#endif /* CHROMIUM_EC */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070033
34#ifdef __KERNEL__
35#include <linux/limits.h>
36#else
37/*
38 * Defines macros that may be needed but are for sure defined by the linux
39 * kernel. This section is removed when cros_ec_commands.h is generated (by
40 * util/make_linux_ec_commands_h.sh).
41 * cros_ec_commands.h looks more integrated to the kernel.
42 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080043
44#ifndef BIT
Caveh Jalali024ffe32023-01-30 14:35:19 -080045#define BIT(nr) (1UL << (nr))
Duncan Laurie67f26cc2017-06-29 23:17:22 -070046#endif
47
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080048#ifndef BIT_ULL
Caveh Jalali024ffe32023-01-30 14:35:19 -080049#define BIT_ULL(nr) (1ULL << (nr))
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080050#endif
51
Yu-Ping Wu9ff78232021-01-06 18:13:36 +080052/*
53 * When building Zephyr, this file ends up being included before Zephyr's
54 * include/sys/util.h so causes a warning there. We don't want to add an #ifdef
55 * in that file since it won't be accepted upstream. So work around it here.
56 */
57#ifndef CONFIG_ZEPHYR
58#ifndef GENMASK
59#define GENMASK(h, l) (((BIT(h) << 1) - 1) ^ (BIT(l) - 1))
60#endif
61
62#ifndef GENMASK_ULL
63#define GENMASK_ULL(h, l) (((BIT_ULL(h) << 1) - 1) ^ (BIT_ULL(l) - 1))
64#endif
65#endif
66
Caveh Jalali024ffe32023-01-30 14:35:19 -080067#endif /* __KERNEL__ */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080068
Rob Barnes8bc5fa92021-06-28 09:32:28 -060069#ifdef __cplusplus
70extern "C" {
71#endif
72
Caveh Jalali6bd733b2023-01-30 17:06:31 -080073/**
74 * Constant for creation of flexible array members that work in both C and
75 * C++. Flexible array members were added in C99 and are not part of the C++
76 * standard. However, clang++ supports them for C++.
77 * When compiling with gcc, flexible array members are not allowed to appear
78 * in an otherwise empty struct, so we use the GCC zero-length array
79 * extension that works with both clang/gcc/g++.
80 */
81#if defined(__cplusplus) && defined(__clang__)
82#define FLEXIBLE_ARRAY_MEMBER_SIZE
83#else
84#define FLEXIBLE_ARRAY_MEMBER_SIZE 0
85#endif
86
Stefan Reinauerd6682e82013-02-21 15:39:35 -080087/*
Duncan Laurie93e24442014-01-06 12:30:52 -080088 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080089 *
Duncan Laurie93e24442014-01-06 12:30:52 -080090 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
91 * determined in other ways. Remove this once the kernel code no longer
92 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080093 */
Caveh Jalali024ffe32023-01-30 14:35:19 -080094#define EC_PROTO_VERSION 0x00000002
Stefan Reinauerd6682e82013-02-21 15:39:35 -080095
96/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080097#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -080098
99/* I/O addresses for ACPI commands */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800100#define EC_LPC_ADDR_ACPI_DATA 0x62
101#define EC_LPC_ADDR_ACPI_CMD 0x66
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800102
103/* I/O addresses for host command */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800104#define EC_LPC_ADDR_HOST_DATA 0x200
105#define EC_LPC_ADDR_HOST_CMD 0x204
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800106
107/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -0800108/* Protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800109#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800110/* For version 2 params; size is EC_PROTO2_MAX_PARAM_SIZE */
111#define EC_LPC_ADDR_HOST_PARAM 0x804
112
Duncan Laurie93e24442014-01-06 12:30:52 -0800113/* Protocol version 3 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800114#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
115#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800117/*
118 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
119 * and they tell the kernel that so we have to think of it as two parts.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800120 *
121 * Other BIOSes report only the I/O port region spanned by the Microchip
122 * MEC series EC; an attempt to address a larger region may fail.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800123 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800124#define EC_HOST_CMD_REGION0 0x800
125#define EC_HOST_CMD_REGION1 0x880
126#define EC_HOST_CMD_REGION_SIZE 0x80
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800127#define EC_HOST_CMD_MEC_REGION_SIZE 0x8
Bill Richardsone221aad2013-06-12 10:50:41 -0700128
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800129/* EC command register bit functions */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800130#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
131#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
132#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
133#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
134#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
135#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
136#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800137
Caveh Jalali024ffe32023-01-30 14:35:19 -0800138#define EC_LPC_ADDR_MEMMAP 0x900
139#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
140#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800141
142/* The offset address of each type of data in mapped memory. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800143#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
144#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
145#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
146#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
147#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
148#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
149#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800150#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800151#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
152#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700153/* Unused 0x28 - 0x2f */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800154#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700155/* Unused 0x31 - 0x33 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800156#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600157/* Battery values are all 32 bits, unless otherwise noted. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800158#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
159#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
160#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
161#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
162#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
163#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600164/* Unused 0x4f */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800165#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
166#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
167#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
168#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700169/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800170#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
171#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
172#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
173#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
174#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700175/* Unused 0x84 - 0x8f */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800176#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700177/* Unused 0x91 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800178#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
Duncan Laurieeb316852015-12-01 18:51:18 -0800179/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
180/* 0x94 - 0x99: 1st Accelerometer */
181/* 0x9a - 0x9f: 2nd Accelerometer */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800182
Caveh Jalali024ffe32023-01-30 14:35:19 -0800183#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800184#define EC_MEMMAP_GPU 0xa6 /* GPU-specific, 8 bits */
185
186/*
187 * Bit fields for EC_MEMMAP_GPU
188 * 0:2: D-Notify level (0:D1, ... 4:D5)
189 * 3: Over temperature
190 */
191#define EC_MEMMAP_GPU_D_NOTIFY_MASK GENMASK(2, 0)
192#define EC_MEMMAP_GPU_OVERT_BIT BIT(3)
193
194/* Power Participant related components */
195#define EC_MEMMAP_PWR_SRC 0xa7 /* Power source (8-bit) */
196/* Unused 0xa8 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700197
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700198/*
199 * ACPI is unable to access memory mapped data at or above this offset due to
200 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
201 * which might be needed by ACPI.
202 */
203#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700204
205/* Define the format of the accelerometer mapped memory status byte. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800206#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
207#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
208#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800209
210/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800211#define EC_TEMP_SENSOR_ENTRIES 16
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800212/*
213 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
214 *
215 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
216 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800217#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800218
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -0800219/* Max temp sensor entries for host commands */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800220#define EC_MAX_TEMP_SENSOR_ENTRIES \
221 (EC_TEMP_SENSOR_ENTRIES + EC_TEMP_SENSOR_B_ENTRIES)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -0800222
Duncan Laurie93e24442014-01-06 12:30:52 -0800223/* Special values for mapped temperature sensors */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800224#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
225#define EC_TEMP_SENSOR_ERROR 0xfe
226#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
Duncan Laurie433432b2013-06-03 10:38:22 -0700227#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800228/*
229 * The offset of temperature value stored in mapped memory. This allows
230 * reporting a temperature range of 200K to 454K = -73C to 181C.
231 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800232#define EC_TEMP_SENSOR_OFFSET 200
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800233
Duncan Laurie93e24442014-01-06 12:30:52 -0800234/*
235 * Number of ALS readings at EC_MEMMAP_ALS
236 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800237#define EC_ALS_ENTRIES 2
Duncan Laurie93e24442014-01-06 12:30:52 -0800238
239/*
240 * The default value a temperature sensor will return when it is present but
241 * has not been read this boot. This is a reasonable number to avoid
242 * triggering alarms on the host.
243 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800244#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
Duncan Laurie93e24442014-01-06 12:30:52 -0800245
Caveh Jalali024ffe32023-01-30 14:35:19 -0800246#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
247#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800248
249/* Report 0 for fan stalled so userspace applications can take
250 * an appropriate action based on this value to control the fan.
251 */
252#define EC_FAN_SPEED_STALLED 0x0 /* Fan stalled */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800253
254/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800255#define EC_BATT_FLAG_AC_PRESENT 0x01
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800256#define EC_BATT_FLAG_BATT_PRESENT 0x02
Caveh Jalali024ffe32023-01-30 14:35:19 -0800257#define EC_BATT_FLAG_DISCHARGING 0x04
258#define EC_BATT_FLAG_CHARGING 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800259#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600260/* Set if some of the static/dynamic data is invalid (or outdated). */
261#define EC_BATT_FLAG_INVALID_DATA 0x20
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800262#define EC_BATT_FLAG_CUT_OFF 0x40
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800263
264/* Switch flags at EC_MEMMAP_SWITCHES */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800265#define EC_SWITCH_LID_OPEN 0x01
266#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800267#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700268/* Was recovery requested via keyboard; now unused. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800269#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800270/* Recovery requested via dedicated signal (from servo board) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800271#define EC_SWITCH_DEDICATED_RECOVERY 0x10
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800272/* Was fake developer mode switch; now unused. Remove in next refactor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800273#define EC_SWITCH_IGNORE0 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800274
275/* Host command interface flags */
276/* Host command interface supports LPC args (LPC interface only) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800277#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800278/* Host command interface supports version 3 protocol */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800279#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800280
281/* Wireless switch flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800282#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
283#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
284#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
285#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
286#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800287
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700288/*****************************************************************************/
289/*
290 * ACPI commands
291 *
292 * These are valid ONLY on the ACPI command/data port.
293 */
294
295/*
296 * ACPI Read Embedded Controller
297 *
298 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
299 *
300 * Use the following sequence:
301 *
302 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
303 * - Wait for EC_LPC_CMDR_PENDING bit to clear
304 * - Write address to EC_LPC_ADDR_ACPI_DATA
305 * - Wait for EC_LPC_CMDR_DATA bit to set
306 * - Read value from EC_LPC_ADDR_ACPI_DATA
307 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700308#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700309
310/*
311 * ACPI Write Embedded Controller
312 *
313 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
314 *
315 * Use the following sequence:
316 *
317 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
318 * - Wait for EC_LPC_CMDR_PENDING bit to clear
319 * - Write address to EC_LPC_ADDR_ACPI_DATA
320 * - Wait for EC_LPC_CMDR_PENDING bit to clear
321 * - Write value to EC_LPC_ADDR_ACPI_DATA
322 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700323#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700324
325/*
326 * ACPI Burst Enable Embedded Controller
327 *
328 * This enables burst mode on the EC to allow the host to issue several
329 * commands back-to-back. While in this mode, writes to mapped multi-byte
330 * data are locked out to ensure data consistency.
331 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700332#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700333
334/*
335 * ACPI Burst Disable Embedded Controller
336 *
337 * This disables burst mode on the EC and stops preventing EC writes to mapped
338 * multi-byte data.
339 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700340#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700341
342/*
343 * ACPI Query Embedded Controller
344 *
345 * This clears the lowest-order bit in the currently pending host events, and
346 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
347 * event 0x80000000 = 32), or 0 if no event was pending.
348 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700349#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700350
351/* Valid addresses in ACPI memory space, for read/write commands */
352
353/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800354#define EC_ACPI_MEM_VERSION 0x00
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700355/*
356 * Test location; writing value here updates test compliment byte to (0xff -
357 * value).
358 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800359#define EC_ACPI_MEM_TEST 0x01
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700360/* Test compliment; writes here are ignored. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800361#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700362
363/* Keyboard backlight brightness percent (0 - 100) */
364#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
365/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800366#define EC_ACPI_MEM_FAN_DUTY 0x04
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700367
368/*
369 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
370 * independent thresholds attached to them. The current value of the ID
371 * register determines which sensor is affected by the THRESHOLD and COMMIT
372 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
373 * as the memory-mapped sensors. The COMMIT register applies those settings.
374 *
375 * The spec does not mandate any way to read back the threshold settings
376 * themselves, but when a threshold is crossed the AP needs a way to determine
377 * which sensor(s) are responsible. Each reading of the ID register clears and
378 * returns one sensor ID that has crossed one of its threshold (in either
379 * direction) since the last read. A value of 0xFF means "no new thresholds
380 * have tripped". Setting or enabling the thresholds for a sensor will clear
381 * the unread event count for that sensor.
382 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800383#define EC_ACPI_MEM_TEMP_ID 0x05
384#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
385#define EC_ACPI_MEM_TEMP_COMMIT 0x07
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700386/*
387 * Here are the bits for the COMMIT register:
388 * bit 0 selects the threshold index for the chosen sensor (0/1)
389 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
390 * Each write to the commit register affects one threshold.
391 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800392#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
393#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700394/*
395 * Example:
396 *
397 * Set the thresholds for sensor 2 to 50 C and 60 C:
398 * write 2 to [0x05] -- select temp sensor 2
399 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
400 * write 0x2 to [0x07] -- enable threshold 0 with this value
401 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
402 * write 0x3 to [0x07] -- enable threshold 1 with this value
403 *
404 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
405 * write 2 to [0x05] -- select temp sensor 2
406 * write 0x1 to [0x07] -- disable threshold 1
407 */
408
409/* DPTF battery charging current limit */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800410#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700411
412/* Charging limit is specified in 64 mA steps */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800413#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700414/* Value to disable DPTF battery charging limit */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800415#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700416
jiazi Yang51fc93f2016-07-28 05:15:01 -0400417/*
418 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800419 * Bits Definition
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800420 * 4 Off Body/On Body status: 0 = Off Body.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800421 * 3:1 Device DPTF Profile Number (DDPN)
422 * 0 = Reserved for backward compatibility (indicates no valid
423 * profile number. Host should fall back to using TBMD).
424 * 1..7 = DPTF Profile number to indicate to host which table needs
425 * to be loaded.
426 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400427 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700428#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
Caveh Jalali024ffe32023-01-30 14:35:19 -0800429#define EC_ACPI_MEM_TBMD_SHIFT 0
430#define EC_ACPI_MEM_TBMD_MASK 0x1
431#define EC_ACPI_MEM_DDPN_SHIFT 1
432#define EC_ACPI_MEM_DDPN_MASK 0x7
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800433#define EC_ACPI_MEM_STTB_SHIFT 4
434#define EC_ACPI_MEM_STTB_MASK 0x1
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700435
436/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600437 * Report device features. Uses the same format as the host command, except:
438 *
439 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
440 * of features", which is of limited interest when the system is already
441 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
442 * these are supported, it defaults to 0.
443 * This allows detecting the presence of this field since older versions of
444 * the EC codebase would simply return 0xff to that unknown address. Check
445 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
446 * are valid.
447 */
448#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
449#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
450#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
451#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
452#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
453#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
454#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
455#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
456
Caveh Jalali024ffe32023-01-30 14:35:19 -0800457#define EC_ACPI_MEM_BATTERY_INDEX 0x12
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600458
459/*
460 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
461 * is enabled (1) or disabled (0).
462 * bit 0 USB port ID 0
463 * ...
464 * bit 7 USB port ID 7
465 */
466#define EC_ACPI_MEM_USB_PORT_POWER 0x13
467
468/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600469 * USB Retimer firmware update.
470 * Read:
471 * Result of last operation AP requested
472 * Write:
473 * bits[3:0]: USB-C port number
474 * bits[7:4]: Operation requested by AP
475 *
476 * NDA (no device attached) case:
477 * To update retimer firmware, AP needs set up TBT Alt mode.
478 * AP requests operations in this sequence:
479 * 1. Get port information about which ports support retimer firmware update.
480 * In the query result, each bit represents one port.
481 * 2. Get current MUX mode, it's NDA.
482 * 3. Suspend specified PD port's task.
483 * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode ->
484 * update firmware -> disconnect MUX -> resume PD task.
485 *
486 * DA (device attached) cases:
487 * Retimer firmware update is not supported in DA cases.
488 * 1. Get port information about which ports support retimer firmware update
489 * 2. Get current MUX mode, it's DA.
490 * 3. AP continues. No more retimer firmware update activities.
491 *
492 */
493#define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14
494
495#define USB_RETIMER_FW_UPDATE_OP_SHIFT 4
Caveh Jalali024ffe32023-01-30 14:35:19 -0800496#define USB_RETIMER_FW_UPDATE_ERR 0xfe
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600497#define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff
Scott Chao18141d8c2021-07-30 10:40:57 +0800498/* Mask to clear unused MUX bits in retimer firmware update */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800499#define USB_RETIMER_FW_UPDATE_MUX_MASK \
500 (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED | \
501 USB_PD_MUX_SAFE_MODE | USB_PD_MUX_TBT_COMPAT_ENABLED | \
502 USB_PD_MUX_USB4_ENABLED)
Scott Chao18141d8c2021-07-30 10:40:57 +0800503
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600504/* Retimer firmware update operations */
505#define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
506#define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800507#define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
508#define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
509#define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
510#define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
511#define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600512#define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
513
Caveh Jalali024ffe32023-01-30 14:35:19 -0800514#define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x)&0x0f)
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600515#define EC_ACPI_MEM_USB_RETIMER_OP(x) \
Caveh Jalali024ffe32023-01-30 14:35:19 -0800516 (((x)&0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600517
518/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700519 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
520 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
521 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800522#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
523#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700524
525/* Current version of ACPI memory address space */
526#define EC_ACPI_MEM_VERSION_CURRENT 2
527
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800528/*
529 * This header file is used in coreboot both in C and ACPI code. The ACPI code
530 * is pre-processed to handle constants but the ASL compiler is unable to
531 * handle actual C code so keep it separate.
532 */
533#ifndef __ACPI__
534
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800535#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800536/*
537 * Define __packed if someone hasn't beat us to it. Linux kernel style
538 * checking prefers __packed over __attribute__((packed)).
539 */
540#ifndef __packed
541#define __packed __attribute__((packed))
542#endif
543
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700544#ifndef __aligned
545#define __aligned(x) __attribute__((aligned(x)))
546#endif
Caveh Jalali024ffe32023-01-30 14:35:19 -0800547#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700548
549/*
550 * Attributes for EC request and response packets. Just defining __packed
551 * results in inefficient assembly code on ARM, if the structure is actually
552 * 32-bit aligned, as it should be for all buffers.
553 *
554 * Be very careful when adding these to existing structures. They will round
555 * up the structure size to the specified boundary.
556 *
557 * Also be very careful to make that if a structure is included in some other
558 * parent structure that the alignment will still be true given the packing of
559 * the parent structure. This is particularly important if the sub-structure
560 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200561 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700562 *
563 * Also be very careful using __packed - particularly when nesting non-packed
564 * structures inside packed ones. In fact, DO NOT use __packed directly;
565 * always use one of these attributes.
566 *
567 * Once everything is annotated properly, the following search strings should
568 * not return ANY matches in this file other than right here:
569 *
570 * "__packed" - generates inefficient code; all sub-structs must also be packed
571 *
572 * "struct [^_]" - all structs should be annotated, except for structs that are
573 * members of other structs/unions (and their original declarations should be
574 * annotated).
575 */
576#ifdef CONFIG_HOSTCMD_ALIGNED
577
578/*
579 * Packed structures where offset and size are always aligned to 1, 2, or 4
580 * byte boundary.
581 */
582#define __ec_align1 __packed
583#define __ec_align2 __packed __aligned(2)
584#define __ec_align4 __packed __aligned(4)
585
586/*
587 * Packed structure which must be under-aligned, because its size is not a
588 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
589 * of all multi-byte fields in it, even though they are themselves aligned.
590 *
591 * In theory, we could duplicate the structure with __aligned(4) for accessing
592 * its members, but use the __packed version for sizeof().
593 */
594#define __ec_align_size1 __packed
595
596/*
597 * Packed structure which must be under-aligned, because its offset inside a
598 * parent structure is not a 4-byte multiple.
599 */
600#define __ec_align_offset1 __packed
601#define __ec_align_offset2 __packed __aligned(2)
602
603/*
604 * Structures which are complicated enough that I'm skipping them on the first
605 * pass. They are effectively unchanged from their previous definitions.
606 *
607 * TODO(rspangler): Figure out what to do with these. It's likely necessary
608 * to work out the size and offset of each member and add explicit padding to
609 * maintain those.
610 */
611#define __ec_todo_packed __packed
612#define __ec_todo_unpacked
613
Caveh Jalali024ffe32023-01-30 14:35:19 -0800614#else /* !CONFIG_HOSTCMD_ALIGNED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700615
616/*
617 * Packed structures make no assumption about alignment, so they do inefficient
618 * byte-wise reads.
619 */
620#define __ec_align1 __packed
621#define __ec_align2 __packed
622#define __ec_align4 __packed
623#define __ec_align_size1 __packed
624#define __ec_align_offset1 __packed
625#define __ec_align_offset2 __packed
626#define __ec_todo_packed __packed
627#define __ec_todo_unpacked
628
Caveh Jalali024ffe32023-01-30 14:35:19 -0800629#endif /* !CONFIG_HOSTCMD_ALIGNED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700630
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800631/* LPC command status byte masks */
632/* EC has written a byte in the data register and host hasn't read it yet */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800633#define EC_LPC_STATUS_TO_HOST 0x01
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800634/* Host has written a command/data byte and the EC hasn't read it yet */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800635#define EC_LPC_STATUS_FROM_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800636/* EC is processing a command */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800637#define EC_LPC_STATUS_PROCESSING 0x04
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800638/* Last write to EC was a command, not data */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800639#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700640/* EC is in burst mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800641#define EC_LPC_STATUS_BURST_MODE 0x10
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800642/* SCI event is pending (requesting SCI query) */
643#define EC_LPC_STATUS_SCI_PENDING 0x20
644/* SMI event is pending (requesting SMI query) */
645#define EC_LPC_STATUS_SMI_PENDING 0x40
646/* (reserved) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800647#define EC_LPC_STATUS_RESERVED 0x80
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800648
649/*
650 * EC is busy. This covers both the EC processing a command, and the host has
651 * written a new command but the EC hasn't picked it up yet.
652 */
653#define EC_LPC_STATUS_BUSY_MASK \
654 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
655
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800656/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700657 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700658 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800659enum ec_status {
660 EC_RES_SUCCESS = 0,
661 EC_RES_INVALID_COMMAND = 1,
662 EC_RES_ERROR = 2,
663 EC_RES_INVALID_PARAM = 3,
664 EC_RES_ACCESS_DENIED = 4,
665 EC_RES_INVALID_RESPONSE = 5,
666 EC_RES_INVALID_VERSION = 6,
667 EC_RES_INVALID_CHECKSUM = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -0800668 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
669 EC_RES_UNAVAILABLE = 9, /* No response available */
670 EC_RES_TIMEOUT = 10, /* We got a timeout */
671 EC_RES_OVERFLOW = 11, /* Table / data overflow */
672 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
673 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
674 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
675 EC_RES_BUS_ERROR = 15, /* Communications bus error */
676 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
677 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
678 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
679 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
680 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700681
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800682 EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700683} __packed;
684BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800685
686/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600687 * Host event codes. ACPI query EC command uses code 0 to mean "no event
688 * pending". We explicitly specify each value in the enum listing so they won't
689 * change if we delete/insert an item or rearrange the list (it needs to be
690 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800691 */
692enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600693 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800694 EC_HOST_EVENT_LID_CLOSED = 1,
695 EC_HOST_EVENT_LID_OPEN = 2,
696 EC_HOST_EVENT_POWER_BUTTON = 3,
697 EC_HOST_EVENT_AC_CONNECTED = 4,
698 EC_HOST_EVENT_AC_DISCONNECTED = 5,
699 EC_HOST_EVENT_BATTERY_LOW = 6,
700 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
701 EC_HOST_EVENT_BATTERY = 8,
702 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700703 /* Event generated by a device attached to the EC */
704 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800705 EC_HOST_EVENT_THERMAL = 11,
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800706 /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */
707 EC_HOST_EVENT_GPU = 12,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800708 EC_HOST_EVENT_KEY_PRESSED = 13,
709 /*
710 * EC has finished initializing the host interface. The host can check
711 * for this event following sending a EC_CMD_REBOOT_EC command to
712 * determine when the EC is ready to accept subsequent commands.
713 */
714 EC_HOST_EVENT_INTERFACE_READY = 14,
715 /* Keyboard recovery combo has been pressed */
716 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
717
718 /* Shutdown due to thermal overload */
719 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
720 /* Shutdown due to battery level too low */
721 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
722
Duncan Laurie93e24442014-01-06 12:30:52 -0800723 /* Suggest that the AP throttle itself */
724 EC_HOST_EVENT_THROTTLE_START = 18,
725 /* Suggest that the AP resume normal speed */
726 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700727
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800728 /* Hang detect logic detected a hang and host event timeout expired */
729 EC_HOST_EVENT_HANG_DETECT = 20,
730 /* Hang detect logic detected a hang and warm rebooted the AP */
731 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700732
733 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700734 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800735
Duncan Lauried8401182014-09-29 08:32:19 -0700736 /* Battery Status flags have changed */
737 EC_HOST_EVENT_BATTERY_STATUS = 23,
738
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700739 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800740 EC_HOST_EVENT_PANIC = 24,
741
Furquan Shaikh066cc852015-06-20 15:53:03 -0700742 /* Keyboard fastboot combo has been pressed */
743 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
744
Gwendal Grignou880b4582016-06-20 08:49:25 -0700745 /* EC RTC event occurred */
746 EC_HOST_EVENT_RTC = 26,
747
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700748 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700749 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700750
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700751 /* EC desires to change state of host-controlled USB mux */
752 EC_HOST_EVENT_USB_MUX = 28,
753
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800754 /*
755 * The device has changed "modes". This can be one of the following:
756 *
757 * - TABLET/LAPTOP mode
758 * - detachable base attach/detach event
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800759 * - on body/off body transition event
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800760 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400761 EC_HOST_EVENT_MODE_CHANGE = 29,
762
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700763 /* Keyboard recovery combo with hardware reinitialization */
764 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
765
Jett Rinkba2edaf2020-01-14 11:49:06 -0700766 /* WoV */
767 EC_HOST_EVENT_WOV = 31,
768
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700769 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800770 * The high bit of the event mask is not used as a host event code. If
771 * it reads back as set, then the entire event mask should be
772 * considered invalid by the host. This can happen when reading the
773 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
774 * not initialized on the EC, or improperly configured on the host.
775 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800776 EC_HOST_EVENT_INVALID = 32,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800777};
778/* Host event mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800779#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800780
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800781/* clang-format off */
782#define HOST_EVENT_TEXT \
783 { \
784 [EC_HOST_EVENT_NONE] = "NONE", \
785 [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \
786 [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \
787 [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \
788 [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \
789 [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \
790 [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \
791 [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \
792 [EC_HOST_EVENT_BATTERY] = "BATTERY", \
793 [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \
794 [EC_HOST_EVENT_DEVICE] = "DEVICE", \
795 [EC_HOST_EVENT_THERMAL] = "THERMAL", \
796 [EC_HOST_EVENT_GPU] = "GPU", \
797 [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \
798 [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \
799 [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \
800 [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \
801 [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \
802 [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \
803 [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \
804 [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \
805 [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \
806 [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \
807 [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \
808 [EC_HOST_EVENT_PANIC] = "PANIC", \
809 [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \
810 [EC_HOST_EVENT_RTC] = "RTC", \
811 [EC_HOST_EVENT_MKBP] = "MKBP", \
812 [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \
813 [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \
814 [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \
815 "KEYBOARD_RECOVERY_HW_REINIT", \
816 [EC_HOST_EVENT_WOV] = "WOV", \
817 [EC_HOST_EVENT_INVALID] = "INVALID", \
818 }
819/* clang-format on */
820
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800821/**
822 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
823 * @flags: The host argument flags.
824 * @command_version: Command version.
825 * @data_size: The length of data.
826 * @checksum: Checksum; sum of command + flags + command_version + data_size +
827 * all params/response data bytes.
828 */
829struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800830 uint8_t flags;
831 uint8_t command_version;
832 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800833 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800834} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800835
836/* Flags for ec_lpc_host_args.flags */
837/*
838 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
839 * params.
840 *
841 * If EC gets a command and this flag is not set, this is an old-style command.
842 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
843 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700844 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800845 */
846#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
847/*
848 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
849 *
850 * If EC responds to a command and this flag is not set, this is an old-style
851 * response. Command version is 0 and response data from EC is at
852 * EC_LPC_ADDR_OLD_PARAM with unknown length.
853 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800854#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800855
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800856/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800857/*
858 * Byte codes returned by EC over SPI interface.
859 *
860 * These can be used by the AP to debug the EC interface, and to determine
861 * when the EC is not in a state where it will ever get around to responding
862 * to the AP.
863 *
864 * Example of sequence of bytes read from EC for a current good transfer:
865 * 1. - - AP asserts chip select (CS#)
866 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
867 * 3. - - EC starts handling CS# interrupt
868 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
869 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
870 * bytes looking for EC_SPI_FRAME_START
871 * 6. - - EC finishes processing and sets up response
872 * 7. EC_SPI_FRAME_START - AP reads frame byte
873 * 8. (response packet) - AP reads response packet
874 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
875 * 10 - - AP deasserts chip select
876 * 11 - - EC processes CS# interrupt and sets up DMA for
877 * next request
878 *
879 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
880 * the following byte values:
881 * EC_SPI_OLD_READY
882 * EC_SPI_RX_READY
883 * EC_SPI_RECEIVING
884 * EC_SPI_PROCESSING
885 *
886 * Then the EC found an error in the request, or was not ready for the request
887 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
888 * because the EC is unable to tell when the AP is done sending its request.
889 */
890
891/*
892 * Framing byte which precedes a response packet from the EC. After sending a
893 * request, the AP will clock in bytes until it sees the framing byte, then
894 * clock in the response packet.
895 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800896#define EC_SPI_FRAME_START 0xec
Duncan Laurie93e24442014-01-06 12:30:52 -0800897
898/*
899 * Padding bytes which are clocked out after the end of a response packet.
900 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800901#define EC_SPI_PAST_END 0xed
Duncan Laurie93e24442014-01-06 12:30:52 -0800902
903/*
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800904 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
Duncan Laurie93e24442014-01-06 12:30:52 -0800905 * that the AP will send a valid packet header (starting with
906 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800907 *
908 * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
909 * CS goes low. This macro has the Most Significant Bit set to zero,
910 * so SDO will not be driven high when CS goes low.
Duncan Laurie93e24442014-01-06 12:30:52 -0800911 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800912#define EC_SPI_RX_READY 0x78
Duncan Laurie93e24442014-01-06 12:30:52 -0800913
914/*
915 * EC has started receiving the request from the AP, but hasn't started
916 * processing it yet.
917 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800918#define EC_SPI_RECEIVING 0xf9
Duncan Laurie93e24442014-01-06 12:30:52 -0800919
920/* EC has received the entire request from the AP and is processing it. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800921#define EC_SPI_PROCESSING 0xfa
Duncan Laurie93e24442014-01-06 12:30:52 -0800922
923/*
924 * EC received bad data from the AP, such as a packet header with an invalid
925 * length. EC will ignore all data until chip select deasserts.
926 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800927#define EC_SPI_RX_BAD_DATA 0xfb
Duncan Laurie93e24442014-01-06 12:30:52 -0800928
929/*
930 * EC received data from the AP before it was ready. That is, the AP asserted
931 * chip select and started clocking data before the EC was ready to receive it.
932 * EC will ignore all data until chip select deasserts.
933 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800934#define EC_SPI_NOT_READY 0xfc
Duncan Laurie93e24442014-01-06 12:30:52 -0800935
936/*
937 * EC was ready to receive a request from the AP. EC has treated the byte sent
938 * by the AP as part of a request packet, or (for old-style ECs) is processing
939 * a fully received packet but is not ready to respond yet.
940 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800941#define EC_SPI_OLD_READY 0xfd
Duncan Laurie93e24442014-01-06 12:30:52 -0800942
943/*****************************************************************************/
944
945/*
946 * Protocol version 2 for I2C and SPI send a request this way:
947 *
948 * 0 EC_CMD_VERSION0 + (command version)
949 * 1 Command number
950 * 2 Length of params = N
951 * 3..N+2 Params, if any
952 * N+3 8-bit checksum of bytes 0..N+2
953 *
954 * The corresponding response is:
955 *
956 * 0 Result code (EC_RES_*)
957 * 1 Length of params = M
958 * 2..M+1 Params, if any
959 * M+2 8-bit checksum of bytes 0..M+1
960 */
961#define EC_PROTO2_REQUEST_HEADER_BYTES 3
962#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -0800963#define EC_PROTO2_REQUEST_OVERHEAD \
964 (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -0800965
966#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
967#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -0800968#define EC_PROTO2_RESPONSE_OVERHEAD \
969 (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -0800970
971/* Parameter length was limited by the LPC interface */
972#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
973
974/* Maximum request and response packet sizes for protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800975#define EC_PROTO2_MAX_REQUEST_SIZE \
976 (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
977#define EC_PROTO2_MAX_RESPONSE_SIZE \
978 (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
Duncan Laurie93e24442014-01-06 12:30:52 -0800979
980/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800981
982/*
983 * Value written to legacy command port / prefix byte to indicate protocol
984 * 3+ structs are being used. Usage is bus-dependent.
985 */
986#define EC_COMMAND_PROTOCOL_3 0xda
987
988#define EC_HOST_REQUEST_VERSION 3
989
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800990/**
991 * struct ec_host_request - Version 3 request from host.
992 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
993 * receives a header with a version it doesn't know how to
994 * parse.
995 * @checksum: Checksum of request and data; sum of all bytes including checksum
996 * should total to 0.
997 * @command: Command to send (EC_CMD_...)
998 * @command_version: Command version.
999 * @reserved: Unused byte in current protocol version; set to 0.
1000 * @data_len: Length of data which follows this header.
1001 */
1002struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001003 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001004 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001005 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001006 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001007 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001008 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001009} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001010
1011#define EC_HOST_RESPONSE_VERSION 3
1012
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001013/**
1014 * struct ec_host_response - Version 3 response from EC.
1015 * @struct_version: Struct version (=3).
1016 * @checksum: Checksum of response and data; sum of all bytes including
1017 * checksum should total to 0.
1018 * @result: EC's response to the command (separate from communication failure)
1019 * @data_len: Length of data which follows this header.
1020 * @reserved: Unused bytes in current protocol version; set to 0.
1021 */
1022struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001023 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001024 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001025 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001026 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001027 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001028} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001029
1030/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001031
1032/*
1033 * Host command protocol V4.
1034 *
1035 * Packets always start with a request or response header. They are followed
1036 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +01001037 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001038 * polynomial.
1039 *
1040 * Host algorithm when sending a request q:
1041 *
1042 * 101) tries_left=(some value, e.g. 3);
1043 * 102) q.seq_num++
1044 * 103) q.seq_dup=0
1045 * 104) Calculate q.header_crc.
1046 * 105) Send request q to EC.
1047 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
1048 *
1049 * 201) If r.struct_version != 4, go to 301.
1050 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
1051 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
1052 * 204) If r.seq_num != q.seq_num, go to 301.
1053 * 205) If r.seq_dup == q.seq_dup, return success.
1054 * 207) If r.seq_dup == 1, go to 301.
1055 * 208) Return error.
1056 *
1057 * 301) If --tries_left <= 0, return error.
1058 * 302) If q.seq_dup == 1, go to 105.
1059 * 303) q.seq_dup = 1
1060 * 304) Go to 104.
1061 *
1062 * EC algorithm when receiving a request q.
1063 * EC has response buffer r, error buffer e.
1064 *
1065 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
1066 * and go to 301
1067 * 102) If q.header_crc mismatches calculated CRC, set e.result =
1068 * EC_RES_INVALID_HEADER_CRC and go to 301
1069 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
1070 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
1071 * and go to 301.
1072 * 104) If q.seq_dup == 0, go to 201.
1073 * 105) If q.seq_num != r.seq_num, go to 201.
1074 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
1075 *
1076 * 201) Process request q into response r.
1077 * 202) r.seq_num = q.seq_num
1078 * 203) r.seq_dup = q.seq_dup
1079 * 204) Calculate r.header_crc
1080 * 205) If r.data_len > 0 and data is no longer available, set e.result =
1081 * EC_RES_DUP_UNAVAILABLE and go to 301.
1082 * 206) Send response r.
1083 *
1084 * 301) e.seq_num = q.seq_num
1085 * 302) e.seq_dup = q.seq_dup
1086 * 303) Calculate e.header_crc.
1087 * 304) Send error response e.
1088 */
1089
1090/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001091struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001092 /*
1093 * bits 0-3: struct_version: Structure version (=4)
1094 * bit 4: is_response: Is response (=0)
1095 * bits 5-6: seq_num: Sequence number
1096 * bit 7: seq_dup: Sequence duplicate flag
1097 */
1098 uint8_t fields0;
1099
1100 /*
1101 * bits 0-4: command_version: Command version
1102 * bits 5-6: Reserved (set 0, ignore on read)
1103 * bit 7: data_crc_present: Is data CRC present after data
1104 */
1105 uint8_t fields1;
1106
1107 /* Command code (EC_CMD_*) */
1108 uint16_t command;
1109
1110 /* Length of data which follows this header (not including data CRC) */
1111 uint16_t data_len;
1112
1113 /* Reserved (set 0, ignore on read) */
1114 uint8_t reserved;
1115
1116 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1117 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001118} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001119
1120/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001121struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001122 /*
1123 * bits 0-3: struct_version: Structure version (=4)
1124 * bit 4: is_response: Is response (=1)
1125 * bits 5-6: seq_num: Sequence number
1126 * bit 7: seq_dup: Sequence duplicate flag
1127 */
1128 uint8_t fields0;
1129
1130 /*
1131 * bits 0-6: Reserved (set 0, ignore on read)
1132 * bit 7: data_crc_present: Is data CRC present after data
1133 */
1134 uint8_t fields1;
1135
1136 /* Result code (EC_RES_*) */
1137 uint16_t result;
1138
1139 /* Length of data which follows this header (not including data CRC) */
1140 uint16_t data_len;
1141
1142 /* Reserved (set 0, ignore on read) */
1143 uint8_t reserved;
1144
1145 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1146 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001147} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001148
1149/* Fields in fields0 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001150#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1151#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1152#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1153#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1154#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001155
1156/* Fields in fields1 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001157#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1158#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001159
1160/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001161/*
1162 * Notes on commands:
1163 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001164 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001165 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001166 * specified, the command does not input or output data, respectively.
1167 * Parameter/response length is implicit in the structs. Some underlying
1168 * communication protocols (I2C, SPI) may add length or checksum headers, but
1169 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001170 *
1171 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1172 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001173 */
1174
1175/*****************************************************************************/
1176/* General / test commands */
1177
1178/*
1179 * Get protocol version, used to deal with non-backward compatible protocol
1180 * changes.
1181 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001182#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001183
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001184/**
1185 * struct ec_response_proto_version - Response to the proto version command.
1186 * @version: The protocol version.
1187 */
1188struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001189 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001190} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001191
1192/*
1193 * Hello. This is a simple command to test the EC is responsive to
1194 * commands.
1195 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001196#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001197
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001198/**
1199 * struct ec_params_hello - Parameters to the hello command.
1200 * @in_data: Pass anything here.
1201 */
1202struct ec_params_hello {
1203 uint32_t in_data;
1204} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001205
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001206/**
1207 * struct ec_response_hello - Response to the hello command.
1208 * @out_data: Output will be in_data + 0x01020304.
1209 */
1210struct ec_response_hello {
1211 uint32_t out_data;
1212} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001213
1214/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001215#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001216
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001217enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001218 EC_IMAGE_UNKNOWN = 0,
1219 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001220 EC_IMAGE_RW,
1221 EC_IMAGE_RW_A = EC_IMAGE_RW,
1222 EC_IMAGE_RO_B,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001223 EC_IMAGE_RW_B,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001224};
1225
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001226/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001227 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001228 * @version_string_ro: Null-terminated RO firmware version string.
1229 * @version_string_rw: Null-terminated RW firmware version string.
1230 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001231 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001232 */
1233struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001234 char version_string_ro[32];
1235 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001236 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001237 uint32_t current_image;
1238} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001239
Rob Barnes5ab14662021-09-17 10:24:45 -06001240/**
1241 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1242 *
1243 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1244 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1245 * and adds one additional field (cros_fwid_rw).
1246 *
1247 * @version_string_ro: Null-terminated RO firmware version string.
1248 * @version_string_rw: Null-terminated RW firmware version string.
1249 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1250 * @current_image: One of ec_image.
1251 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1252 */
1253struct ec_response_get_version_v1 {
1254 char version_string_ro[32];
1255 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001256 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
Rob Barnes5ab14662021-09-17 10:24:45 -06001257 uint32_t current_image;
Caveh Jalali024ffe32023-01-30 14:35:19 -08001258 char cros_fwid_rw[32]; /* Added in version 1 */
Rob Barnes5ab14662021-09-17 10:24:45 -06001259} __ec_align4;
1260
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001261/* Read test - DEPRECATED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001262#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001263
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001264/*
1265 * Get build information
1266 *
1267 * Response is null-terminated string.
1268 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001269#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001270
1271/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001272#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001273
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001274/**
1275 * struct ec_response_get_chip_info - Response to the get chip info command.
1276 * @vendor: Null-terminated string for chip vendor.
1277 * @name: Null-terminated string for chip name.
1278 * @revision: Null-terminated string for chip mask version.
1279 */
1280struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001281 char vendor[32];
1282 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001283 char revision[32];
1284} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001285
1286/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001287#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001288
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001289/**
1290 * struct ec_response_board_version - Response to the board version command.
1291 * @board_version: A monotonously incrementing number.
1292 */
1293struct ec_response_board_version {
1294 uint16_t board_version;
1295} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001296
1297/*
1298 * Read memory-mapped data.
1299 *
1300 * This is an alternate interface to memory-mapped data for bus protocols
1301 * which don't support direct-mapped memory - I2C, SPI, etc.
1302 *
1303 * Response is params.size bytes of data.
1304 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001305#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001306
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001307/**
1308 * struct ec_params_read_memmap - Parameters for the read memory map command.
1309 * @offset: Offset in memmap (EC_MEMMAP_*).
1310 * @size: Size to read in bytes.
1311 */
1312struct ec_params_read_memmap {
1313 uint8_t offset;
1314 uint8_t size;
1315} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001316
1317/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001318#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001319
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001320/**
1321 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1322 * @cmd: Command to check.
1323 */
1324struct ec_params_get_cmd_versions {
1325 uint8_t cmd;
1326} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001327
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001328/**
1329 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1330 * versions (v1)
1331 * @cmd: Command to check.
1332 */
1333struct ec_params_get_cmd_versions_v1 {
1334 uint16_t cmd;
1335} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001336
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001337/**
1338 * struct ec_response_get_cmd_version - Response to the get command versions.
1339 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1340 * a desired version.
1341 */
1342struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001343 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001344} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001345
Duncan Laurie433432b2013-06-03 10:38:22 -07001346/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001347 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001348 * on lpc since it has its own out-of-band busy indicator.
1349 *
1350 * lpc must read the status from the command register. Attempting this on
1351 * lpc will overwrite the args/parameter space and corrupt its data.
1352 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001353#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001354
1355/* Avoid using ec_status which is for return values */
1356enum ec_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001357 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001358};
1359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001360/**
1361 * struct ec_response_get_comms_status - Response to the get comms status
1362 * command.
1363 * @flags: Mask of enum ec_comms_status.
1364 */
1365struct ec_response_get_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001366 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001367} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001368
Duncan Laurie93e24442014-01-06 12:30:52 -08001369/* Fake a variety of responses, purely for testing purposes. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001370#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001371
1372/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001373struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001374 uint32_t ec_result;
1375 uint32_t ret_len;
1376 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001377} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001378
1379/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001380struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001381 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001382} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001383
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001384/* Get protocol information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001385#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001386
1387/* Flags for ec_response_get_protocol_info.flags */
1388/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001389#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001390
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001391/**
1392 * struct ec_response_get_protocol_info - Response to the get protocol info.
1393 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1394 * version n).
1395 * @max_request_packet_size: Maximum request packet size in bytes.
1396 * @max_response_packet_size: Maximum response packet size in bytes.
1397 * @flags: see EC_PROTOCOL_INFO_*
1398 */
1399struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001400 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001401 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001402 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001403 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001404 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001405} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001406
Duncan Laurie93e24442014-01-06 12:30:52 -08001407/*****************************************************************************/
1408/* Get/Set miscellaneous values */
1409
1410/* The upper byte of .flags tells what to do (nothing means "get") */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001411#define EC_GSV_SET 0x80000000
Duncan Laurie93e24442014-01-06 12:30:52 -08001412
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001413/*
1414 * The lower three bytes of .flags identifies the parameter, if that has
1415 * meaning for an individual command.
1416 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001417#define EC_GSV_PARAM_MASK 0x00ffffff
1418
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001419struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001420 uint32_t flags;
1421 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001422} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001423
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001424struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001425 uint32_t flags;
1426 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001427} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001428
Duncan Laurieeb316852015-12-01 18:51:18 -08001429/* More than one command can use these structs to get/set parameters. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001430#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001431
Duncan Laurieeb316852015-12-01 18:51:18 -08001432/*****************************************************************************/
1433/* List the features supported by the firmware */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001434#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001435
1436/* Supported features */
1437enum ec_feature_code {
1438 /*
1439 * This image contains a limited set of features. Another image
1440 * in RW partition may support more features.
1441 */
1442 EC_FEATURE_LIMITED = 0,
1443 /*
1444 * Commands for probing/reading/writing/erasing the flash in the
1445 * EC are present.
1446 */
1447 EC_FEATURE_FLASH = 1,
1448 /*
1449 * Can control the fan speed directly.
1450 */
1451 EC_FEATURE_PWM_FAN = 2,
1452 /*
1453 * Can control the intensity of the keyboard backlight.
1454 */
1455 EC_FEATURE_PWM_KEYB = 3,
1456 /*
1457 * Support Google lightbar, introduced on Pixel.
1458 */
1459 EC_FEATURE_LIGHTBAR = 4,
1460 /* Control of LEDs */
1461 EC_FEATURE_LED = 5,
1462 /* Exposes an interface to control gyro and sensors.
1463 * The host goes through the EC to access these sensors.
1464 * In addition, the EC may provide composite sensors, like lid angle.
1465 */
1466 EC_FEATURE_MOTION_SENSE = 6,
1467 /* The keyboard is controlled by the EC */
1468 EC_FEATURE_KEYB = 7,
1469 /* The AP can use part of the EC flash as persistent storage. */
1470 EC_FEATURE_PSTORE = 8,
1471 /* The EC monitors BIOS port 80h, and can return POST codes. */
1472 EC_FEATURE_PORT80 = 9,
1473 /*
1474 * Thermal management: include TMP specific commands.
1475 * Higher level than direct fan control.
1476 */
1477 EC_FEATURE_THERMAL = 10,
1478 /* Can switch the screen backlight on/off */
1479 EC_FEATURE_BKLIGHT_SWITCH = 11,
1480 /* Can switch the wifi module on/off */
1481 EC_FEATURE_WIFI_SWITCH = 12,
1482 /* Monitor host events, through for example SMI or SCI */
1483 EC_FEATURE_HOST_EVENTS = 13,
1484 /* The EC exposes GPIO commands to control/monitor connected devices. */
1485 EC_FEATURE_GPIO = 14,
1486 /* The EC can send i2c messages to downstream devices. */
1487 EC_FEATURE_I2C = 15,
1488 /* Command to control charger are included */
1489 EC_FEATURE_CHARGER = 16,
1490 /* Simple battery support. */
1491 EC_FEATURE_BATTERY = 17,
1492 /*
1493 * Support Smart battery protocol
1494 * (Common Smart Battery System Interface Specification)
1495 */
1496 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001497 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001498 EC_FEATURE_HANG_DETECT = 19,
1499 /* Report power information, for pit only */
1500 EC_FEATURE_PMU = 20,
1501 /* Another Cros EC device is present downstream of this one */
1502 EC_FEATURE_SUB_MCU = 21,
1503 /* Support USB Power delivery (PD) commands */
1504 EC_FEATURE_USB_PD = 22,
1505 /* Control USB multiplexer, for audio through USB port for instance. */
1506 EC_FEATURE_USB_MUX = 23,
1507 /* Motion Sensor code has an internal software FIFO */
1508 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1509 /* Support temporary secure vstore */
1510 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001511 /* EC decides on USB-C SS mux state, muxes configured by host */
1512 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1513 /* EC has RTC feature that can be controlled by host commands */
1514 EC_FEATURE_RTC = 27,
1515 /* The MCU exposes a Fingerprint sensor */
1516 EC_FEATURE_FINGERPRINT = 28,
1517 /* The MCU exposes a Touchpad */
1518 EC_FEATURE_TOUCHPAD = 29,
1519 /* The MCU has RWSIG task enabled */
1520 EC_FEATURE_RWSIG = 30,
1521 /* EC has device events support */
1522 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001523 /* EC supports the unified wake masks for LPC/eSPI systems */
1524 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001525 /* EC supports 64-bit host events */
1526 EC_FEATURE_HOST_EVENT64 = 33,
1527 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1528 EC_FEATURE_EXEC_IN_RAM = 34,
1529 /* EC supports CEC commands */
1530 EC_FEATURE_CEC = 35,
1531 /* EC supports tight sensor timestamping. */
1532 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001533 /*
1534 * EC supports tablet mode detection aligned to Chrome and allows
1535 * setting of threshold by host command using
1536 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1537 */
1538 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001539 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001540 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001541 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1542 * be sent to RO to be precise.
1543 */
1544 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001545 /* The MCU is a System Companion Processor (SCP). */
1546 EC_FEATURE_SCP = 39,
1547 /* The MCU is an Integrated Sensor Hub */
1548 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001549 /* New TCPMv2 TYPEC_ prefaced commands supported */
1550 EC_FEATURE_TYPEC_CMD = 41,
1551 /*
1552 * The EC will wait for direction from the AP to enter Type-C alternate
1553 * modes or USB4.
1554 */
1555 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1556 /*
1557 * The EC will wait for an acknowledge from the AP after setting the
1558 * mux.
1559 */
1560 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001561 /*
1562 * The EC supports entering and residing in S4.
1563 */
1564 EC_FEATURE_S4_RESIDENCY = 44,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001565 /*
1566 * The EC supports the AP directing mux sets for the board.
1567 */
1568 EC_FEATURE_TYPEC_AP_MUX_SET = 45,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001569 /*
1570 * The EC supports the AP composing VDMs for us to send.
1571 */
1572 EC_FEATURE_TYPEC_AP_VDM_SEND = 46,
Duncan Laurieeb316852015-12-01 18:51:18 -08001573};
1574
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001575#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1576#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1577
1578struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001579 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001580} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001581
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001582/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001583/* Get the board's SKU ID from EC */
1584#define EC_CMD_GET_SKU_ID 0x000E
1585
Kevin Chiue2bb0592017-09-12 09:13:41 +08001586/* Set SKU ID from AP */
1587#define EC_CMD_SET_SKU_ID 0x000F
1588
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001589struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001590 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001591} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001592
1593/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001594/* Flash commands */
1595
1596/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001597#define EC_CMD_FLASH_INFO 0x0010
1598#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001599
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001600/**
1601 * struct ec_response_flash_info - Response to the flash info command.
1602 * @flash_size: Usable flash size in bytes.
1603 * @write_block_size: Write block size. Write offset and size must be a
1604 * multiple of this.
1605 * @erase_block_size: Erase block size. Erase offset and size must be a
1606 * multiple of this.
1607 * @protect_block_size: Protection block size. Protection offset and size
1608 * must be a multiple of this.
1609 *
1610 * Version 0 returns these fields.
1611 */
1612struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001613 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001614 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001615 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001616 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001617} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001618
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001619/*
1620 * Flags for version 1+ flash info command
1621 * EC flash erases bits to 0 instead of 1.
1622 */
1623#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001625/*
1626 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001627 * be necessary on a chip where write/erase can be corrupted by other board
1628 * activity, or where the chip needs to enable some sort of programming voltage,
1629 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001630 * chip functionality.
1631 */
1632#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001633
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001634/**
1635 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1636 * @flash_size: Usable flash size in bytes.
1637 * @write_block_size: Write block size. Write offset and size must be a
1638 * multiple of this.
1639 * @erase_block_size: Erase block size. Erase offset and size must be a
1640 * multiple of this.
1641 * @protect_block_size: Protection block size. Protection offset and size
1642 * must be a multiple of this.
1643 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1644 * size is exactly this and offset is a multiple of this.
1645 * For example, an EC may have a write buffer which can do
1646 * half-page operations if data is aligned, and a slower
1647 * word-at-a-time write mode.
1648 * @flags: Flags; see EC_FLASH_INFO_*
1649 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001650 * Version 1 returns the same initial fields as version 0, with additional
1651 * fields following.
1652 *
1653 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001654 * if they did we'd define the version 0 structure as a sub-structure of this
1655 * one.
1656 *
1657 * Version 2 supports flash banks of different sizes:
1658 * The caller specified the number of banks it has preallocated
1659 * (num_banks_desc)
1660 * The EC returns the number of banks describing the flash memory.
1661 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001662 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001663struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001664 /* Version 0 fields; see above for description */
1665 uint32_t flash_size;
1666 uint32_t write_block_size;
1667 uint32_t erase_block_size;
1668 uint32_t protect_block_size;
1669
1670 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001671 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001672 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001673} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001674
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001675struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001676 /* Number of banks to describe */
1677 uint16_t num_banks_desc;
1678 /* Reserved; set 0; ignore on read */
1679 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001680} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001681
1682struct ec_flash_bank {
1683 /* Number of sector is in this bank. */
1684 uint16_t count;
1685 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1686 uint8_t size_exp;
1687 /* Minimal write size for the sectors in this bank */
1688 uint8_t write_size_exp;
1689 /* Erase size for the sectors in this bank */
1690 uint8_t erase_size_exp;
1691 /* Size for write protection, usually identical to erase size. */
1692 uint8_t protect_size_exp;
1693 /* Reserved; set 0; ignore on read */
1694 uint8_t reserved[2];
1695};
1696
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001697struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001698 /* Total flash in the EC. */
1699 uint32_t flash_size;
1700 /* Flags; see EC_FLASH_INFO_* */
1701 uint32_t flags;
1702 /* Maximum size to use to send data to write to the EC. */
1703 uint32_t write_ideal_size;
1704 /* Number of banks present in the EC. */
1705 uint16_t num_banks_total;
1706 /* Number of banks described in banks array. */
1707 uint16_t num_banks_desc;
1708 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001709} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001710
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001711/*
1712 * Read flash
1713 *
1714 * Response is params.size bytes of data.
1715 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001716#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001717
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001718/**
1719 * struct ec_params_flash_read - Parameters for the flash read command.
1720 * @offset: Byte offset to read.
1721 * @size: Size to read in bytes.
1722 */
1723struct ec_params_flash_read {
1724 uint32_t offset;
1725 uint32_t size;
1726} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001727
1728/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001729#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001730#define EC_VER_FLASH_WRITE 1
1731
1732/* Version 0 of the flash command supported only 64 bytes of data */
1733#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001734
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001735/**
1736 * struct ec_params_flash_write - Parameters for the flash write command.
1737 * @offset: Byte offset to write.
1738 * @size: Size to write in bytes.
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001739 * @data: Data to write.
1740 * @data.words32: uint32_t data to write.
1741 * @data.bytes: uint8_t data to write.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001742 */
1743struct ec_params_flash_write {
1744 uint32_t offset;
1745 uint32_t size;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001746 /* Followed by data to write. This union allows accessing an
1747 * underlying buffer as uint32s or uint8s for convenience.
1748 */
1749 union {
1750 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1751 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1752 } data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001753} __ec_align4;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001754BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001755
1756/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001757#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001758
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001759/**
1760 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1761 * @offset: Byte offset to erase.
1762 * @size: Size to erase in bytes.
1763 */
1764struct ec_params_flash_erase {
1765 uint32_t offset;
1766 uint32_t size;
1767} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001768
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001769/*
1770 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001771 * subcommands can returns:
1772 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1773 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1774 * EC_RES_ERROR : other errors.
1775 * EC_RES_BUSY : an existing erase operation is in progress.
1776 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1777 *
1778 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1779 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1780 * the proper result.
1781 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1782 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1783 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1784 * permitted while erasing. (For instance, STM32F4).
1785 */
1786enum ec_flash_erase_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001787 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1788 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1789 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001790};
1791
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001792/**
1793 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1794 * @cmd: One of ec_flash_erase_cmd.
1795 * @reserved: Pad byte; currently always contains 0.
1796 * @flag: No flags defined yet; set to 0.
1797 * @params: Same as v0 parameters.
1798 */
1799struct ec_params_flash_erase_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001800 uint8_t cmd;
1801 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001802 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001803 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001804} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001805
1806/*
1807 * Get/set flash protection.
1808 *
1809 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1810 * firmware write protect GPIO, not all flags will take effect immediately;
1811 * some flags require a subsequent hard reset to take effect. Check the
1812 * returned flags bits to see what actually happened.
1813 *
1814 * If mask=0, simply returns the current flags state.
1815 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001816#define EC_CMD_FLASH_PROTECT 0x0015
Caveh Jalali024ffe32023-01-30 14:35:19 -08001817#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001818
1819/* Flags for flash protection */
1820/* RO flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001821#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001822/*
1823 * RO flash code protected now. If this bit is set, at-boot status cannot
1824 * be changed.
1825 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001826#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001827/* Entire flash code protected now, until reboot. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001828#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001829/* Flash write protect GPIO is asserted now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001830#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001831/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001832#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001833/*
1834 * Error - flash protection is in inconsistent state. At least one bank of
1835 * flash which should be protected is not protected. Usually fixed by
1836 * re-requesting the desired flags, or by a hard reset if that fails.
1837 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001838#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001839/* Entire flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001840#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001841/* RW flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001842#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001843/* RW flash code protected now. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001844#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001845/* Rollback information flash region protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001846#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001847/* Rollback information flash region protected now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001848#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001849/* Error - Unknown error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001850#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001852/**
1853 * struct ec_params_flash_protect - Parameters for the flash protect command.
1854 * @mask: Bits in flags to apply.
1855 * @flags: New flags to apply.
1856 */
1857struct ec_params_flash_protect {
1858 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001859 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001860} __ec_align4;
1861
1862/**
1863 * struct ec_response_flash_protect - Response to the flash protect command.
1864 * @flags: Current value of flash protect flags.
1865 * @valid_flags: Flags which are valid on this platform. This allows the
1866 * caller to distinguish between flags which aren't set vs. flags
1867 * which can't be set on this platform.
1868 * @writable_flags: Flags which can be changed given the current protection
1869 * state.
1870 */
1871struct ec_response_flash_protect {
1872 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001873 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001874 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001875} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001876
1877/*
1878 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1879 * write protect. These commands may be reused with version > 0.
1880 */
1881
1882/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001883#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001884#define EC_VER_FLASH_REGION_INFO 1
1885
1886enum ec_flash_region {
1887 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001888 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001889 /*
1890 * Region which holds active RW image. 'Active' is different from
1891 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1892 * scheduled to run, active/non-active applies only to RW images (for
1893 * the same reason 'update' applies only to RW images. It's a state of
1894 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1895 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1896 * doesn't enter 'running' state but it's still active on a flash.
1897 */
1898 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001899 /*
1900 * Region which should be write-protected in the factory (a superset of
1901 * EC_FLASH_REGION_RO)
1902 */
1903 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001904 /* Region which holds updatable (non-active) RW image */
1905 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001906 /* Number of regions */
1907 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001908};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001909/*
1910 * 'RW' is vague if there are multiple RW images; we mean the active one,
1911 * so the old constant is deprecated.
1912 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001913#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001914
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001915/**
1916 * struct ec_params_flash_region_info - Parameters for the flash region info
1917 * command.
1918 * @region: Flash region; see EC_FLASH_REGION_*
1919 */
1920struct ec_params_flash_region_info {
1921 uint32_t region;
1922} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001923
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001924struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001925 uint32_t offset;
1926 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001927} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001928
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001929/* Get SPI flash information */
1930#define EC_CMD_FLASH_SPI_INFO 0x0018
1931
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001932struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001933 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1934 uint8_t jedec[3];
1935
1936 /* Pad byte; currently always contains 0 */
1937 uint8_t reserved0;
1938
1939 /* Manufacturer / device ID from command 0x90 */
1940 uint8_t mfr_dev_id[2];
1941
1942 /* Status registers from command 0x05 and 0x35 */
1943 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001944} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001945
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001946/* Select flash during flash operations */
1947#define EC_CMD_FLASH_SELECT 0x0019
1948
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001949/**
1950 * struct ec_params_flash_select - Parameters for the flash select command.
1951 * @select: 1 to select flash, 0 to deselect flash
1952 */
1953struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001954 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001955} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001956
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001957/**
1958 * Request random numbers to be generated and returned.
1959 * Can be used to test the random number generator is truly random.
1960 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1961 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1962 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001963#define EC_CMD_RAND_NUM 0x001A
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001964#define EC_VER_RAND_NUM 0
1965
1966struct ec_params_rand_num {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001967 uint16_t num_rand_bytes; /**< num random bytes to generate */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001968} __ec_align4;
1969
1970struct ec_response_rand_num {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001971 /**
1972 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
1973 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
1974 */
1975 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
1976} __ec_align1;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001977BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1978
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001979/**
1980 * Get information about the key used to sign the RW firmware.
1981 * For more details on the fields, see "struct vb21_packed_key".
1982 */
1983#define EC_CMD_RWSIG_INFO 0x001B
1984#define EC_VER_RWSIG_INFO 0
1985
1986#define VBOOT2_KEY_ID_BYTES 20
1987
1988#ifdef CHROMIUM_EC
1989/* Don't force external projects to depend on the vboot headers. */
1990#include "vb21_struct.h"
1991BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1992#endif
1993
1994struct ec_response_rwsig_info {
1995 /**
1996 * Signature algorithm used by the key
1997 * (enum vb2_signature_algorithm).
1998 */
1999 uint16_t sig_alg;
2000
2001 /**
2002 * Hash digest algorithm used with the key
2003 * (enum vb2_hash_algorithm).
2004 */
2005 uint16_t hash_alg;
2006
2007 /** Key version. */
2008 uint32_t key_version;
2009
2010 /** Key ID (struct vb2_id). */
2011 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2012
2013 uint8_t key_is_valid;
2014
2015 /** Alignment padding. */
2016 uint8_t reserved[3];
2017} __ec_align4;
2018
2019BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2020
2021/**
2022 * Get information about the system, such as reset flags, locked state, etc.
2023 */
2024#define EC_CMD_SYSINFO 0x001C
2025#define EC_VER_SYSINFO 0
2026
2027enum sysinfo_flags {
2028 SYSTEM_IS_LOCKED = BIT(0),
2029 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2030 SYSTEM_JUMP_ENABLED = BIT(2),
2031 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08002032 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2033 /*
2034 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2035 * set and cleared when the system shuts down (not when the host event
2036 * flag is cleared).
2037 */
2038 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002039};
2040
2041struct ec_response_sysinfo {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002042 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002043 uint32_t current_image; /**< enum ec_image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002044 uint32_t flags; /**< enum sysinfo_flags */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002045} __ec_align4;
2046
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002047/*****************************************************************************/
2048/* PWM commands */
2049
2050/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002051#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002053struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002054 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002055} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002056
2057/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002058#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002059
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002060/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002061struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002062 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002063} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002064
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002065/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002066struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002067 uint32_t rpm;
2068 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002069} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002071/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002072/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002073#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002074
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002075struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002076 uint8_t percent;
2077 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002078} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002079
2080/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002081/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002082#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002083
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002084struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002085 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002086} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002087
2088/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002089#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002090
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002091/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002092struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002093 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002094} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002095
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002096/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002097struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002098 uint32_t percent;
2099 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002100} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002101
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002102#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002103/* 16 bit duty cycle, 0xffff = 100% */
2104#define EC_PWM_MAX_DUTY 0xffff
2105
2106enum ec_pwm_type {
2107 /* All types, indexed by board-specific enum pwm_channel */
2108 EC_PWM_TYPE_GENERIC = 0,
2109 /* Keyboard backlight */
2110 EC_PWM_TYPE_KB_LIGHT,
2111 /* Display backlight */
2112 EC_PWM_TYPE_DISPLAY_LIGHT,
2113 EC_PWM_TYPE_COUNT,
2114};
2115
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002116struct ec_params_pwm_set_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002117 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2118 uint8_t pwm_type; /* ec_pwm_type */
2119 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002120} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002121
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002122#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002124struct ec_params_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002125 uint8_t pwm_type; /* ec_pwm_type */
2126 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002127} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002128
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002129struct ec_response_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002130 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002131} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002132
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002133/*****************************************************************************/
2134/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002135 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002136 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2137 * into a subcommand. We'll make separate structs for subcommands with
2138 * different input args, so that we know how much to expect.
2139 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002140#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002141
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002142struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002143 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002144} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002145
Duncan Laurie433432b2013-06-03 10:38:22 -07002146#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002147
2148/*
2149 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002150 * host command, but the alignment is the same regardless. Keep it that way.
2151 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002152struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002153 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002154 int32_t google_ramp_up;
2155 int32_t google_ramp_down;
2156 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002157 int32_t s0_tick_delay[2]; /* AC=0/1 */
2158 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie93e24442014-01-06 12:30:52 -08002159 int32_t s0s3_ramp_down;
2160 int32_t s3_sleep_for;
2161 int32_t s3_ramp_up;
2162 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002163
2164 /* Oscillation */
2165 uint8_t new_s0;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002166 uint8_t osc_min[2]; /* AC=0/1 */
2167 uint8_t osc_max[2]; /* AC=0/1 */
2168 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002169
2170 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002171 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2172 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2173 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002174
2175 /* Battery level thresholds */
2176 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2177
2178 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002179 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2180 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie433432b2013-06-03 10:38:22 -07002181
2182 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002183 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002184} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002185
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002186struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002187 /* Timing */
2188 int32_t google_ramp_up;
2189 int32_t google_ramp_down;
2190 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002191 int32_t s0_tick_delay[2]; /* AC=0/1 */
2192 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002193 int32_t s0s3_ramp_down;
2194 int32_t s3_sleep_for;
2195 int32_t s3_ramp_up;
2196 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002197 int32_t s5_ramp_up;
2198 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002199 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002200 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002201 int32_t tap_display_time;
2202
2203 /* Tap-for-battery params */
2204 uint8_t tap_pct_red;
2205 uint8_t tap_pct_green;
2206 uint8_t tap_seg_min_on;
2207 uint8_t tap_seg_max_on;
2208 uint8_t tap_seg_osc;
2209 uint8_t tap_idx[3];
2210
2211 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002212 uint8_t osc_min[2]; /* AC=0/1 */
2213 uint8_t osc_max[2]; /* AC=0/1 */
2214 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002215
2216 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002217 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2218 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2219 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002220
2221 /* Battery level thresholds */
2222 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2223
2224 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002225 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2226 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002227
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002228 /* s5: single color pulse on inhibited power-up */
2229 uint8_t s5_idx;
2230
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002231 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002232 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002233} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002234
Duncan Laurieeb316852015-12-01 18:51:18 -08002235/* Lightbar command params v2
2236 * crbug.com/467716
2237 *
2238 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2239 * logical groups to make it more manageable ( < 120 bytes).
2240 *
2241 * NOTE: Each of these groups must be less than 120 bytes.
2242 */
2243
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002244struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002245 /* Timing */
2246 int32_t google_ramp_up;
2247 int32_t google_ramp_down;
2248 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002249 int32_t s0_tick_delay[2]; /* AC=0/1 */
2250 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002251 int32_t s0s3_ramp_down;
2252 int32_t s3_sleep_for;
2253 int32_t s3_ramp_up;
2254 int32_t s3_ramp_down;
2255 int32_t s5_ramp_up;
2256 int32_t s5_ramp_down;
2257 int32_t tap_tick_delay;
2258 int32_t tap_gate_delay;
2259 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002260} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002261
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002262struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002263 /* Tap-for-battery params */
2264 uint8_t tap_pct_red;
2265 uint8_t tap_pct_green;
2266 uint8_t tap_seg_min_on;
2267 uint8_t tap_seg_max_on;
2268 uint8_t tap_seg_osc;
2269 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002270} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002272struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002273 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002274 uint8_t osc_min[2]; /* AC=0/1 */
2275 uint8_t osc_max[2]; /* AC=0/1 */
2276 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002277} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002278
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002279struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002280 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002281 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2282 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2283 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002284} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002285
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002286struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002287 /* Battery level thresholds */
2288 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002289} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002290
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002291struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002292 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002293 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2294 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurieeb316852015-12-01 18:51:18 -08002295
2296 /* s5: single color pulse on inhibited power-up */
2297 uint8_t s5_idx;
2298
2299 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002300 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002301} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002302
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002303/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002304#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002305struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002306 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002307 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002308} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002309
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002310struct ec_params_lightbar {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002311 uint8_t cmd; /* Command (see enum lightbar_command) */
Duncan Laurie433432b2013-06-03 10:38:22 -07002312 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002313 /*
2314 * The following commands have no args:
2315 *
2316 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2317 * version, get_brightness, get_demo, suspend, resume,
2318 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2319 * get_params_v2_bright, get_params_v2_thlds,
2320 * get_params_v2_colors
2321 *
2322 * Don't use an empty struct, because C++ hates that.
2323 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002324
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002325 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002326 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002327 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002328
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002329 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002330 uint8_t ctrl, reg, value;
2331 } reg;
2332
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002333 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002334 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002335 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002336
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002337 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002338 uint8_t led;
2339 } get_rgb;
2340
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002341 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002342 uint8_t enable;
2343 } manual_suspend_ctrl;
2344
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002345 struct lightbar_params_v0 set_params_v0;
2346 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002347
2348 struct lightbar_params_v2_timing set_v2par_timing;
2349 struct lightbar_params_v2_tap set_v2par_tap;
2350 struct lightbar_params_v2_oscillation set_v2par_osc;
2351 struct lightbar_params_v2_brightness set_v2par_bright;
2352 struct lightbar_params_v2_thresholds set_v2par_thlds;
2353 struct lightbar_params_v2_colors set_v2par_colors;
2354
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002355 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002356 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002357} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002358
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002359struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002360 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002361 struct __ec_todo_unpacked {
2362 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002363 uint8_t reg;
2364 uint8_t ic0;
2365 uint8_t ic1;
2366 } vals[23];
2367 } dump;
2368
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002369 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002370 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002371 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002372
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002373 struct lightbar_params_v0 get_params_v0;
2374 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002375
Duncan Laurieeb316852015-12-01 18:51:18 -08002376 struct lightbar_params_v2_timing get_params_v2_timing;
2377 struct lightbar_params_v2_tap get_params_v2_tap;
2378 struct lightbar_params_v2_oscillation get_params_v2_osc;
2379 struct lightbar_params_v2_brightness get_params_v2_bright;
2380 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2381 struct lightbar_params_v2_colors get_params_v2_colors;
2382
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002383 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002384 uint32_t num;
2385 uint32_t flags;
2386 } version;
2387
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002388 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002389 uint8_t red, green, blue;
2390 } get_rgb;
2391
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002392 /*
2393 * The following commands have no response:
2394 *
2395 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2396 * set_params_v0, set_params_v1, set_program,
2397 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2398 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2399 * set_v2par_thlds, set_v2par_colors
2400 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002401 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002402} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002403
2404/* Lightbar commands */
2405enum lightbar_command {
2406 LIGHTBAR_CMD_DUMP = 0,
2407 LIGHTBAR_CMD_OFF = 1,
2408 LIGHTBAR_CMD_ON = 2,
2409 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002410 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002411 LIGHTBAR_CMD_SEQ = 5,
2412 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002413 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002414 LIGHTBAR_CMD_GET_SEQ = 8,
2415 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002416 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2417 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002418 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002419 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2420 LIGHTBAR_CMD_GET_RGB = 14,
2421 LIGHTBAR_CMD_GET_DEMO = 15,
2422 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2423 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002424 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002425 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2426 LIGHTBAR_CMD_SUSPEND = 20,
2427 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002428 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2429 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2430 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2431 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2432 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2433 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2434 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2435 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2436 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2437 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2438 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2439 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002440 LIGHTBAR_NUM_CMDS,
Duncan Laurie433432b2013-06-03 10:38:22 -07002441};
2442
2443/*****************************************************************************/
2444/* LED control commands */
2445
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002446#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002447
Bill Richardsone221aad2013-06-12 10:50:41 -07002448enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002449 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002450 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002451 /*
2452 * LED to indicate system power state (on or in suspend).
2453 * May be on power button or on C-panel.
2454 */
2455 EC_LED_ID_POWER_LED,
2456 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002457 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002458 /* LED to indicate left side */
2459 EC_LED_ID_LEFT_LED,
2460 /* LED to indicate right side */
2461 EC_LED_ID_RIGHT_LED,
2462 /* LED to indicate recovery mode with HW_REINIT */
2463 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2464 /* LED to indicate sysrq debug mode. */
2465 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002466
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002467 EC_LED_ID_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002468};
Duncan Laurie433432b2013-06-03 10:38:22 -07002469
Bill Richardsone221aad2013-06-12 10:50:41 -07002470/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002471#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002472#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002473
2474enum ec_led_colors {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002475 EC_LED_COLOR_INVALID = -1,
Bill Richardsone221aad2013-06-12 10:50:41 -07002476 EC_LED_COLOR_RED = 0,
2477 EC_LED_COLOR_GREEN,
2478 EC_LED_COLOR_BLUE,
2479 EC_LED_COLOR_YELLOW,
2480 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002481 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002482
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002483 EC_LED_COLOR_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002484};
2485
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002486struct ec_params_led_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002487 uint8_t led_id; /* Which LED to control */
2488 uint8_t flags; /* Control flags */
Bill Richardsone221aad2013-06-12 10:50:41 -07002489
2490 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002491} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002492
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002493struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002494 /*
2495 * Available brightness value range.
2496 *
2497 * Range 0 means color channel not present.
2498 * Range 1 means on/off control.
2499 * Other values means the LED is control by PWM.
2500 */
2501 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002502} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002503
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002504/*****************************************************************************/
2505/* Verified boot commands */
2506
2507/*
2508 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2509 * reused for other purposes with version > 0.
2510 */
2511
2512/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002513#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002514
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002515struct ec_params_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002516 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2517 uint8_t hash_type; /* enum ec_vboot_hash_type */
2518 uint8_t nonce_size; /* Nonce size; may be 0 */
2519 uint8_t reserved0; /* Reserved; set 0 */
2520 uint32_t offset; /* Offset in flash to hash */
2521 uint32_t size; /* Number of bytes to hash */
2522 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002523} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002524
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002525struct ec_response_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002526 uint8_t status; /* enum ec_vboot_hash_status */
2527 uint8_t hash_type; /* enum ec_vboot_hash_type */
2528 uint8_t digest_size; /* Size of hash digest in bytes */
2529 uint8_t reserved0; /* Ignore; will be 0 */
2530 uint32_t offset; /* Offset in flash which was hashed */
2531 uint32_t size; /* Number of bytes hashed */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002532 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002533} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002534
2535enum ec_vboot_hash_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002536 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2537 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2538 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2539 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002540};
2541
2542enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002543 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002544};
2545
2546enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002547 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2548 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2549 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002550};
2551
Duncan Laurie433432b2013-06-03 10:38:22 -07002552/*
2553 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2554 * If one of these is specified, the EC will automatically update offset and
2555 * size to the correct values for the specified image (RO or RW).
2556 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002557#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2558#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2559#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002560
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002561/*
2562 * 'RW' is vague if there are multiple RW images; we mean the active one,
2563 * so the old constant is deprecated.
2564 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002565#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002566
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002567/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002568/*
2569 * Motion sense commands. We'll make separate structs for sub-commands with
2570 * different input args, so that we know how much to expect.
2571 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002572#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002573
2574/* Motion sense commands */
2575enum motionsense_command {
2576 /*
2577 * Dump command returns all motion sensor data including motion sense
2578 * module flags and individual sensor flags.
2579 */
2580 MOTIONSENSE_CMD_DUMP = 0,
2581
2582 /*
2583 * Info command returns data describing the details of a given sensor,
2584 * including enum motionsensor_type, enum motionsensor_location, and
2585 * enum motionsensor_chip.
2586 */
2587 MOTIONSENSE_CMD_INFO = 1,
2588
2589 /*
2590 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002591 * in milliseconds.
2592 * It is per sensor, the EC run sample task at the minimum of all
2593 * sensors EC_RATE.
2594 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2595 * to collect all the sensor samples.
2596 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2597 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002598 */
2599 MOTIONSENSE_CMD_EC_RATE = 2,
2600
2601 /*
2602 * Sensor ODR command is a setter/getter command for the output data
2603 * rate of a specific motion sensor in millihertz.
2604 */
2605 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2606
2607 /*
2608 * Sensor range command is a setter/getter command for the range of
2609 * a specified motion sensor in +/-G's or +/- deg/s.
2610 */
2611 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2612
2613 /*
2614 * Setter/getter command for the keyboard wake angle. When the lid
2615 * angle is greater than this value, keyboard wake is disabled in S3,
2616 * and when the lid angle goes less than this value, keyboard wake is
2617 * enabled. Note, the lid angle measurement is an approximate,
2618 * un-calibrated value, hence the wake angle isn't exact.
2619 */
2620 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2621
Duncan Laurieeb316852015-12-01 18:51:18 -08002622 /*
2623 * Returns a single sensor data.
2624 */
2625 MOTIONSENSE_CMD_DATA = 6,
2626
2627 /*
2628 * Return sensor fifo info.
2629 */
2630 MOTIONSENSE_CMD_FIFO_INFO = 7,
2631
2632 /*
2633 * Insert a flush element in the fifo and return sensor fifo info.
2634 * The host can use that element to synchronize its operation.
2635 */
2636 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2637
2638 /*
2639 * Return a portion of the fifo.
2640 */
2641 MOTIONSENSE_CMD_FIFO_READ = 9,
2642
2643 /*
2644 * Perform low level calibration.
2645 * On sensors that support it, ask to do offset calibration.
2646 */
2647 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2648
2649 /*
2650 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002651 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002652 * The offsets can be calculated by the host, or via
2653 * PERFORM_CALIB command.
2654 */
2655 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2656
2657 /*
2658 * List available activities for a MOTION sensor.
2659 * Indicates if they are enabled or disabled.
2660 */
2661 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2662
2663 /*
2664 * Activity management
2665 * Enable/Disable activity recognition.
2666 */
2667 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2668
2669 /*
2670 * Lid Angle
2671 */
2672 MOTIONSENSE_CMD_LID_ANGLE = 14,
2673
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002674 /*
2675 * Allow the FIFO to trigger interrupt via MKBP events.
2676 * By default the FIFO does not send interrupt to process the FIFO
2677 * until the AP is ready or it is coming from a wakeup sensor.
2678 */
2679 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2680
2681 /*
2682 * Spoof the readings of the sensors. The spoofed readings can be set
2683 * to arbitrary values, or will lock to the last read actual values.
2684 */
2685 MOTIONSENSE_CMD_SPOOF = 16,
2686
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002687 /* Set lid angle for tablet mode detection. */
2688 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2689
2690 /*
2691 * Sensor Scale command is a setter/getter command for the calibration
2692 * scale.
2693 */
2694 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2695
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002696 /*
2697 * Read the current online calibration values (if available).
2698 */
2699 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2700
Yidi Lin42f79592020-09-21 18:04:10 +08002701 /*
2702 * Activity management
2703 * Retrieve current status of given activity.
2704 */
2705 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2706
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002707 /* Number of motionsense sub-commands. */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002708 MOTIONSENSE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002709};
2710
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002711/* List of motion sensor types. */
2712enum motionsensor_type {
2713 MOTIONSENSE_TYPE_ACCEL = 0,
2714 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002715 MOTIONSENSE_TYPE_MAG = 2,
2716 MOTIONSENSE_TYPE_PROX = 3,
2717 MOTIONSENSE_TYPE_LIGHT = 4,
2718 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002719 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002720 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002721 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002722 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002723};
2724
2725/* List of motion sensor locations. */
2726enum motionsensor_location {
2727 MOTIONSENSE_LOC_BASE = 0,
2728 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002729 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002730 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002731};
2732
2733/* List of motion sensor chips. */
2734enum motionsensor_chip {
2735 MOTIONSENSE_CHIP_KXCJ9 = 0,
2736 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002737 MOTIONSENSE_CHIP_BMI160 = 2,
2738 MOTIONSENSE_CHIP_SI1141 = 3,
2739 MOTIONSENSE_CHIP_SI1142 = 4,
2740 MOTIONSENSE_CHIP_SI1143 = 5,
2741 MOTIONSENSE_CHIP_KX022 = 6,
2742 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002743 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002744 MOTIONSENSE_CHIP_BMP280 = 9,
2745 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002746 MOTIONSENSE_CHIP_BH1730 = 11,
2747 MOTIONSENSE_CHIP_GPIO = 12,
2748 MOTIONSENSE_CHIP_LIS2DH = 13,
2749 MOTIONSENSE_CHIP_LSM6DSM = 14,
2750 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002751 MOTIONSENSE_CHIP_LIS2MDL = 16,
2752 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2753 MOTIONSENSE_CHIP_LSM6DSO = 18,
2754 MOTIONSENSE_CHIP_LNG2DM = 19,
2755 MOTIONSENSE_CHIP_TCS3400 = 20,
2756 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2757 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002758 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002759 MOTIONSENSE_CHIP_BMI260 = 24,
2760 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002761 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002762 MOTIONSENSE_CHIP_BMA422 = 27,
2763 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002764 MOTIONSENSE_CHIP_BMI220 = 29,
2765 MOTIONSENSE_CHIP_CM32183 = 30,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002766 MOTIONSENSE_CHIP_MAX,
2767};
2768
2769/* List of orientation positions */
2770enum motionsensor_orientation {
2771 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2772 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2773 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2774 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2775 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002776};
2777
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002778struct ec_response_activity_data {
2779 uint8_t activity; /* motionsensor_activity */
2780 uint8_t state;
2781} __ec_todo_packed;
2782
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002783struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002784 /* Flags for each sensor. */
2785 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002786 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002787 uint8_t sensor_num;
2788 /* Each sensor is up to 3-axis. */
2789 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002790 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002791 /* for sensors using unsigned data */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002792 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002793 struct __ec_todo_packed {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002794 uint16_t reserved;
2795 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002796 };
2797 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002798 struct ec_response_activity_data activity_data;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002799 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002800 };
2801 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002802} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002803
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002804/* Response to AP reporting calibration data for a given sensor. */
2805struct ec_response_online_calibration_data {
2806 /** The calibration values. */
2807 int16_t data[3];
2808};
2809
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002810/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002811struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002812 /* Size of the fifo */
2813 uint16_t size;
2814 /* Amount of space used in the fifo */
2815 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002816 /* Timestamp recorded in us.
2817 * aka accurate timestamp when host event was triggered.
2818 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002819 uint32_t timestamp;
2820 /* Total amount of vector lost */
2821 uint16_t total_lost;
2822 /* Lost events since the last fifo_info, per sensors */
2823 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002824} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002825
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002826struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002827 uint32_t number_data;
2828 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002829} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002830
2831/* List supported activity recognition */
2832enum motionsensor_activity {
2833 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2834 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2835 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002836 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002837 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002838};
2839
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002840struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002841 uint8_t sensor_num;
2842 uint8_t activity; /* one of enum motionsensor_activity */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002843 uint8_t enable; /* 1: enable, 0: disable */
Duncan Laurieeb316852015-12-01 18:51:18 -08002844 uint8_t reserved;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002845 uint16_t parameters[4]; /* activity dependent parameters */
2846} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002847
2848/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002849#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002850
2851/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002852#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002853
2854/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002855 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002856 * data contains time stamp
2857 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002858#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2859#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2860#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2861#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2862#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002863
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002864#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2865
Duncan Laurieeb316852015-12-01 18:51:18 -08002866/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002867 * Send this value for the data element to only perform a read. If you
2868 * send any other value, the EC will interpret it as data to set and will
2869 * return the actual value set.
2870 */
2871#define EC_MOTION_SENSE_NO_VALUE -1
2872
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002873#define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
Duncan Laurieeb316852015-12-01 18:51:18 -08002874
2875/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2876/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002877#define MOTION_SENSE_SET_OFFSET BIT(0)
2878
2879/* Default Scale value, factor 1. */
2880#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002881
2882#define LID_ANGLE_UNRELIABLE 500
2883
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884enum motionsense_spoof_mode {
2885 /* Disable spoof mode. */
2886 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2887
2888 /* Enable spoof mode, but use provided component values. */
2889 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2890
2891 /* Enable spoof mode, but use the current sensor values. */
2892 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2893
2894 /* Query the current spoof mode status for the sensor. */
2895 MOTIONSENSE_SPOOF_MODE_QUERY,
2896};
2897
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002898struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002899 uint8_t cmd;
2900 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002901 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002902 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002903 /*
2904 * Maximal number of sensor the host is expecting.
2905 * 0 means the host is only interested in the number
2906 * of sensors controlled by the EC.
2907 */
2908 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002909 } dump;
2910
2911 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002912 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002913 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002914 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002915 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002916 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08002917 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002918 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002919 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002920
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002921 /*
2922 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2923 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002924 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002925 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002926 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002927
2928 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002929 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2930 * Allow entering/exiting the calibration mode.
2931 */
2932 struct __ec_todo_unpacked {
2933 uint8_t sensor_num;
2934 uint8_t enable;
2935 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002936
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002937 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002938 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2939 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002940 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002941 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002942 uint8_t sensor_num;
2943
2944 /* Rounding flag, true for round-up, false for down. */
2945 uint8_t roundup;
2946
2947 uint16_t reserved;
2948
2949 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2950 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002951 } ec_rate, sensor_odr, sensor_range;
2952
2953 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002954 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002955 uint8_t sensor_num;
2956
2957 /*
2958 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2959 * the calibration information in the EC.
2960 * If unset, just retrieve calibration information.
2961 */
2962 uint16_t flags;
2963
2964 /*
2965 * Temperature at calibration, in units of 0.01 C
2966 * 0x8000: invalid / unknown.
2967 * 0x0: 0C
2968 * 0x7fff: +327.67C
2969 */
2970 int16_t temp;
2971
2972 /*
2973 * Offset for calibration.
2974 * Unit:
2975 * Accelerometer: 1/1024 g
2976 * Gyro: 1/1024 deg/s
2977 * Compass: 1/16 uT
2978 */
2979 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002980 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002981
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002982 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2983 struct __ec_todo_packed {
2984 uint8_t sensor_num;
2985
2986 /*
2987 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2988 * the calibration information in the EC.
2989 * If unset, just retrieve calibration information.
2990 */
2991 uint16_t flags;
2992
2993 /*
2994 * Temperature at calibration, in units of 0.01 C
2995 * 0x8000: invalid / unknown.
2996 * 0x0: 0C
2997 * 0x7fff: +327.67C
2998 */
2999 int16_t temp;
3000
3001 /*
3002 * Scale for calibration:
3003 * By default scale is 1, it is encoded on 16bits:
3004 * 1 = BIT(15)
3005 * ~2 = 0xFFFF
3006 * ~0 = 0.
3007 */
3008 uint16_t scale[3];
3009 } sensor_scale;
3010
Duncan Laurieeb316852015-12-01 18:51:18 -08003011 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003012 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08003013
3014 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003015 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003016 /*
3017 * Number of expected vector to return.
3018 * EC may return less or 0 if none available.
3019 */
3020 uint32_t max_data_vector;
3021 } fifo_read;
3022
Yidi Lin42f79592020-09-21 18:04:10 +08003023 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08003024 struct ec_motion_sense_activity set_activity;
3025
3026 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003027 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003028
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003029 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3030 struct __ec_todo_unpacked {
3031 /*
3032 * 1: enable, 0 disable fifo,
3033 * EC_MOTION_SENSE_NO_VALUE return value.
3034 */
3035 int8_t enable;
3036 } fifo_int_enable;
3037
3038 /* Used for MOTIONSENSE_CMD_SPOOF */
3039 struct __ec_todo_packed {
3040 uint8_t sensor_id;
3041
3042 /* See enum motionsense_spoof_mode. */
3043 uint8_t spoof_enable;
3044
3045 /* Ignored, used for alignment. */
3046 uint8_t reserved;
3047
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003048 union {
3049 /* Individual component values to spoof. */
3050 int16_t components[3];
3051
3052 /* Used when spoofing an activity */
3053 struct {
3054 /* enum motionsensor_activity */
3055 uint8_t activity_num;
3056
3057 /* spoof activity state */
3058 uint8_t activity_state;
3059 };
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003060 } __ec_todo_packed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003061 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003062
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003063 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3064 struct __ec_todo_unpacked {
3065 /*
3066 * Lid angle threshold for switching between tablet and
3067 * clamshell mode.
3068 */
3069 int16_t lid_angle;
3070
3071 /*
3072 * Hysteresis degree to prevent fluctuations between
3073 * clamshell and tablet mode if lid angle keeps
3074 * changing around the threshold. Lid motion driver will
3075 * use lid_angle + hys_degree to trigger tablet mode and
3076 * lid_angle - hys_degree to trigger clamshell mode.
3077 */
3078 int16_t hys_degree;
3079 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003080
3081 /*
3082 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3083 * Allow reading a single sensor's online calibration value.
3084 */
3085 struct __ec_todo_unpacked {
3086 uint8_t sensor_num;
3087 } online_calib_read;
3088
Yidi Lin42f79592020-09-21 18:04:10 +08003089 /*
3090 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3091 */
3092 struct __ec_todo_unpacked {
3093 uint8_t sensor_num;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003094 uint8_t activity; /* enum motionsensor_activity */
Yidi Lin42f79592020-09-21 18:04:10 +08003095 } get_activity;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003096 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003097} __ec_todo_packed;
3098
Jett Rinkba2edaf2020-01-14 11:49:06 -07003099enum motion_sense_cmd_info_flags {
3100 /* The sensor supports online calibration */
3101 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3102};
3103
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003104struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003105 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003106 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003107 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003108 /* Flags representing the motion sensor module. */
3109 uint8_t module_flags;
3110
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003111 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003112 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003113
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003114 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003115 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003116 * for holding all the data.
3117 */
3118 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003119 } dump;
3120
3121 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003122 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003123 /* Should be element of enum motionsensor_type. */
3124 uint8_t type;
3125
3126 /* Should be element of enum motionsensor_location. */
3127 uint8_t location;
3128
3129 /* Should be element of enum motionsensor_chip. */
3130 uint8_t chip;
3131 } info;
3132
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003133 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3134 struct __ec_todo_unpacked {
3135 /* Should be element of enum motionsensor_type. */
3136 uint8_t type;
3137
3138 /* Should be element of enum motionsensor_location. */
3139 uint8_t location;
3140
3141 /* Should be element of enum motionsensor_chip. */
3142 uint8_t chip;
3143
3144 /* Minimum sensor sampling frequency */
3145 uint32_t min_frequency;
3146
3147 /* Maximum sensor sampling frequency */
3148 uint32_t max_frequency;
3149
3150 /* Max number of sensor events that could be in fifo */
3151 uint32_t fifo_max_event_count;
3152 } info_3;
3153
Jett Rinkba2edaf2020-01-14 11:49:06 -07003154 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3155 struct __ec_align4 {
3156 /* Should be element of enum motionsensor_type. */
3157 uint8_t type;
3158
3159 /* Should be element of enum motionsensor_location. */
3160 uint8_t location;
3161
3162 /* Should be element of enum motionsensor_chip. */
3163 uint8_t chip;
3164
3165 /* Minimum sensor sampling frequency */
3166 uint32_t min_frequency;
3167
3168 /* Maximum sensor sampling frequency */
3169 uint32_t max_frequency;
3170
3171 /* Max number of sensor events that could be in fifo */
3172 uint32_t fifo_max_event_count;
3173
3174 /*
3175 * Should be elements of
3176 * enum motion_sense_cmd_info_flags
3177 */
3178 uint32_t flags;
3179 } info_4;
3180
Duncan Laurieeb316852015-12-01 18:51:18 -08003181 /* Used for MOTIONSENSE_CMD_DATA */
3182 struct ec_response_motion_sensor_data data;
3183
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003184 /*
3185 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003186 * MOTIONSENSE_CMD_SENSOR_RANGE,
3187 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3188 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3189 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003190 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003191 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003192 /* Current value of the parameter queried. */
3193 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003194 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Caveh Jalali024ffe32023-01-30 14:35:19 -08003195 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003196
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003197 /*
3198 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3199 * PERFORM_CALIB.
3200 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003201 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003202 int16_t temp;
3203 int16_t offset[3];
3204 } sensor_offset, perform_calib;
3205
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003206 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003207 struct __ec_todo_unpacked {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003208 int16_t temp;
3209 uint16_t scale[3];
3210 } sensor_scale;
3211
Duncan Laurieeb316852015-12-01 18:51:18 -08003212 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3213
3214 struct ec_response_motion_sense_fifo_data fifo_read;
3215
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003216 struct ec_response_online_calibration_data online_calib_read;
3217
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003218 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003219 uint16_t reserved;
3220 uint32_t enabled;
3221 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003222 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003223
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003224 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003225
Duncan Laurieeb316852015-12-01 18:51:18 -08003226 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003227 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003228 /*
3229 * Angle between 0 and 360 degree if available,
3230 * LID_ANGLE_UNRELIABLE otherwise.
3231 */
3232 uint16_t value;
3233 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003234
3235 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3236 struct __ec_todo_unpacked {
3237 /*
3238 * Lid angle threshold for switching between tablet and
3239 * clamshell mode.
3240 */
3241 uint16_t lid_angle;
3242
3243 /* Hysteresis degree. */
3244 uint16_t hys_degree;
3245 } tablet_mode_threshold;
3246
Yidi Lin42f79592020-09-21 18:04:10 +08003247 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3248 struct __ec_todo_unpacked {
3249 uint8_t state;
3250 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003251 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003252} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003253
3254/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003255/* Force lid open command */
3256
3257/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003258#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003259
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003260struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003261 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003262} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003263
3264/*****************************************************************************/
3265/* Configure the behavior of the power button */
3266#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3267
3268enum ec_config_power_button_flags {
3269 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003270 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003271};
3272
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003273struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003274 /* See enum ec_config_power_button_flags */
3275 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003276} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003277
3278/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003279/* USB charging control commands */
3280
3281/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003282#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003283
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003284enum usb_charge_mode {
3285 /* Disable USB port. */
3286 USB_CHARGE_MODE_DISABLED,
3287 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3288 USB_CHARGE_MODE_SDP2,
3289 /* Set USB port to Charging Downstream Port, BC 1.2. */
3290 USB_CHARGE_MODE_CDP,
3291 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3292 USB_CHARGE_MODE_DCP_SHORT,
3293 /* Enable USB port (for dumb ports). */
3294 USB_CHARGE_MODE_ENABLED,
3295 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3296 USB_CHARGE_MODE_DEFAULT,
3297
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003298 USB_CHARGE_MODE_COUNT,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003299};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003301enum usb_suspend_charge {
3302 /* Enable charging in suspend */
3303 USB_ALLOW_SUSPEND_CHARGE,
3304 /* Disable charging in suspend */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003305 USB_DISALLOW_SUSPEND_CHARGE,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003306};
3307
3308struct ec_params_usb_charge_set_mode {
3309 uint8_t usb_port_id;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003310 uint8_t mode : 7; /* enum usb_charge_mode */
3311 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003312} __ec_align1;
3313
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003314/*****************************************************************************/
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003315/* Tablet mode commands */
3316
3317/* Set tablet mode */
3318#define EC_CMD_SET_TABLET_MODE 0x0031
3319
3320enum tablet_mode_override {
3321 TABLET_MODE_DEFAULT,
3322 TABLET_MODE_FORCE_TABLET,
3323 TABLET_MODE_FORCE_CLAMSHELL,
3324};
3325
3326struct ec_params_set_tablet_mode {
3327 uint8_t tablet_mode; /* enum tablet_mode_override */
3328} __ec_align1;
3329
3330/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003331/* Persistent storage for host */
3332
3333/* Maximum bytes that can be read/written in a single command */
3334#define EC_PSTORE_SIZE_MAX 64
3335
3336/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003337#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003338
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003339struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003340 /* Persistent storage size, in bytes */
3341 uint32_t pstore_size;
3342 /* Access size; read/write offset and size must be a multiple of this */
3343 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003344} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003345
3346/*
3347 * Read persistent storage
3348 *
3349 * Response is params.size bytes of data.
3350 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003351#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003352
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003353struct ec_params_pstore_read {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003354 uint32_t offset; /* Byte offset to read */
3355 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003356} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003357
3358/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003359#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003360
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003361struct ec_params_pstore_write {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003362 uint32_t offset; /* Byte offset to write */
3363 uint32_t size; /* Size to write in bytes */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003364 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003365} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003366
3367/*****************************************************************************/
3368/* Real-time clock */
3369
3370/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003371struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003372 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003373} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003374
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003375struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003376 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003377} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003378
3379/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003380#define EC_CMD_RTC_GET_VALUE 0x0044
3381#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003382
3383/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003384#define EC_CMD_RTC_SET_VALUE 0x0046
3385#define EC_CMD_RTC_SET_ALARM 0x0047
3386
3387/* Pass as time param to SET_ALARM to clear the current alarm */
3388#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003389
3390/*****************************************************************************/
3391/* Port80 log access */
3392
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003393/* Maximum entries that can be read/written in a single command */
3394#define EC_PORT80_SIZE_MAX 32
3395
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003396/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003397#define EC_CMD_PORT80_LAST_BOOT 0x0048
3398#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003399
3400enum ec_port80_subcmd {
3401 EC_PORT80_GET_INFO = 0,
3402 EC_PORT80_READ_BUFFER,
3403};
3404
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003405struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003406 uint16_t subcmd;
3407 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003408 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003409 uint32_t offset;
3410 uint32_t num_entries;
3411 } read_buffer;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003412 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003413} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003414
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003415struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003416 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003417 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003418 uint32_t writes;
3419 uint32_t history_size;
3420 uint32_t last_boot;
3421 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003422 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003423 uint16_t codes[EC_PORT80_SIZE_MAX];
3424 } data;
3425 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003426} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003427
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003428struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003429 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003430} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003431
3432/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003433/* Temporary secure storage for host verified boot use */
3434
3435/* Number of bytes in a vstore slot */
3436#define EC_VSTORE_SLOT_SIZE 64
3437
3438/* Maximum number of vstore slots */
3439#define EC_VSTORE_SLOT_MAX 32
3440
3441/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003442#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003443struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003444 /* Indicates which slots are locked */
3445 uint32_t slot_locked;
3446 /* Total number of slots available */
3447 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003448} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003449
3450/*
3451 * Read temporary secure storage
3452 *
3453 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3454 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003455#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003456
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003457struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003458 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003459} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003460
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003461struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003462 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003463} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003464
3465/*
3466 * Write temporary secure storage and lock it.
3467 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003468#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003469
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003470struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003471 uint8_t slot; /* Slot to write to */
3472 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003473} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003474
3475/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003476/* Thermal engine commands. Note that there are two implementations. We'll
3477 * reuse the command number, but the data and behavior is incompatible.
3478 * Version 0 is what originally shipped on Link.
3479 * Version 1 separates the CPU thermal limits from the fan control.
3480 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003481
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003482#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3483#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003484
Duncan Laurie93e24442014-01-06 12:30:52 -08003485/* The version 0 structs are opaque. You have to know what they are for
3486 * the get/set commands to make any sense.
3487 */
3488
3489/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003490struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003491 uint8_t sensor_type;
3492 uint8_t threshold_id;
3493 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003494} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003495
Duncan Laurie93e24442014-01-06 12:30:52 -08003496/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003497struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003498 uint8_t sensor_type;
3499 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003500} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003502struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003503 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003504} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003505
Duncan Laurie93e24442014-01-06 12:30:52 -08003506/* The version 1 structs are visible. */
3507enum ec_temp_thresholds {
3508 EC_TEMP_THRESH_WARN = 0,
3509 EC_TEMP_THRESH_HIGH,
3510 EC_TEMP_THRESH_HALT,
3511
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003512 EC_TEMP_THRESH_COUNT,
Duncan Laurie93e24442014-01-06 12:30:52 -08003513};
3514
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003515/*
3516 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003517 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003518 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003519 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3520 * hysteresis.
3521 * For example,
3522 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3523 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3524 * EC will throttle ap when temperature >= 301 K, and release throttling when
3525 * temperature <= 299 K.
3526 *
3527 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3528 * For example,
3529 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3530 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3531 * EC will throttle ap when temperature >= 301 K, and release throttling when
3532 * temperature <= 294 K.
3533 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003534 * Note that this structure is a sub-structure of
3535 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003536 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003537struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003538 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003539 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003540 uint32_t temp_fan_off; /* no active cooling needed */
3541 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003542} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003543
3544/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003545struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003546 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003547} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003548/* This returns a struct ec_thermal_config */
3549
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003550/*
3551 * Version 1 - set config for one sensor.
3552 * Use read-modify-write for best results!
3553 */
3554struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003555 uint32_t sensor_num;
3556 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003557} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003558/* This returns no data */
3559
3560/****************************************************************************/
3561
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003562/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003563#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003564
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003565/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003566struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003567 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003568} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003569
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003570/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003571#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3572#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003573
3574/*
3575 * The original TMP006 calibration only needed four params, but now we need
3576 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3577 * the params opaque. The v1 "get" response will include the algorithm number
3578 * and how many params it requires. That way we can change the EC code without
3579 * needing to update this file. We can also use a different algorithm on each
3580 * sensor.
3581 */
3582
3583/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003584struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003585 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003586} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003587
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003588/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003589struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003590 float s0;
3591 float b0;
3592 float b1;
3593 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003594} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003595
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003596struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003597 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003598 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003599 float s0;
3600 float b0;
3601 float b1;
3602 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003603} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003604
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003605/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003606struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003607 uint8_t algorithm;
3608 uint8_t num_params;
3609 uint8_t reserved[2];
3610 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003611} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003612
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003613struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003614 uint8_t index;
3615 uint8_t algorithm;
3616 uint8_t num_params;
3617 uint8_t reserved;
3618 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003619} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003620
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003621/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003622#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003623
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003624struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003625 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003626} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003627
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003628struct ec_response_tmp006_get_raw {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003629 int32_t t; /* In 1/100 K */
3630 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003631} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003632
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003633/*****************************************************************************/
3634/* MKBP - Matrix KeyBoard Protocol */
3635
3636/*
3637 * Read key state
3638 *
3639 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3640 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003641 *
3642 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3643 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3644 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003645 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003646#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003647
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003648/*
3649 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3650 */
3651#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003652
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003653struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003654 uint32_t rows;
3655 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003656 /* Formerly "switches", which was 0. */
3657 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003658} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003659
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003660struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003661 uint8_t info_type;
3662 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003663} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003664
3665enum ec_mkbp_info_type {
3666 /*
3667 * Info about the keyboard matrix: number of rows and columns.
3668 *
3669 * Returns struct ec_response_mkbp_info.
3670 */
3671 EC_MKBP_INFO_KBD = 0,
3672
3673 /*
3674 * For buttons and switches, info about which specifically are
3675 * supported. event_type must be set to one of the values in enum
3676 * ec_mkbp_event.
3677 *
3678 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3679 * bitmask indicating which buttons or switches are present. See the
3680 * bit inidices below.
3681 */
3682 EC_MKBP_INFO_SUPPORTED = 1,
3683
3684 /*
3685 * Instantaneous state of buttons and switches.
3686 *
3687 * event_type must be set to one of the values in enum ec_mkbp_event.
3688 *
3689 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3690 * indicating the current state of the keyboard matrix.
3691 *
3692 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3693 * event state.
3694 *
3695 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3696 * state of supported buttons.
3697 *
3698 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3699 * state of supported switches.
3700 */
3701 EC_MKBP_INFO_CURRENT = 2,
3702};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003703
3704/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003705#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003706
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003707struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003708 uint8_t col;
3709 uint8_t row;
3710 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003711} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003712
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003713#define EC_CMD_GET_KEYBOARD_ID 0x0063
3714
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003715struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003716 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003717} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003718
3719enum keyboard_id {
3720 KEYBOARD_ID_UNSUPPORTED = 0,
3721 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3722};
3723
Duncan Laurie433432b2013-06-03 10:38:22 -07003724/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003725#define EC_CMD_MKBP_SET_CONFIG 0x0064
3726#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003727
3728/* flags */
3729enum mkbp_config_flags {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003730 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
Duncan Laurie433432b2013-06-03 10:38:22 -07003731};
3732
3733enum mkbp_config_valid {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003734 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3735 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3736 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3737 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3738 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3739 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3740 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003741};
3742
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003743/*
3744 * Configuration for our key scanning algorithm.
3745 *
3746 * Note that this is used as a sub-structure of
3747 * ec_{params/response}_mkbp_get_config.
3748 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003749struct ec_mkbp_config {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003750 uint32_t valid_mask; /* valid fields */
3751 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3752 uint8_t valid_flags; /* which flags are valid */
3753 uint16_t scan_period_us; /* period between start of scans */
Duncan Laurie433432b2013-06-03 10:38:22 -07003754 /* revert to interrupt mode after no activity for this long */
3755 uint32_t poll_timeout_us;
3756 /*
3757 * minimum post-scan relax time. Once we finish a scan we check
3758 * the time until we are due to start the next one. If this time is
3759 * shorter this field, we use this instead.
3760 */
3761 uint16_t min_post_scan_delay_us;
3762 /* delay between setting up output and waiting for it to settle */
3763 uint16_t output_settle_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003764 uint16_t debounce_down_us; /* time for debounce on key down */
3765 uint16_t debounce_up_us; /* time for debounce on key up */
Duncan Laurie433432b2013-06-03 10:38:22 -07003766 /* maximum depth to allow for fifo (0 = no keyscan output) */
3767 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003768} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003769
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003770struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003771 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003772} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003773
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003774struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003775 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003776} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003777
3778/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003779#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003780
3781enum ec_keyscan_seq_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003782 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3783 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3784 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3785 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3786 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003787};
3788
3789enum ec_collect_flags {
3790 /*
3791 * Indicates this scan was processed by the EC. Due to timing, some
3792 * scans may be skipped.
3793 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003794 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003795};
3796
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003797struct ec_collect_item {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003798 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003799} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003800
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003801struct ec_params_keyscan_seq_ctrl {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003802 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
Duncan Laurie433432b2013-06-03 10:38:22 -07003803 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003804 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003805 uint8_t active; /* still active */
3806 uint8_t num_items; /* number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003807 /* Current item being presented */
3808 uint8_t cur_item;
3809 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003810 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003811 /*
3812 * Absolute time for this scan, measured from the
3813 * start of the sequence.
3814 */
3815 uint32_t time_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003816 uint8_t scan[0]; /* keyscan data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003817 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003818 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003819 uint8_t start_item; /* First item to return */
3820 uint8_t num_items; /* Number of items to return */
Duncan Laurie433432b2013-06-03 10:38:22 -07003821 } collect;
3822 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003823} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003824
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003825struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003826 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003827 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003828 uint8_t num_items; /* Number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003829 /* Data for each item */
3830 struct ec_collect_item item[0];
3831 } collect;
3832 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003833} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003834
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003835/*
3836 * Get the next pending MKBP event.
3837 *
3838 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3839 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003840#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003841
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003842#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3843
3844/*
3845 * We use the most significant bit of the event type to indicate to the host
3846 * that the EC has more MKBP events available to provide.
3847 */
3848#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3849
3850/* The mask to apply to get the raw event type */
3851#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3852
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003853enum ec_mkbp_event {
3854 /* Keyboard matrix changed. The event data is the new matrix state. */
3855 EC_MKBP_EVENT_KEY_MATRIX = 0,
3856
3857 /* New host event. The event data is 4 bytes of host event flags. */
3858 EC_MKBP_EVENT_HOST_EVENT = 1,
3859
Duncan Laurieeb316852015-12-01 18:51:18 -08003860 /* New Sensor FIFO data. The event data is fifo_info structure. */
3861 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3862
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003863 /* The state of the non-matrixed buttons have changed. */
3864 EC_MKBP_EVENT_BUTTON = 3,
3865
3866 /* The state of the switches have changed. */
3867 EC_MKBP_EVENT_SWITCH = 4,
3868
3869 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3870 EC_MKBP_EVENT_FINGERPRINT = 5,
3871
3872 /*
3873 * Sysrq event: send emulated sysrq. The event data is sysrq,
3874 * corresponding to the key to be pressed.
3875 */
3876 EC_MKBP_EVENT_SYSRQ = 6,
3877
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003878 /*
3879 * New 64-bit host event.
3880 * The event data is 8 bytes of host event flags.
3881 */
3882 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3883
3884 /* Notify the AP that something happened on CEC */
3885 EC_MKBP_EVENT_CEC_EVENT = 8,
3886
3887 /* Send an incoming CEC message to the AP */
3888 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3889
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003890 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3891 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3892
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003893 /* New online calibration values are available. */
3894 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3895
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003896 /* Peripheral device charger event */
3897 EC_MKBP_EVENT_PCHG = 12,
3898
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003899 /* Number of MKBP events */
3900 EC_MKBP_EVENT_COUNT,
3901};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003902BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003903
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003904/* clang-format off */
3905#define EC_MKBP_EVENT_TEXT \
3906 { \
3907 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
3908 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
3909 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
3910 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
3911 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
3912 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
3913 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
3914 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
3915 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
3916 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
3917 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
3918 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
3919 [EC_MKBP_EVENT_PCHG] = "PCHG", \
3920 }
3921/* clang-format on */
3922
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003923union __ec_align_offset1 ec_response_get_next_data {
3924 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003925
3926 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003927 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003928 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003929
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003930 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003931 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003932 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003933 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003934 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003935
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003936 uint32_t buttons;
3937
3938 uint32_t switches;
3939
3940 uint32_t fp_events;
3941
3942 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003943
3944 /* CEC events from enum mkbp_cec_event */
3945 uint32_t cec_events;
3946};
3947
3948union __ec_align_offset1 ec_response_get_next_data_v1 {
3949 uint8_t key_matrix[16];
3950
3951 /* Unaligned */
3952 uint32_t host_event;
3953 uint64_t host_event64;
3954
3955 struct __ec_todo_unpacked {
3956 /* For aligning the fifo_info */
3957 uint8_t reserved[3];
3958 struct ec_response_motion_sense_fifo_info info;
3959 } sensor_fifo;
3960
3961 uint32_t buttons;
3962
3963 uint32_t switches;
3964
3965 uint32_t fp_events;
3966
3967 uint32_t sysrq;
3968
3969 /* CEC events from enum mkbp_cec_event */
3970 uint32_t cec_events;
3971
3972 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003973};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003974BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003975
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003976struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003977 uint8_t event_type;
3978 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003979 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003980} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003981
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003982struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003983 uint8_t event_type;
3984 /* Followed by event data if any */
3985 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003986} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003987
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003988/* Bit indices for buttons and switches.*/
3989/* Buttons */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003990#define EC_MKBP_POWER_BUTTON 0
3991#define EC_MKBP_VOL_UP 1
3992#define EC_MKBP_VOL_DOWN 2
3993#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003994
3995/* Switches */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003996#define EC_MKBP_LID_OPEN 0
3997#define EC_MKBP_TABLET_MODE 1
3998#define EC_MKBP_BASE_ATTACHED 2
3999#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004000
Gwendal Grignou880b4582016-06-20 08:49:25 -07004001/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004002#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07004003
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004004struct ec_response_keyboard_factory_test {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004005 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004006} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004007
4008/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004009#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF)
4010#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004011#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
Caveh Jalali024ffe32023-01-30 14:35:19 -08004012#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
4013 (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004014#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4015#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
Caveh Jalali024ffe32023-01-30 14:35:19 -08004016#define EC_MKBP_FP_MATCH_IDX(fpe) \
4017 (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
4018#define EC_MKBP_FP_ENROLL BIT(27)
4019#define EC_MKBP_FP_MATCH BIT(28)
4020#define EC_MKBP_FP_FINGER_DOWN BIT(29)
4021#define EC_MKBP_FP_FINGER_UP BIT(30)
4022#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004023/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004024#define EC_MKBP_FP_ERR_ENROLL_OK 0
4025#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4026#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4027#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4028#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004029/* Can be used to detect if image was usable for enrollment or not. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004030#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004031/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004032#define EC_MKBP_FP_ERR_MATCH_NO 0
4033#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4034#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
4035#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4036#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4037#define EC_MKBP_FP_ERR_MATCH_YES 1
4038#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004039#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4040
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004041#define EC_CMD_MKBP_WAKE_MASK 0x0069
4042enum ec_mkbp_event_mask_action {
4043 /* Retrieve the value of a wake mask. */
4044 GET_WAKE_MASK = 0,
4045
4046 /* Set the value of a wake mask. */
4047 SET_WAKE_MASK,
4048};
4049
4050enum ec_mkbp_mask_type {
4051 /*
4052 * These are host events sent via MKBP.
4053 *
4054 * Some examples are:
4055 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4056 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4057 *
4058 * The only things that should be in this mask are:
4059 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4060 */
4061 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4062
4063 /*
4064 * These are MKBP events. Some examples are:
4065 *
4066 * EC_MKBP_EVENT_KEY_MATRIX
4067 * EC_MKBP_EVENT_SWITCH
4068 *
4069 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4070 */
4071 EC_MKBP_EVENT_WAKE_MASK,
4072};
4073
4074struct ec_params_mkbp_event_wake_mask {
4075 /* One of enum ec_mkbp_event_mask_action */
4076 uint8_t action;
4077
4078 /*
4079 * Which MKBP mask are you interested in acting upon? This is one of
4080 * ec_mkbp_mask_type.
4081 */
4082 uint8_t mask_type;
4083
4084 /* If setting a new wake mask, this contains the mask to set. */
4085 uint32_t new_wake_mask;
4086};
4087
4088struct ec_response_mkbp_event_wake_mask {
4089 uint32_t wake_mask;
4090};
4091
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004092/*****************************************************************************/
4093/* Temperature sensor commands */
4094
4095/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004096#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004097
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004098struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004099 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004100} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004101
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004102struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004103 char sensor_name[32];
4104 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004105} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004106
4107/*****************************************************************************/
4108
4109/*
4110 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4111 * commands accidentally sent to the wrong interface. See the ACPI section
4112 * below.
4113 */
4114
4115/*****************************************************************************/
4116/* Host event commands */
4117
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004118/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004119/*
4120 * Host event mask params and response structures, shared by all of the host
4121 * event commands below.
4122 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004123struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004124 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004125} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004126
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004127struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004128 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004129} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004130
4131/* These all use ec_response_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004132#define EC_CMD_HOST_EVENT_GET_B 0x0087
4133#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4134#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004135#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004136
4137/* These all use ec_params_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004138#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4139#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4140#define EC_CMD_HOST_EVENT_CLEAR 0x008C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004141#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
Caveh Jalali024ffe32023-01-30 14:35:19 -08004142#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004143
Jenny TC1dfc2c32017-12-14 14:24:39 +05304144/*
4145 * Unified host event programming interface - Should be used by newer versions
4146 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004147 *
4148 * EC returns:
4149 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4150 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304151 */
4152
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004153struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304154 /* Action requested by host - one of enum ec_host_event_action. */
4155 uint8_t action;
4156
4157 /*
4158 * Mask type that the host requested the action on - one of
4159 * enum ec_host_event_mask_type.
4160 */
4161 uint8_t mask_type;
4162
4163 /* Set to 0, ignore on read */
4164 uint16_t reserved;
4165
4166 /* Value to be used in case of set operations. */
4167 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004168} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304169
4170/*
4171 * Response structure returned by EC_CMD_HOST_EVENT.
4172 * Update the value on a GET request. Set to 0 on GET/CLEAR
4173 */
4174
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004175struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304176 /* Mask value in case of get operation */
4177 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004178} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304179
4180enum ec_host_event_action {
4181 /*
4182 * params.value is ignored. Value of mask_type populated
4183 * in response.value
4184 */
4185 EC_HOST_EVENT_GET,
4186
4187 /* Bits in params.value are set */
4188 EC_HOST_EVENT_SET,
4189
4190 /* Bits in params.value are cleared */
4191 EC_HOST_EVENT_CLEAR,
4192};
4193
4194enum ec_host_event_mask_type {
4195
4196 /* Main host event copy */
4197 EC_HOST_EVENT_MAIN,
4198
4199 /* Copy B of host events */
4200 EC_HOST_EVENT_B,
4201
4202 /* SCI Mask */
4203 EC_HOST_EVENT_SCI_MASK,
4204
4205 /* SMI Mask */
4206 EC_HOST_EVENT_SMI_MASK,
4207
4208 /* Mask of events that should be always reported in hostevents */
4209 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4210
4211 /* Active wake mask */
4212 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4213
4214 /* Lazy wake mask for S0ix */
4215 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4216
4217 /* Lazy wake mask for S3 */
4218 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4219
4220 /* Lazy wake mask for S5 */
4221 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4222};
4223
Caveh Jalali024ffe32023-01-30 14:35:19 -08004224#define EC_CMD_HOST_EVENT 0x00A4
Jenny TC1dfc2c32017-12-14 14:24:39 +05304225
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004226/*****************************************************************************/
4227/* Switch commands */
4228
4229/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004230#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004231
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004232struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004233 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004234} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004235
4236/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004237#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004238#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004239
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004240/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004241struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004242 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004243} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004244
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004245/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004246struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004247 /* Flags to enable now */
4248 uint8_t now_flags;
4249
4250 /* Which flags to copy from now_flags */
4251 uint8_t now_mask;
4252
4253 /*
4254 * Flags to leave enabled in S3, if they're on at the S0->S3
4255 * transition. (Other flags will be disabled by the S0->S3
4256 * transition.)
4257 */
4258 uint8_t suspend_flags;
4259
4260 /* Which flags to copy from suspend_flags */
4261 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004262} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004263
4264/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004265struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004266 /* Flags to enable now */
4267 uint8_t now_flags;
4268
4269 /* Flags to leave enabled in S3 */
4270 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004271} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004272
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004273/*****************************************************************************/
4274/* GPIO commands. Only available on EC if write protect has been disabled. */
4275
4276/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004277#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004278
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004279struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004280 char name[32];
4281 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004282} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004283
4284/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004285#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004286
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004287/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004288struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004289 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004290} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004291
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004292struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004293 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004294} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004295
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004296/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004297struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004298 uint8_t subcmd;
4299 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004300 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004301 char name[32];
4302 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004303 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004304 uint8_t index;
4305 } get_info;
4306 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004307} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004308
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004309struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004310 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004311 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004312 uint8_t val;
4313 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004314 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004315 uint8_t val;
4316 char name[32];
4317 uint32_t flags;
4318 } get_info;
4319 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004320} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004321
4322enum gpio_get_subcmd {
4323 EC_GPIO_GET_BY_NAME = 0,
4324 EC_GPIO_GET_COUNT = 1,
4325 EC_GPIO_GET_INFO = 2,
4326};
4327
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004328/*****************************************************************************/
4329/* I2C commands. Only available when flash write protect is unlocked. */
4330
Duncan Laurie93e24442014-01-06 12:30:52 -08004331/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004332 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4333 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4334 *
4335 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004336 */
4337
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004338/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004339#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004340
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004341struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004342 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004343 uint8_t read_size; /* Either 8 or 16. */
4344 uint8_t port;
4345 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004346} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004347
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004348struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004349 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004350} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004351
4352/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004353#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004354
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004355struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004356 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004357 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004358 uint8_t write_size; /* Either 8 or 16. */
4359 uint8_t port;
4360 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004361} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004362
4363/*****************************************************************************/
4364/* Charge state commands. Only available when flash write protect unlocked. */
4365
Duncan Laurie93e24442014-01-06 12:30:52 -08004366/* Force charge state machine to stop charging the battery or force it to
4367 * discharge the battery.
4368 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004369#define EC_CMD_CHARGE_CONTROL 0x0096
Scott Chao18141d8c2021-07-30 10:40:57 +08004370#define EC_VER_CHARGE_CONTROL 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004371
Duncan Laurie93e24442014-01-06 12:30:52 -08004372enum ec_charge_control_mode {
4373 CHARGE_CONTROL_NORMAL = 0,
4374 CHARGE_CONTROL_IDLE,
4375 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004376 /* Add no more entry below. */
4377 CHARGE_CONTROL_COUNT,
4378};
4379
Caveh Jalali024ffe32023-01-30 14:35:19 -08004380#define EC_CHARGE_MODE_TEXT \
4381 { \
4382 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4383 [CHARGE_CONTROL_IDLE] = "IDLE", \
4384 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
Scott Chao18141d8c2021-07-30 10:40:57 +08004385 }
4386
4387enum ec_charge_control_cmd {
4388 EC_CHARGE_CONTROL_CMD_SET = 0,
4389 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004390};
4391
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004392struct ec_params_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004393 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004394
4395 /* Below are the fields added in V2. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004396 uint8_t cmd; /* enum ec_charge_control_cmd. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004397 uint8_t reserved;
4398 /*
4399 * Lower and upper thresholds for battery sustainer. This struct isn't
4400 * named to avoid tainting foreign projects' name spaces.
4401 *
4402 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4403 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4404 * lower=-1, upper=-1.
4405 */
4406 struct {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004407 int8_t lower; /* Display SoC in percentage. */
4408 int8_t upper; /* Display SoC in percentage. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004409 } sustain_soc;
4410} __ec_align4;
4411
4412/* Added in v2 */
4413struct ec_response_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004414 uint32_t mode; /* enum charge_control_mode */
4415 struct { /* Battery sustainer thresholds */
Scott Chao18141d8c2021-07-30 10:40:57 +08004416 int8_t lower;
4417 int8_t upper;
4418 } sustain_soc;
4419 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004420} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004421
4422/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004423
4424/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004425#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004426
4427/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004428 * Read data from the saved snapshot. If the subcmd parameter is
4429 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4430 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4431 * end of the previous snapshot.
4432 *
4433 * The params are only looked at in version >= 1 of this command. Prior
4434 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004435 *
4436 * Response is null-terminated string. Empty string, if there is no more
4437 * remaining output.
4438 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004439#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004440
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004441enum ec_console_read_subcmd {
4442 CONSOLE_READ_NEXT = 0,
4443 CONSOLE_READ_RECENT,
4444};
Duncan Laurieeb316852015-12-01 18:51:18 -08004445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004446struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004447 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004448} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004449
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004450/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004451
4452/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004453 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004454 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004455 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4456 * EC_RES_SUCCESS if the command was successful.
4457 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004458 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004459#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004460
Caveh Jalali024ffe32023-01-30 14:35:19 -08004461#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004462
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004463struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004464 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004465} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004466
Duncan Laurie433432b2013-06-03 10:38:22 -07004467/*****************************************************************************/
4468/* USB port mux control. */
4469
4470/*
4471 * Switch USB mux or return to automatic switching.
4472 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004473#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004474
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004475struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004476 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004477} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004478
4479/*****************************************************************************/
4480/* LDOs / FETs control. */
4481
4482enum ec_ldo_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004483 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4484 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
Duncan Laurie433432b2013-06-03 10:38:22 -07004485};
4486
4487/*
4488 * Switch on/off a LDO.
4489 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004490#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004491
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004492struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004493 uint8_t index;
4494 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004495} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004496
4497/*
4498 * Get LDO state.
4499 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004500#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004502struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004503 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004504} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004505
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004506struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004507 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004508} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004509
4510/*****************************************************************************/
4511/* Power info. */
4512
4513/*
4514 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004515 *
4516 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004517 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004518#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004519
Jett Rinkba2edaf2020-01-14 11:49:06 -07004520/*
4521 * v1 of EC_CMD_POWER_INFO
4522 */
4523enum system_power_source {
4524 /*
4525 * Haven't established which power source is used yet,
4526 * or no presence signals are available
4527 */
4528 POWER_SOURCE_UNKNOWN = 0,
4529 /* System is running on battery alone */
4530 POWER_SOURCE_BATTERY = 1,
4531 /* System is running on A/C alone */
4532 POWER_SOURCE_AC = 2,
4533 /* System is running on A/C and battery */
4534 POWER_SOURCE_AC_BATTERY = 3,
4535};
4536
4537struct ec_response_power_info_v1 {
4538 /* enum system_power_source */
4539 uint8_t system_power_source;
4540 /* Battery state-of-charge, 0-100, 0 if not present */
4541 uint8_t battery_soc;
4542 /* AC Adapter 100% rating, Watts */
4543 uint8_t ac_adapter_100pct;
4544 /* AC Adapter 10ms rating, Watts */
4545 uint8_t ac_adapter_10ms;
4546 /* Battery 1C rating, derated */
4547 uint8_t battery_1cd;
4548 /* Rest of Platform average, Watts */
4549 uint8_t rop_avg;
4550 /* Rest of Platform peak, Watts */
4551 uint8_t rop_peak;
4552 /* Nominal charger efficiency, % */
4553 uint8_t nominal_charger_eff;
4554 /* Rest of Platform VR Average Efficiency, % */
4555 uint8_t rop_avg_eff;
4556 /* Rest of Platform VR Peak Efficiency, % */
4557 uint8_t rop_peak_eff;
4558 /* SoC VR Efficiency at Average level, % */
4559 uint8_t soc_avg_eff;
4560 /* SoC VR Efficiency at Peak level, % */
4561 uint8_t soc_peak_eff;
4562 /* Intel-specific items */
4563 struct {
4564 /* Battery's level of DBPT support: 0, 2 */
4565 uint8_t batt_dbpt_support_level;
4566 /*
4567 * Maximum peak power from battery (10ms), Watts
4568 * If DBPT is not supported, this is 0
4569 */
4570 uint8_t batt_dbpt_max_peak_power;
4571 /*
4572 * Sustained peak power from battery, Watts
4573 * If DBPT is not supported, this is 0
4574 */
4575 uint8_t batt_dbpt_sus_peak_power;
4576 } intel;
4577} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004578
4579/*****************************************************************************/
4580/* I2C passthru command */
4581
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004582#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004583
Duncan Laurie433432b2013-06-03 10:38:22 -07004584/* Read data; if not present, message is a write */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004585#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004586
4587/* Mask for address */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004588#define EC_I2C_ADDR_MASK 0x3ff
Duncan Laurie433432b2013-06-03 10:38:22 -07004589
Caveh Jalali024ffe32023-01-30 14:35:19 -08004590#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4591#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004592
4593/* Any error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004594#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
Duncan Laurie433432b2013-06-03 10:38:22 -07004595
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004596struct ec_params_i2c_passthru_msg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004597 uint16_t addr_flags; /* I2C peripheral address and flags */
4598 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004599} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004600
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004601struct ec_params_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004602 uint8_t port; /* I2C port number */
4603 uint8_t num_msgs; /* Number of messages */
Duncan Laurie433432b2013-06-03 10:38:22 -07004604 struct ec_params_i2c_passthru_msg msg[];
4605 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004606} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004607
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004608struct ec_response_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004609 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4610 uint8_t num_msgs; /* Number of messages processed */
4611 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004612} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004613
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004614/*****************************************************************************/
4615/* Power button hang detect */
4616
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004617#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004618
4619/* Reasons to start hang detection timer */
4620/* Power button pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004621#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004622
4623/* Lid closed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004624#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004625
Caveh Jalali024ffe32023-01-30 14:35:19 -08004626/* Lid opened */
4627#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004628
4629/* Start of AP S3->S0 transition (booting or resuming from suspend) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004630#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004631
4632/* Reasons to cancel hang detection */
4633
4634/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004635#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004636
4637/* Any host command from AP received */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004638#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004639
4640/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004641#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004642
4643/*
4644 * If this flag is set, all the other fields are ignored, and the hang detect
4645 * timer is started. This provides the AP a way to start the hang timer
4646 * without reconfiguring any of the other hang detect settings. Note that
4647 * you must previously have configured the timeouts.
4648 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004649#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004650
4651/*
4652 * If this flag is set, all the other fields are ignored (including
4653 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4654 * without reconfiguring any of the other hang detect settings.
4655 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004656#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004657
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004658struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004659 /* Flags; see EC_HANG_* */
4660 uint32_t flags;
4661
4662 /* Timeout in msec before generating host event, if enabled */
4663 uint16_t host_event_timeout_msec;
4664
4665 /* Timeout in msec before generating warm reboot, if enabled */
4666 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004667} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004668
4669/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004670/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004671
4672/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004673 * This is the single catch-all host command to exchange data regarding the
4674 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004675 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004676#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004677
4678/* Subcommands for this host command */
4679enum charge_state_command {
4680 CHARGE_STATE_CMD_GET_STATE,
4681 CHARGE_STATE_CMD_GET_PARAM,
4682 CHARGE_STATE_CMD_SET_PARAM,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004683 CHARGE_STATE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004684};
4685
4686/*
4687 * Known param numbers are defined here. Ranges are reserved for board-specific
4688 * params, which are handled by the particular implementations.
4689 */
4690enum charge_state_params {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004691 /* charger voltage limit */
4692 CS_PARAM_CHG_VOLTAGE,
4693
4694 /* charger current limit */
4695 CS_PARAM_CHG_CURRENT,
4696
4697 /* charger input current limit */
4698 CS_PARAM_CHG_INPUT_CURRENT,
4699
4700 /* charger-specific status */
4701 CS_PARAM_CHG_STATUS,
4702
4703 /* charger-specific options */
4704 CS_PARAM_CHG_OPTION,
4705
4706 /*
4707 * Check if power is limited due to low battery and / or a
4708 * weak external charger. READ ONLY.
4709 */
4710 CS_PARAM_LIMIT_POWER,
4711
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004712 /* How many so far? */
4713 CS_NUM_BASE_PARAMS,
4714
4715 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4716 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4717 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4718
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004719 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4720 CS_PARAM_DEBUG_MIN = 0x20000,
4721 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4722 CS_PARAM_DEBUG_MANUAL_MODE,
4723 CS_PARAM_DEBUG_SEEMS_DEAD,
4724 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4725 CS_PARAM_DEBUG_BATT_REMOVED,
4726 CS_PARAM_DEBUG_MANUAL_CURRENT,
4727 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4728 CS_PARAM_DEBUG_MAX = 0x2ffff,
4729
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004730 /* Other custom param ranges go here... */
4731};
4732
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004733struct ec_params_charge_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004734 uint8_t cmd; /* enum charge_state_command */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004735 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004736 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004737
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004738 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004739 uint32_t param; /* enum charge_state_param */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004740 } get_param;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004741
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004742 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004743 uint32_t param; /* param to set */
4744 uint32_t value; /* value to set */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004745 } set_param;
4746 } __ec_todo_packed;
Caveh Jalali024ffe32023-01-30 14:35:19 -08004747 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004748} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004749
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004750struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004751 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004752 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004753 int ac;
4754 int chg_voltage;
4755 int chg_current;
4756 int chg_input_current;
4757 int batt_state_of_charge;
4758 } get_state;
4759
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004760 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004761 uint32_t value;
4762 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004763
4764 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004765 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004766} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004767
Duncan Laurie433432b2013-06-03 10:38:22 -07004768/*
4769 * Set maximum battery charging current.
4770 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004771#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004772
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004773struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004774 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004775} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004776
4777/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004778 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004779 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004780#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004781
Duncan Laurieeb316852015-12-01 18:51:18 -08004782/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004783struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004784 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4785 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004786} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004787
Duncan Laurieeb316852015-12-01 18:51:18 -08004788#define EC_POWER_LIMIT_NONE 0xffff
4789
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004790/*
4791 * Set maximum voltage & current of a dedicated charge port
4792 */
4793#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004795struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004796 uint16_t current_lim; /* in mA */
4797 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004798} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004799
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08004800/*
4801 * Get and set charging splashscreen variables
4802 */
4803#define EC_CMD_CHARGESPLASH 0x00A5
4804
4805enum ec_chargesplash_cmd {
4806 /* Get the current state variables */
4807 EC_CHARGESPLASH_GET_STATE = 0,
4808
4809 /* Indicate initialization of the display loop */
4810 EC_CHARGESPLASH_DISPLAY_READY,
4811
4812 /* Manually put the EC into the requested state */
4813 EC_CHARGESPLASH_REQUEST,
4814
4815 /* Reset all state variables */
4816 EC_CHARGESPLASH_RESET,
4817
4818 /* Manually trigger a lockout */
4819 EC_CHARGESPLASH_LOCKOUT,
4820};
4821
4822struct __ec_align1 ec_params_chargesplash {
4823 /* enum ec_chargesplash_cmd */
4824 uint8_t cmd;
4825};
4826
4827struct __ec_align1 ec_response_chargesplash {
4828 uint8_t requested;
4829 uint8_t display_initialized;
4830 uint8_t locked_out;
4831};
4832
Duncan Laurieeb316852015-12-01 18:51:18 -08004833/*****************************************************************************/
4834/* Hibernate/Deep Sleep Commands */
4835
4836/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004837#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004838
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004839struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004840 /*
4841 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4842 * current settings without changing them.
4843 */
4844 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004845} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004846
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004847struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004848 /*
4849 * The current time in seconds in which the system has been in the G3
4850 * state. This value is reset if the EC transitions out of G3.
4851 */
4852 uint32_t time_g3;
4853
4854 /*
4855 * The current time remaining in seconds until the EC should hibernate.
4856 * This value is also reset if the EC transitions out of G3.
4857 */
4858 uint32_t time_remaining;
4859
4860 /*
4861 * The current time in seconds that the EC should wait in G3 before
4862 * hibernating.
4863 */
4864 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004865} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004866
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004867/* Inform the EC when entering a sleep state */
4868#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4869
4870enum host_sleep_event {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004871 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4872 HOST_SLEEP_EVENT_S3_RESUME = 2,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004873 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Caveh Jalali024ffe32023-01-30 14:35:19 -08004874 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004875 /* S3 suspend with additional enabled wake sources */
4876 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004877};
4878
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004879struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004880 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004881} __ec_align1;
4882
4883/*
4884 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4885 * transition failures
4886 */
4887#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4888
4889/* Disable timeout detection for this sleep transition */
4890#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4891
4892struct ec_params_host_sleep_event_v1 {
4893 /* The type of sleep being entered or exited. */
4894 uint8_t sleep_event;
4895
4896 /* Padding */
4897 uint8_t reserved;
4898 union {
4899 /* Parameters that apply for suspend messages. */
4900 struct {
4901 /*
4902 * The timeout in milliseconds between when this message
4903 * is received and when the EC will declare sleep
4904 * transition failure if the sleep signal is not
4905 * asserted.
4906 */
4907 uint16_t sleep_timeout_ms;
4908 } suspend_params;
4909
4910 /* No parameters for non-suspend messages. */
4911 };
4912} __ec_align2;
4913
4914/* A timeout occurred when this bit is set */
4915#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4916
4917/*
4918 * The mask defining which bits correspond to the number of sleep transitions,
4919 * as well as the maximum number of suspend line transitions that will be
4920 * reported back to the host.
4921 */
4922#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4923
4924struct ec_response_host_sleep_event_v1 {
4925 union {
4926 /* Response fields that apply for resume messages. */
4927 struct {
4928 /*
4929 * The number of sleep power signal transitions that
4930 * occurred since the suspend message. The high bit
4931 * indicates a timeout occurred.
4932 */
4933 uint32_t sleep_transitions;
4934 } resume_response;
4935
4936 /* No response fields for non-resume messages. */
4937 };
4938} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004939
4940/*****************************************************************************/
4941/* Device events */
4942#define EC_CMD_DEVICE_EVENT 0x00AA
4943
4944enum ec_device_event {
4945 EC_DEVICE_EVENT_TRACKPAD,
4946 EC_DEVICE_EVENT_DSP,
4947 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004948 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004949};
4950
4951enum ec_device_event_param {
4952 /* Get and clear pending device events */
4953 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4954 /* Get device event mask */
4955 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4956 /* Set device event mask */
4957 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4958};
4959
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004960#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004961
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004962struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004963 uint32_t event_mask;
4964 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004965} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004966
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004967struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004968 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004969} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004970
Duncan Laurie433432b2013-06-03 10:38:22 -07004971/*****************************************************************************/
4972/* Smart battery pass-through */
4973
4974/* Get / Set 16-bit smart battery registers */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004975#define EC_CMD_SB_READ_WORD 0x00B0
4976#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004977
4978/* Get / Set string smart battery parameters
4979 * formatted as SMBUS "block".
4980 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004981#define EC_CMD_SB_READ_BLOCK 0x00B2
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004982#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004983
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004984struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004985 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004986} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004987
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004988struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004989 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004990} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004991
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004992struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004993 uint8_t reg;
4994 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004995} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004996
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004997struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004998 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004999} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07005000
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005001struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07005002 uint8_t reg;
5003 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005004} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005005
5006/*****************************************************************************/
5007/* Battery vendor parameters
5008 *
5009 * Get or set vendor-specific parameters in the battery. Implementations may
5010 * differ between boards or batteries. On a set operation, the response
5011 * contains the actual value set, which may be rounded or clipped from the
5012 * requested value.
5013 */
5014
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005015#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005016
5017enum ec_battery_vendor_param_mode {
5018 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5019 BATTERY_VENDOR_PARAM_MODE_SET,
5020};
5021
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005022struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005023 uint32_t param;
5024 uint32_t value;
5025 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005026} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005027
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005028struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005029 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005030} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005031
5032/*****************************************************************************/
5033/*
5034 * Smart Battery Firmware Update Commands
5035 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005036#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005037
5038enum ec_sb_fw_update_subcmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005039 EC_SB_FW_UPDATE_PREPARE = 0x0,
5040 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
5041 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
5042 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
5043 EC_SB_FW_UPDATE_END = 0x4,
5044 EC_SB_FW_UPDATE_STATUS = 0x5,
5045 EC_SB_FW_UPDATE_PROTECT = 0x6,
5046 EC_SB_FW_UPDATE_MAX = 0x7,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005047};
5048
5049#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
5050#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
5051#define SB_FW_UPDATE_CMD_INFO_SIZE 8
5052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005053struct ec_sb_fw_update_header {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005054 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
5055 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005056} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005057
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005058struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005059 struct ec_sb_fw_update_header hdr;
5060 union {
5061 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
5062 /* EC_SB_FW_UPDATE_INFO = 0x1 */
5063 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
5064 /* EC_SB_FW_UPDATE_END = 0x4 */
5065 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
5066 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005067 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005068
5069 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005070 struct __ec_align4 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005071 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005072 } write;
5073 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005074} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005075
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005076struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005077 union {
5078 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005079 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005080 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
5081 } info;
5082
5083 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005084 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005085 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
5086 } status;
5087 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005088} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005089
5090/*
5091 * Entering Verified Boot Mode Command
5092 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5093 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07005094 *
5095 * EC no longer needs to know what mode vboot has entered,
5096 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005097 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005098#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005099
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005100struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005101 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005102} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005103
Caveh Jalali024ffe32023-01-30 14:35:19 -08005104#define VBOOT_MODE_NORMAL 0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005105#define VBOOT_MODE_DEVELOPER 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08005106#define VBOOT_MODE_RECOVERY 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005107
Duncan Laurie433432b2013-06-03 10:38:22 -07005108/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07005109/*
5110 * I2C passthru protection command: Protects I2C tunnels against access on
5111 * certain addresses (board-specific).
5112 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005113#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07005114
5115enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005116 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5117 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5118 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005119};
5120
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005121struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005122 uint8_t subcmd;
Caveh Jalali024ffe32023-01-30 14:35:19 -08005123 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005124} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005126struct ec_response_i2c_passthru_protect {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005127 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005128} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005129
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005130/*****************************************************************************/
5131/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005132 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005133 *
5134 * These commands are for sending and receiving message via HDMI CEC
5135 */
5136
5137#define MAX_CEC_MSG_LEN 16
5138
5139/* CEC message from the AP to be written on the CEC bus */
5140#define EC_CMD_CEC_WRITE_MSG 0x00B8
5141
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005142/**
5143 * struct ec_params_cec_write - Message to write to the CEC bus
5144 * @msg: message content to write to the CEC bus
5145 */
5146struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005147 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005148} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005149
5150/* Set various CEC parameters */
5151#define EC_CMD_CEC_SET 0x00BA
5152
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005153/**
5154 * struct ec_params_cec_set - CEC parameters set
5155 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5156 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5157 * or 1 to enable CEC functionality, in case cmd is
5158 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5159 * address between 0 and 15 or 0xff to unregister
5160 */
5161struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005162 uint8_t cmd; /* enum cec_command */
5163 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005164} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005165
5166/* Read various CEC parameters */
5167#define EC_CMD_CEC_GET 0x00BB
5168
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005169/**
5170 * struct ec_params_cec_get - CEC parameters get
5171 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5172 */
5173struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005174 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005175} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005176
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005177/**
5178 * struct ec_response_cec_get - CEC parameters get response
5179 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5180 * disabled or 1 if CEC functionality is enabled,
5181 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5182 * configured logical address between 0 and 15 or 0xff if unregistered
5183 */
5184struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005185 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005186} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005187
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005188/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005189enum cec_command {
5190 /* CEC reading, writing and events enable */
5191 CEC_CMD_ENABLE,
5192 /* CEC logical address */
5193 CEC_CMD_LOGICAL_ADDRESS,
5194};
5195
5196/* Events from CEC to AP */
5197enum mkbp_cec_event {
5198 /* Outgoing message was acknowledged by a follower */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005199 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005200 /* Outgoing message was not acknowledged */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005201 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005202};
5203
Gwendal Grignou880b4582016-06-20 08:49:25 -07005204/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005205
Jett Rinkba2edaf2020-01-14 11:49:06 -07005206/* Commands for audio codec. */
5207#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005208
Jett Rinkba2edaf2020-01-14 11:49:06 -07005209enum ec_codec_subcmd {
5210 EC_CODEC_GET_CAPABILITIES = 0x0,
5211 EC_CODEC_GET_SHM_ADDR = 0x1,
5212 EC_CODEC_SET_SHM_ADDR = 0x2,
5213 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005214};
5215
Jett Rinkba2edaf2020-01-14 11:49:06 -07005216enum ec_codec_cap {
5217 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5218 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5219 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005220};
5221
Jett Rinkba2edaf2020-01-14 11:49:06 -07005222enum ec_codec_shm_id {
5223 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5224 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5225 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005226};
5227
Jett Rinkba2edaf2020-01-14 11:49:06 -07005228enum ec_codec_shm_type {
5229 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5230 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005231};
5232
Jett Rinkba2edaf2020-01-14 11:49:06 -07005233struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5234 uint8_t shm_id;
5235 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005236};
5237
Jett Rinkba2edaf2020-01-14 11:49:06 -07005238struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5239 uint64_t phys_addr;
5240 uint32_t len;
5241 uint8_t shm_id;
5242 uint8_t reserved[3];
5243};
5244
5245struct __ec_align4 ec_param_ec_codec {
5246 uint8_t cmd; /* enum ec_codec_subcmd */
5247 uint8_t reserved[3];
5248
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005249 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005250 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5251 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005252 };
5253};
5254
Jett Rinkba2edaf2020-01-14 11:49:06 -07005255struct __ec_align4 ec_response_ec_codec_get_capabilities {
5256 uint32_t capabilities;
5257};
5258
5259struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5260 uint64_t phys_addr;
5261 uint32_t len;
5262 uint8_t type;
5263 uint8_t reserved[3];
5264};
5265
5266/*****************************************************************************/
5267
5268/* Commands for DMIC on audio codec. */
5269#define EC_CMD_EC_CODEC_DMIC 0x00BD
5270
5271enum ec_codec_dmic_subcmd {
5272 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5273 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5274 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5275 EC_CODEC_DMIC_SUBCMD_COUNT,
5276};
5277
5278enum ec_codec_dmic_channel {
5279 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5280 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5281 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5282 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5283 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5284 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5285 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5286 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5287 EC_CODEC_DMIC_CHANNEL_COUNT,
5288};
5289
5290struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5291 uint8_t channel; /* enum ec_codec_dmic_channel */
5292 uint8_t gain;
5293 uint8_t reserved[2];
5294};
5295
5296struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5297 uint8_t channel; /* enum ec_codec_dmic_channel */
5298 uint8_t reserved[3];
5299};
5300
5301struct __ec_align4 ec_param_ec_codec_dmic {
5302 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5303 uint8_t reserved[3];
5304
5305 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005306 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5307 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005308 };
5309};
5310
5311struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5312 uint8_t max_gain;
5313};
5314
5315struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5316 uint8_t gain;
5317};
5318
5319/*****************************************************************************/
5320
5321/* Commands for I2S RX on audio codec. */
5322
5323#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5324
5325enum ec_codec_i2s_rx_subcmd {
5326 EC_CODEC_I2S_RX_ENABLE = 0x0,
5327 EC_CODEC_I2S_RX_DISABLE = 0x1,
5328 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5329 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5330 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005331 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005332 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5333};
5334
5335enum ec_codec_i2s_rx_sample_depth {
5336 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5337 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5338 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5339};
5340
5341enum ec_codec_i2s_rx_daifmt {
5342 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5343 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5344 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5345 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5346};
5347
5348struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5349 uint8_t depth;
5350 uint8_t reserved[3];
5351};
5352
5353struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5354 uint8_t left;
5355 uint8_t right;
5356 uint8_t reserved[2];
5357};
5358
5359struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5360 uint8_t daifmt;
5361 uint8_t reserved[3];
5362};
5363
5364struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5365 uint32_t bclk;
5366};
5367
5368struct __ec_align4 ec_param_ec_codec_i2s_rx {
5369 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5370 uint8_t reserved[3];
5371
5372 union {
5373 struct ec_param_ec_codec_i2s_rx_set_sample_depth
Caveh Jalali024ffe32023-01-30 14:35:19 -08005374 set_sample_depth_param;
5375 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5376 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005377 };
5378};
5379
5380/*****************************************************************************/
5381/* Commands for WoV on audio codec. */
5382
5383#define EC_CMD_EC_CODEC_WOV 0x00BF
5384
5385enum ec_codec_wov_subcmd {
5386 EC_CODEC_WOV_SET_LANG = 0x0,
5387 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5388 EC_CODEC_WOV_GET_LANG = 0x2,
5389 EC_CODEC_WOV_ENABLE = 0x3,
5390 EC_CODEC_WOV_DISABLE = 0x4,
5391 EC_CODEC_WOV_READ_AUDIO = 0x5,
5392 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5393 EC_CODEC_WOV_SUBCMD_COUNT,
5394};
5395
5396/*
5397 * @hash is SHA256 of the whole language model.
5398 * @total_len indicates the length of whole language model.
5399 * @offset is the cursor from the beginning of the model.
5400 * @buf is the packet buffer.
5401 * @len denotes how many bytes in the buf.
5402 */
5403struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5404 uint8_t hash[32];
5405 uint32_t total_len;
5406 uint32_t offset;
5407 uint8_t buf[128];
5408 uint32_t len;
5409};
5410
5411struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5412 uint8_t hash[32];
5413 uint32_t total_len;
5414};
5415
5416struct __ec_align4 ec_param_ec_codec_wov {
5417 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5418 uint8_t reserved[3];
5419
5420 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005421 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5422 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005423 };
5424};
5425
5426struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5427 uint8_t hash[32];
5428};
5429
5430struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5431 uint8_t buf[128];
5432 uint32_t len;
5433};
5434
5435struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5436 uint32_t offset;
5437 uint32_t len;
5438};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005439
5440/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005441/* Commands for PoE PSE controller */
5442
5443#define EC_CMD_PSE 0x00C0
5444
5445enum ec_pse_subcmd {
5446 EC_PSE_STATUS = 0x0,
5447 EC_PSE_ENABLE = 0x1,
5448 EC_PSE_DISABLE = 0x2,
5449 EC_PSE_SUBCMD_COUNT,
5450};
5451
5452struct __ec_align1 ec_params_pse {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005453 uint8_t cmd; /* enum ec_pse_subcmd */
5454 uint8_t port; /* PSE port */
Yidi Lin42f79592020-09-21 18:04:10 +08005455};
5456
5457enum ec_pse_status {
5458 EC_PSE_STATUS_DISABLED = 0x0,
5459 EC_PSE_STATUS_ENABLED = 0x1,
5460 EC_PSE_STATUS_POWERED = 0x2,
5461};
5462
5463struct __ec_align1 ec_response_pse_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005464 uint8_t status; /* enum ec_pse_status */
Yidi Lin42f79592020-09-21 18:04:10 +08005465};
5466
5467/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005468/* System commands */
5469
5470/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005471 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5472 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005473 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005474#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005475
5476/* Command */
5477enum ec_reboot_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005478 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5479 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5480 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005481 /* (command 3 was jump to RW-B) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005482 EC_REBOOT_COLD = 4, /* Cold-reboot */
5483 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5484 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005485 /*
5486 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5487 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5488 */
5489 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005490 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5491 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005492};
5493
5494/* Flags for ec_params_reboot_ec.reboot_flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005495#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5496#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5497#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5498#define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005499
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005500struct ec_params_reboot_ec {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005501 uint8_t cmd; /* enum ec_reboot_cmd */
5502 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005503} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005504
Duncan Laurie433432b2013-06-03 10:38:22 -07005505/*
5506 * Get information on last EC panic.
5507 *
5508 * Returns variable-length platform-dependent panic information. See panic.h
5509 * for details.
5510 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005511#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005512
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005513/*****************************************************************************/
5514/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005515 * Special commands
5516 *
5517 * These do not follow the normal rules for commands. See each command for
5518 * details.
5519 */
5520
5521/*
5522 * Reboot NOW
5523 *
5524 * This command will work even when the EC LPC interface is busy, because the
5525 * reboot command is processed at interrupt level. Note that when the EC
5526 * reboots, the host will reboot too, so there is no response to this command.
5527 *
5528 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5529 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005530#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005531
5532/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005533 * Resend last response (not supported on LPC).
5534 *
5535 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5536 * there was no previous command, or the previous command's response was too
5537 * big to save.
5538 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005539#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005540
5541/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005542 * This header byte on a command indicate version 0. Any header byte less
5543 * than this means that we are talking to an old EC which doesn't support
5544 * versioning. In that case, we assume version 0.
5545 *
5546 * Header bytes greater than this indicate a later version. For example,
5547 * EC_CMD_VERSION0 + 1 means we are using version 1.
5548 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005549 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005550 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005551#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005552
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005553/*****************************************************************************/
5554/*
5555 * PD commands
5556 *
5557 * These commands are for PD MCU communication.
5558 */
5559
5560/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005561#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005562#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005563
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005564enum pd_charge_state {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005565 /* Don't change charge state */
5566 PD_CHARGE_NO_CHANGE = 0,
5567
5568 /* No charging allowed */
5569 PD_CHARGE_NONE,
5570
5571 /* 5V charging only */
5572 PD_CHARGE_5V,
5573
5574 /* Charge at max voltage */
5575 PD_CHARGE_MAX,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005576};
5577
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005578/* Status of EC being sent to PD */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005579#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005580
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005581struct ec_params_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005582 /* EC status */
5583 uint8_t status;
5584
5585 /* battery state of charge */
5586 int8_t batt_soc;
5587
5588 /* charging state (from enum pd_charge_state) */
5589 uint8_t charge_state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005590} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005591
5592/* Status of PD being sent back to EC */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005593#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5594#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005595#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005596#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5597#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5598#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5599#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
5600#define PD_STATUS_EC_INT_ACTIVE \
5601 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005602struct ec_response_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005603 /* input current limit */
5604 uint32_t curr_lim_ma;
5605
5606 /* PD MCU status */
5607 uint16_t status;
5608
5609 /* active charging port */
5610 int8_t active_charge_port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005611} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005612
5613/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005614#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005615
5616/* PD MCU host event status bits */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005617#define PD_EVENT_UPDATE_DEVICE BIT(0)
5618#define PD_EVENT_POWER_CHANGE BIT(1)
5619#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5620#define PD_EVENT_DATA_SWAP BIT(3)
5621#define PD_EVENT_TYPEC BIT(4)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005622
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005623struct ec_response_host_event_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005624 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005625} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005626
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005627/*
5628 * Set USB type-C port role and muxes
5629 *
5630 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5631 *
5632 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5633 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005634#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005635
5636enum usb_pd_control_role {
5637 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5638 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5639 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5640 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5641 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005642 USB_PD_CTRL_ROLE_FREEZE = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005643 USB_PD_CTRL_ROLE_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005644};
5645
5646enum usb_pd_control_mux {
5647 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5648 USB_PD_CTRL_MUX_NONE = 1,
5649 USB_PD_CTRL_MUX_USB = 2,
5650 USB_PD_CTRL_MUX_DP = 3,
5651 USB_PD_CTRL_MUX_DOCK = 4,
5652 USB_PD_CTRL_MUX_AUTO = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005653 USB_PD_CTRL_MUX_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005654};
5655
Duncan Laurieeb316852015-12-01 18:51:18 -08005656enum usb_pd_control_swap {
5657 USB_PD_CTRL_SWAP_NONE = 0,
5658 USB_PD_CTRL_SWAP_DATA = 1,
5659 USB_PD_CTRL_SWAP_POWER = 2,
5660 USB_PD_CTRL_SWAP_VCONN = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005661 USB_PD_CTRL_SWAP_COUNT,
Duncan Laurieeb316852015-12-01 18:51:18 -08005662};
5663
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005664struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005665 uint8_t port;
5666 uint8_t role;
5667 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005668 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005669} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005670
Caveh Jalali024ffe32023-01-30 14:35:19 -08005671#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5672#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005673#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005674
Caveh Jalali024ffe32023-01-30 14:35:19 -08005675#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5676#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5677#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5678#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5679#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5680#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005681/* Partner unconstrained power */
5682#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
Duncan Laurieeb316852015-12-01 18:51:18 -08005683
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005684struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005685 uint8_t enabled;
5686 uint8_t role;
5687 uint8_t polarity;
5688 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005689} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005691struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005692 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005693 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005694 uint8_t polarity;
5695 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005696} __ec_align1;
5697
Jett Rinkba2edaf2020-01-14 11:49:06 -07005698/* Possible port partner connections based on CC line states */
5699enum pd_cc_states {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005700 PD_CC_NONE = 0, /* No port partner attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005701
5702 /* From DFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005703 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
5704 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5705 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5706 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005707
5708 /* From UFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005709 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
5710 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005711};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005712
Jett Rinkba2edaf2020-01-14 11:49:06 -07005713/* Active/Passive Cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005714#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005715/* Optical/Non-optical cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005716#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005717/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005718#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005719/* Active Link Uni-Direction */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005720#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005721
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005722struct ec_response_usb_pd_control_v2 {
5723 uint8_t enabled;
5724 uint8_t role;
5725 uint8_t polarity;
5726 char state[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08005727 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5728 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
5729 uint8_t reserved; /* Reserved for future use */
5730 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5731 uint8_t cable_speed; /* TBT_SS_* cable speed */
5732 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005733} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005734
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005735#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005736
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005737/* Maximum number of PD ports on a device, num_ports will be <= this */
5738#define EC_USB_PD_MAX_PORTS 8
5739
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005740struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005741 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005742} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005743
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005744#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005745
5746#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005747struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005748 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005749} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005750
5751enum usb_chg_type {
5752 USB_CHG_TYPE_NONE,
5753 USB_CHG_TYPE_PD,
5754 USB_CHG_TYPE_C,
5755 USB_CHG_TYPE_PROPRIETARY,
5756 USB_CHG_TYPE_BC12_DCP,
5757 USB_CHG_TYPE_BC12_CDP,
5758 USB_CHG_TYPE_BC12_SDP,
5759 USB_CHG_TYPE_OTHER,
5760 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005761 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005762 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005763};
5764enum usb_power_roles {
5765 USB_PD_PORT_POWER_DISCONNECTED,
5766 USB_PD_PORT_POWER_SOURCE,
5767 USB_PD_PORT_POWER_SINK,
5768 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5769};
5770
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005771struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005772 uint16_t voltage_max;
5773 uint16_t voltage_now;
5774 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005775 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005776} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005777
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005778struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005779 uint8_t role;
5780 uint8_t type;
5781 uint8_t dualrole;
5782 uint8_t reserved1;
5783 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005784 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005785} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005786
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005787/*
5788 * This command will return the number of USB PD charge port + the number
5789 * of dedicated port present.
5790 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5791 */
5792#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005793struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005794 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005795} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005796
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08005797/*
5798 * This command enable/disable dynamic PDO selection.
5799 */
5800#define EC_CMD_USB_PD_DPS_CONTROL 0x0106
5801
5802struct ec_params_usb_pd_dps_control {
5803 uint8_t enable;
5804} __ec_align1;
5805
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005806/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005807#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005808
5809enum usb_pd_fw_update_cmds {
5810 USB_PD_FW_REBOOT,
5811 USB_PD_FW_FLASH_ERASE,
5812 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005813 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005814};
5815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005816struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005817 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005818 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005819 uint8_t port;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005820
5821 /* Size to write in bytes */
5822 uint32_t size;
5823
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005824 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005825} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005826
5827/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005828#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005829/* RW hash is first 20 bytes of SHA-256 of RW section */
5830#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005831struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005832 uint16_t dev_id;
5833 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005834
5835 /*
5836 * Reserved for alignment of current_image
5837 * TODO(rspangler) but it's not aligned!
5838 * Should have been reserved[2].
5839 */
5840 uint8_t reserved;
5841
5842 /* One of ec_image */
5843 uint32_t current_image;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005844} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005845
5846/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005847#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005848
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005849struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005850 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005851} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005852
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005853/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005854#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005855struct ec_params_usb_pd_discovery_entry {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005856 uint16_t vid; /* USB-IF VID */
5857 uint16_t pid; /* USB-IF PID */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005858 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005859} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005860
5861/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005862#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005863
5864/* Negative port parameters have special meaning */
5865enum usb_pd_override_ports {
5866 OVERRIDE_DONT_CHARGE = -2,
5867 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005868 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005869};
5870
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005871struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005872 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005873} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005874
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005875/*
5876 * Read (and delete) one entry of PD event log.
5877 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5878 * future non-PD logs that use the same internal EC event_log.
5879 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005880#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005881
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005882struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005883 uint32_t timestamp; /* relative timestamp in milliseconds */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005884 uint8_t type; /* event type : see PD_EVENT_xx below */
5885 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5886 uint16_t data; /* type-defined data payload */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005887 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005888} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005889
5890/* The timestamp is the microsecond counter shifted to get about a ms. */
5891#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5892
Caveh Jalali024ffe32023-01-30 14:35:19 -08005893#define PD_LOG_SIZE_MASK 0x1f
5894#define PD_LOG_PORT_MASK 0xe0
5895#define PD_LOG_PORT_SHIFT 5
5896#define PD_LOG_PORT_SIZE(port, size) \
5897 (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK))
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005898#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08005899#define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005900
5901/* PD event log : entry types */
5902/* PD MCU events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005903#define PD_EVENT_MCU_BASE 0x00
5904#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
5905#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005906/* Reserved for custom board event */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005907#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005908/* PD generic accessory events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005909#define PD_EVENT_ACC_BASE 0x20
5910#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
5911#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005912/* PD power supply events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005913#define PD_EVENT_PS_BASE 0x40
5914#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005915/* PD video dongles events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005916#define PD_EVENT_VIDEO_BASE 0x60
5917#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
5918#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005919/* Returned in the "type" field, when there is no entry available */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005920#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005921
5922/*
5923 * PD_EVENT_MCU_CHARGE event definition :
5924 * the payload is "struct usb_chg_measures"
5925 * the data field contains the port state flags as defined below :
5926 */
5927/* Port partner is a dual role device */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005928#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005929/* Port is the pending override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005930#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005931/* Port is the override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005932#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005933/* Charger type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005934#define CHARGE_FLAGS_TYPE_SHIFT 3
5935#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005936/* Power delivery role */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005937#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005938
5939/*
5940 * PD_EVENT_PS_FAULT data field flags definition :
5941 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005942#define PS_FAULT_OCP 1
5943#define PS_FAULT_FAST_OCP 2
5944#define PS_FAULT_OVP 3
5945#define PS_FAULT_DISCH 4
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005946
5947/*
5948 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5949 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005950struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005951 uint8_t major;
5952 uint8_t minor;
5953 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005954} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005955
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005956struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005957 uint8_t family[2];
5958 uint8_t chipid[2];
5959 struct mcdp_version irom;
5960 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005961} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005962
5963/* struct mcdp_info field decoding */
5964#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5965#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5966
5967/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005968#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005969struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005970 uint16_t svid_idx; /* SVID index to get */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005971 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005972} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005973
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005974struct ec_params_usb_pd_get_mode_response {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005975 uint16_t svid; /* SVID */
5976 uint16_t opos; /* Object Position */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005977 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005978} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005979
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005980#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005981
5982enum pd_mode_cmd {
5983 PD_EXIT_MODE = 0,
5984 PD_ENTER_MODE = 1,
5985 /* Not a command. Do NOT remove. */
5986 PD_MODE_CMD_COUNT,
5987};
5988
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005989struct ec_params_usb_pd_set_mode_request {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005990 uint32_t cmd; /* enum pd_mode_cmd */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005991 uint16_t svid; /* SVID to set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005992 uint8_t opos; /* Object Position */
5993 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005994} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005995
5996/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005997#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005998
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005999struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006000 uint8_t type; /* event type : see PD_EVENT_xx above */
6001 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006002} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006003
Gwendal Grignou880b4582016-06-20 08:49:25 -07006004/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006005#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07006006
6007enum ec_pd_control_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006008 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6009 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6010 PD_RESET, /* Force reset the PD chip */
6011 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6012 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006013};
6014
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006015struct ec_params_pd_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006016 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006017 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006018} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07006019
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006020/* Get info about USB-C SS muxes */
6021#define EC_CMD_USB_PD_MUX_INFO 0x011A
6022
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006023struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006024 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006025} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006026
6027/* Flags representing mux state */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006028#define USB_PD_MUX_NONE 0 /* Open switch */
6029#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6030#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6031#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6032#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6033#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6034#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6035#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6036#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006037#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006038#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006039
6040/* USB-C Dock connected */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006041#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006042
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006043struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006044 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006045} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006046
Caveh Jalali024ffe32023-01-30 14:35:19 -08006047#define EC_CMD_PD_CHIP_INFO 0x011B
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006048
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006049struct ec_params_pd_chip_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006050 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006051 /*
6052 * Fetch the live chip info or hard-coded + cached chip info
6053 * 0: hardcoded value for VID/PID, cached value for FW version
6054 * 1: live chip value for VID/PID/FW Version
6055 */
6056 uint8_t live;
6057} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006058
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006059struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006060 uint16_t vendor_id;
6061 uint16_t product_id;
6062 uint16_t device_id;
6063 union {
6064 uint8_t fw_version_string[8];
6065 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006066 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006067} __ec_align2;
6068
6069struct ec_response_pd_chip_info_v1 {
6070 uint16_t vendor_id;
6071 uint16_t product_id;
6072 uint16_t device_id;
6073 union {
6074 uint8_t fw_version_string[8];
6075 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006076 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006077 union {
6078 uint8_t min_req_fw_version_string[8];
6079 uint64_t min_req_fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006080 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006081} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006082
6083/* Run RW signature verification and get status */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006084#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006085
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006086struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006087 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006088} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006089
6090/* For controlling RWSIG task */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006091#define EC_CMD_RWSIG_ACTION 0x011D
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006092
6093enum rwsig_action {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006094 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6095 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006096};
6097
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006098struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006099 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006100} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006101
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006102/* Run verification on a slot */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006103#define EC_CMD_EFS_VERIFY 0x011E
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006104
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006105struct ec_params_efs_verify {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006106 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006107} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006108
6109/*
6110 * Retrieve info from Cros Board Info store. Response is based on the data
6111 * type. Integers return a uint32. Strings return a string, using the response
6112 * size to determine how big it is.
6113 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006114#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006115/*
6116 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6117 * hardware write-protect enabled.
6118 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006119#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006120
Daisuke Nojirif984a052018-02-15 12:38:15 -08006121enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006122 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006123 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6124 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06006125 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006126 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6127 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6128 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6129 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08006130 /* Second Source Factory Cache */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006131 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6132 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006133 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006134 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006135};
6136
6137/*
6138 * Flags to control read operation
6139 *
6140 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6141 * write was successful without reboot.
6142 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006143#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006144
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006145struct ec_params_get_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006146 uint32_t tag; /* enum cbi_data_tag */
6147 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006148} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006149
6150/*
6151 * Flags to control write behavior.
6152 *
6153 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6154 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006155 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006156 * will be initialized to zero first.
6157 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006158#define CBI_SET_NO_SYNC BIT(0)
6159#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006160
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006161struct ec_params_set_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006162 uint32_t tag; /* enum cbi_data_tag */
6163 uint32_t flag; /* CBI_SET_* */
6164 uint32_t size; /* Data size */
6165 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006166} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006167
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006168/*
6169 * Information about resets of the AP by the EC and the EC's own uptime.
6170 */
6171#define EC_CMD_GET_UPTIME_INFO 0x0121
6172
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006173/* EC reset causes */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006174#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6175#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6176#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6177#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6178#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6179#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6180#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6181#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6182#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6183#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6184#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6185#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6186#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006187/* Some reset flags preserved from previous boot */
6188#define EC_RESET_FLAG_PRESERVED BIT(13)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006189#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6190#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6191#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6192#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006193/* AP experienced a watchdog reset */
6194#define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6195/* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6196#define EC_RESET_FLAG_STAY_IN_RO BIT(19)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006197#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6198#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6199#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006200
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006201/*
6202 * Reason codes used by the AP after a shutdown to figure out why it was reset
6203 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6204 * compatibility:
6205 * - New entries must be inserted prior to the _COUNT field
6206 * - If an existing entry is no longer in service, it must be replaced with a
6207 * RESERVED entry instead.
6208 * - The semantic meaning of an entry should not change.
6209 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6210 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006211enum chipset_shutdown_reason {
6212 /*
6213 * Beginning of reset reasons.
6214 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006215 CHIPSET_RESET_BEGIN = 0,
6216 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6217 /* Custom reason defined by a board.c or baseboard.c file */
6218 CHIPSET_RESET_BOARD_CUSTOM,
6219 /* Believe that the AP has hung */
6220 CHIPSET_RESET_HANG_REBOOT,
6221 /* Reset by EC console command */
6222 CHIPSET_RESET_CONSOLE_CMD,
6223 /* Reset by EC host command */
6224 CHIPSET_RESET_HOST_CMD,
6225 /* Keyboard module reset key combination */
6226 CHIPSET_RESET_KB_SYSRESET,
6227 /* Keyboard module warm reboot */
6228 CHIPSET_RESET_KB_WARM_REBOOT,
6229 /* Debug module warm reboot */
6230 CHIPSET_RESET_DBG_WARM_REBOOT,
6231 /* I cannot self-terminate. You must lower me into the steel. */
6232 CHIPSET_RESET_AP_REQ,
6233 /* Reset as side-effect of startup sequence */
6234 CHIPSET_RESET_INIT,
6235 /* EC detected an AP watchdog event. */
6236 CHIPSET_RESET_AP_WATCHDOG,
6237
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006238 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006239
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006240 /*
6241 * Beginning of shutdown reasons.
6242 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006243 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6244 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6245 /* Forcing a shutdown as part of EC initialization */
6246 CHIPSET_SHUTDOWN_INIT,
6247 /* Custom reason on a per-board basis. */
6248 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6249 /* This is a reason to inhibit startup, not cause shut down. */
6250 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6251 /* A power_wait_signal is being asserted */
6252 CHIPSET_SHUTDOWN_WAIT,
6253 /* Critical battery level. */
6254 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6255 /* Because you told me to. */
6256 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6257 /* Forcing a shutdown to effect entry to G3. */
6258 CHIPSET_SHUTDOWN_G3,
6259 /* Force shutdown due to over-temperature. */
6260 CHIPSET_SHUTDOWN_THERMAL,
6261 /* Force a chipset shutdown from the power button through EC */
6262 CHIPSET_SHUTDOWN_BUTTON,
6263
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006264 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006265};
6266
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006267struct ec_response_uptime_info {
6268 /*
6269 * Number of milliseconds since the last EC boot. Sysjump resets
6270 * typically do not restart the EC's time_since_boot epoch.
6271 *
6272 * WARNING: The EC's sense of time is much less accurate than the AP's
6273 * sense of time, in both phase and frequency. This timebase is similar
6274 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6275 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006276 uint32_t time_since_ec_boot_ms;
6277
6278 /*
6279 * Number of times the AP was reset by the EC since the last EC boot.
6280 * Note that the AP may be held in reset by the EC during the initial
6281 * boot sequence, such that the very first AP boot may count as more
6282 * than one here.
6283 */
6284 uint32_t ap_resets_since_ec_boot;
6285
6286 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006287 * The set of flags which describe the EC's most recent reset.
6288 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006289 */
6290 uint32_t ec_reset_flags;
6291
6292 /* Empty log entries have both the cause and timestamp set to zero. */
6293 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006294 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006295 uint16_t reset_cause;
6296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006297 /* Reserved for protocol growth. */
6298 uint16_t reserved;
6299
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006300 /*
6301 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006302 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6303 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006304 */
6305 uint32_t reset_time_ms;
6306 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006307} __ec_align4;
6308
6309/*
6310 * Add entropy to the device secret (stored in the rollback region).
6311 *
6312 * Depending on the chip, the operation may take a long time (e.g. to erase
6313 * flash), so the commands are asynchronous.
6314 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006315#define EC_CMD_ADD_ENTROPY 0x0122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006316
6317enum add_entropy_action {
6318 /* Add entropy to the current secret. */
6319 ADD_ENTROPY_ASYNC = 0,
6320 /*
6321 * Add entropy, and also make sure that the previous secret is erased.
6322 * (this can be implemented by adding entropy multiple times until
6323 * all rolback blocks have been overwritten).
6324 */
6325 ADD_ENTROPY_RESET_ASYNC = 1,
6326 /* Read back result from the previous operation. */
6327 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006328};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006329
6330struct ec_params_rollback_add_entropy {
6331 uint8_t action;
6332} __ec_align1;
6333
6334/*
6335 * Perform a single read of a given ADC channel.
6336 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006337#define EC_CMD_ADC_READ 0x0123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006338
6339struct ec_params_adc_read {
6340 uint8_t adc_channel;
6341} __ec_align1;
6342
6343struct ec_response_adc_read {
6344 int32_t adc_value;
6345} __ec_align4;
6346
6347/*
6348 * Read back rollback info
6349 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006350#define EC_CMD_ROLLBACK_INFO 0x0124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006351
6352struct ec_response_rollback_info {
6353 int32_t id; /* Incrementing number to indicate which region to use. */
6354 int32_t rollback_min_version;
6355 int32_t rw_rollback_version;
6356} __ec_align4;
6357
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006358/* Issue AP reset */
6359#define EC_CMD_AP_RESET 0x0125
6360
6361/*****************************************************************************/
6362/* Locate peripheral chips
6363 *
6364 * Return values:
6365 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6366 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6367 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6368 */
6369#define EC_CMD_LOCATE_CHIP 0x0126
6370
6371enum ec_chip_type {
6372 EC_CHIP_TYPE_CBI_EEPROM = 0,
6373 EC_CHIP_TYPE_TCPC = 1,
6374 EC_CHIP_TYPE_COUNT,
6375 EC_CHIP_TYPE_MAX = 0xFF,
6376};
6377
6378enum ec_bus_type {
6379 EC_BUS_TYPE_I2C = 0,
6380 EC_BUS_TYPE_EMBEDDED = 1,
6381 EC_BUS_TYPE_COUNT,
6382 EC_BUS_TYPE_MAX = 0xFF,
6383};
6384
6385struct ec_i2c_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006386 uint16_t port; /* Physical port for device */
6387 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006388};
6389
6390struct ec_params_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006391 uint8_t type; /* enum ec_chip_type */
6392 uint8_t index; /* Specifies one instance of chip type */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006393 /* Used for type specific parameters in future */
6394 union {
6395 uint16_t reserved;
6396 };
6397} __ec_align2;
6398
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006399struct ec_response_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006400 uint8_t bus_type; /* enum ec_bus_type */
6401 uint8_t reserved; /* Aligning the following union to 2 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006402 union {
6403 struct ec_i2c_info i2c_info;
6404 };
6405} __ec_align2;
6406
Jett Rinkba2edaf2020-01-14 11:49:06 -07006407/*
6408 * Reboot AP on G3
6409 *
6410 * This command is used for validation purpose, where the AP needs to be
6411 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006412 * wake events.
6413 * - With command version 0:
6414 * AP reboots immediately from G3
6415 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6416 * - With command version 1:
6417 * AP reboots after the user specified delay
6418 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006419 */
6420#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6421
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006422struct ec_params_reboot_ap_on_g3_v1 {
6423 /* configurable delay in seconds in G3 state */
6424 uint32_t reboot_ap_at_g3_delay;
6425} __ec_align4;
6426
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006427/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006428/* Get PD port capabilities
6429 *
6430 * Returns the following static *capabilities* of the given port:
6431 * 1) Power role: source, sink, or dual. It is not anticipated that
6432 * future CrOS devices would ever be only a source, so the options are
6433 * sink or dual.
6434 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6435 * believe any CrOS device would support Try.SNK, so this would be source
6436 * or none).
6437 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6438 * for CrOS devices.
6439 */
6440#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6441
6442enum ec_pd_power_role_caps {
6443 EC_PD_POWER_ROLE_SOURCE = 0,
6444 EC_PD_POWER_ROLE_SINK = 1,
6445 EC_PD_POWER_ROLE_DUAL = 2,
6446};
6447
6448enum ec_pd_try_power_role_caps {
6449 EC_PD_TRY_POWER_ROLE_NONE = 0,
6450 EC_PD_TRY_POWER_ROLE_SINK = 1,
6451 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6452};
6453
6454enum ec_pd_data_role_caps {
6455 EC_PD_DATA_ROLE_DFP = 0,
6456 EC_PD_DATA_ROLE_UFP = 1,
6457 EC_PD_DATA_ROLE_DUAL = 2,
6458};
6459
6460/* From: power_manager/power_supply_properties.proto */
6461enum ec_pd_port_location {
6462 /* The location of the port is unknown, or there's only one port. */
6463 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6464
6465 /*
6466 * Various positions on the device. The first word describes the side of
6467 * the device where the port is located while the second clarifies the
6468 * position. For example, LEFT_BACK means the farthest-back port on the
6469 * left side, while BACK_LEFT means the leftmost port on the back of the
6470 * device.
6471 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006472 EC_PD_PORT_LOCATION_LEFT = 1,
6473 EC_PD_PORT_LOCATION_RIGHT = 2,
6474 EC_PD_PORT_LOCATION_BACK = 3,
6475 EC_PD_PORT_LOCATION_FRONT = 4,
6476 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6477 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006478 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006479 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6480 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6481 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006482};
6483
6484struct ec_params_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006485 uint8_t port; /* Which port to interrogate */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006486} __ec_align1;
6487
6488struct ec_response_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006489 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6490 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6491 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6492 uint8_t pd_port_location; /* enum ec_pd_port_location */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006493} __ec_align1;
6494
6495/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006496/*
6497 * Button press simulation
6498 *
6499 * This command is used to simulate a button press.
6500 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6501 * Time duration for which button needs to be pressed is an optional parameter.
6502 *
6503 * NOTE: This is only available on unlocked devices for testing purposes only.
6504 */
6505#define EC_CMD_BUTTON 0x0129
6506
6507struct ec_params_button {
6508 /* Button mask aligned to enum keyboard_button_type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006509 uint32_t btn_mask;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006510
6511 /* Duration in milliseconds button needs to be pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006512 uint32_t press_ms;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006513} __ec_align1;
6514
6515enum keyboard_button_type {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006516 KEYBOARD_BUTTON_POWER = 0,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006517 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006518 KEYBOARD_BUTTON_VOLUME_UP = 2,
6519 KEYBOARD_BUTTON_RECOVERY = 3,
6520 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6521 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6522 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6523 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6524 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6525 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6526 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6527 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006528
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006529 KEYBOARD_BUTTON_COUNT,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006530};
Yidi Lin42f79592020-09-21 18:04:10 +08006531
Rajat Jainc0495722020-04-02 23:58:35 -07006532/*****************************************************************************/
6533/*
6534 * "Get the Keyboard Config". An EC implementing this command is expected to be
6535 * vivaldi capable, i.e. can send action codes for the top row keys.
6536 * Additionally, capability to send function codes for the same keys is
6537 * optional and acceptable.
6538 *
6539 * Note: If the top row can generate both function and action codes by
6540 * using a dedicated Fn key, it does not matter whether the key sends
6541 * "function" or "action" codes by default. In both cases, the response
6542 * for this command will look the same.
6543 */
6544#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6545
6546/* Possible values for the top row keys */
6547enum action_key {
6548 TK_ABSENT = 0,
6549 TK_BACK = 1,
6550 TK_FORWARD = 2,
6551 TK_REFRESH = 3,
6552 TK_FULLSCREEN = 4,
6553 TK_OVERVIEW = 5,
6554 TK_BRIGHTNESS_DOWN = 6,
6555 TK_BRIGHTNESS_UP = 7,
6556 TK_VOL_MUTE = 8,
6557 TK_VOL_DOWN = 9,
6558 TK_VOL_UP = 10,
6559 TK_SNAPSHOT = 11,
6560 TK_PRIVACY_SCRN_TOGGLE = 12,
6561 TK_KBD_BKLIGHT_DOWN = 13,
6562 TK_KBD_BKLIGHT_UP = 14,
6563 TK_PLAY_PAUSE = 15,
6564 TK_NEXT_TRACK = 16,
6565 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006566 TK_KBD_BKLIGHT_TOGGLE = 18,
6567 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006568 TK_MENU = 20,
Rajat Jainc0495722020-04-02 23:58:35 -07006569};
6570
6571/*
6572 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6573 * If this needs to change, please create a new version of the command.
6574 */
6575#define MAX_TOP_ROW_KEYS 15
6576#define MIN_TOP_ROW_KEYS 10
6577
6578/*
6579 * Is the keyboard capable of sending function keys *in addition to*
6580 * action keys. This is possible for e.g. if the keyboard has a
6581 * dedicated Fn key.
6582 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006583#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
Rajat Jainc0495722020-04-02 23:58:35 -07006584/*
6585 * Whether the keyboard has a dedicated numeric keyboard.
6586 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006587#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
Rajat Jainc0495722020-04-02 23:58:35 -07006588/*
6589 * Whether the keyboard has a screenlock key.
6590 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006591#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
Rajat Jainc0495722020-04-02 23:58:35 -07006592
6593struct ec_response_keybd_config {
6594 /*
6595 * Number of top row keys, excluding Esc and Screenlock.
6596 * If this is 0, all Vivaldi keyboard code is disabled.
6597 * (i.e. does not expose any tables to the kernel).
6598 */
6599 uint8_t num_top_row_keys;
6600
6601 /*
6602 * The action keys in the top row, in order from left to right.
6603 * The values are filled from enum action_key. Esc and Screenlock
6604 * keys are not considered part of top row keys.
6605 */
6606 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6607
6608 /* Capability flags */
6609 uint8_t capabilities;
6610
6611} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006612
Yidi Lin42f79592020-09-21 18:04:10 +08006613/*
6614 * Configure smart discharge
6615 */
6616#define EC_CMD_SMART_DISCHARGE 0x012B
6617
Caveh Jalali024ffe32023-01-30 14:35:19 -08006618#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
Yidi Lin42f79592020-09-21 18:04:10 +08006619
6620/* Discharge rates when the system is in cutoff or hibernation. */
6621struct discharge_rate {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006622 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6623 uint16_t hibern; /* Discharge rate (uA) in hibernation */
Yidi Lin42f79592020-09-21 18:04:10 +08006624};
6625
6626struct smart_discharge_zone {
6627 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6628 int cutoff;
6629 /* When the capacity (mAh) is below this, EC stays up. */
6630 int stayup;
6631};
6632
6633struct ec_params_smart_discharge {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006634 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
Yidi Lin42f79592020-09-21 18:04:10 +08006635 /*
6636 * Desired hours for the battery to survive before reaching 0%. Set to
6637 * zero to disable smart discharging. That is, the system hibernates as
6638 * soon as the G3 idle timer expires.
6639 */
6640 uint16_t hours_to_zero;
6641 /* Set both to zero to keep the current rates. */
6642 struct discharge_rate drate;
6643};
6644
6645struct ec_response_smart_discharge {
6646 uint16_t hours_to_zero;
6647 struct discharge_rate drate;
6648 struct smart_discharge_zone dzone;
6649};
6650
6651/*****************************************************************************/
6652/* Voltage regulator controls */
6653
6654/*
6655 * Get basic info of voltage regulator for given index.
6656 *
6657 * Returns the regulator name and supported voltage list in mV.
6658 */
6659#define EC_CMD_REGULATOR_GET_INFO 0x012C
6660
6661/* Maximum length of regulator name */
6662#define EC_REGULATOR_NAME_MAX_LEN 16
6663
6664/* Maximum length of the supported voltage list. */
6665#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6666
6667struct ec_params_regulator_get_info {
6668 uint32_t index;
6669} __ec_align4;
6670
6671struct ec_response_regulator_get_info {
6672 char name[EC_REGULATOR_NAME_MAX_LEN];
6673 uint16_t num_voltages;
6674 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6675} __ec_align2;
6676
6677/*
6678 * Configure the regulator as enabled / disabled.
6679 */
6680#define EC_CMD_REGULATOR_ENABLE 0x012D
6681
6682struct ec_params_regulator_enable {
6683 uint32_t index;
6684 uint8_t enable;
6685} __ec_align4;
6686
6687/*
6688 * Query if the regulator is enabled.
6689 *
6690 * Returns 1 if the regulator is enabled, 0 if not.
6691 */
6692#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6693
6694struct ec_params_regulator_is_enabled {
6695 uint32_t index;
6696} __ec_align4;
6697
6698struct ec_response_regulator_is_enabled {
6699 uint8_t enabled;
6700} __ec_align1;
6701
6702/*
6703 * Set voltage for the voltage regulator within the range specified.
6704 *
6705 * The driver should select the voltage in range closest to min_mv.
6706 *
6707 * Also note that this might be called before the regulator is enabled, and the
6708 * setting should be in effect after the regulator is enabled.
6709 */
6710#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6711
6712struct ec_params_regulator_set_voltage {
6713 uint32_t index;
6714 uint32_t min_mv;
6715 uint32_t max_mv;
6716} __ec_align4;
6717
6718/*
6719 * Get the currently configured voltage for the voltage regulator.
6720 *
6721 * Note that this might be called before the regulator is enabled, and this
6722 * should return the configured output voltage if the regulator is enabled.
6723 */
6724#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6725
6726struct ec_params_regulator_get_voltage {
6727 uint32_t index;
6728} __ec_align4;
6729
6730struct ec_response_regulator_get_voltage {
6731 uint32_t voltage_mv;
6732} __ec_align4;
6733
6734/*
6735 * Gather all discovery information for the given port and partner type.
6736 *
6737 * Note that if discovery has not yet completed, only the currently completed
6738 * responses will be filled in. If the discovery data structures are changed
6739 * in the process of the command running, BUSY will be returned.
6740 *
6741 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6742 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6743 * maximum parameter size.
6744 */
6745#define EC_CMD_TYPEC_DISCOVERY 0x0131
6746
6747enum typec_partner_type {
6748 TYPEC_PARTNER_SOP = 0,
6749 TYPEC_PARTNER_SOP_PRIME = 1,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006750 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
Yidi Lin42f79592020-09-21 18:04:10 +08006751};
6752
6753struct ec_params_typec_discovery {
6754 uint8_t port;
6755 uint8_t partner_type; /* enum typec_partner_type */
6756} __ec_align1;
6757
6758struct svid_mode_info {
6759 uint16_t svid;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006760 uint16_t mode_count; /* Number of modes partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08006761 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6762};
6763
6764struct ec_response_typec_discovery {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006765 uint8_t identity_count; /* Number of identity VDOs partner sent */
6766 uint8_t svid_count; /* Number of SVIDs partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08006767 uint16_t reserved;
6768 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6769 struct svid_mode_info svids[0];
6770} __ec_align1;
6771
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006772/* USB Type-C commands for AP-controlled device policy. */
6773#define EC_CMD_TYPEC_CONTROL 0x0132
6774
6775enum typec_control_command {
6776 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6777 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006778 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006779 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006780 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006781 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
6782 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006783};
6784
6785/* Modes (USB or alternate) that a type-C port may enter. */
6786enum typec_mode {
6787 TYPEC_MODE_DP,
6788 TYPEC_MODE_TBT,
6789 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006790};
6791
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006792/* Replies the AP may specify to the TBT EnterMode command as a UFP */
6793enum typec_tbt_ufp_reply {
6794 TYPEC_TBT_UFP_REPLY_NAK,
6795 TYPEC_TBT_UFP_REPLY_ACK,
6796};
6797
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006798#define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
6799
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006800struct typec_usb_mux_set {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006801 /* Index of the mux to set in the chain */
6802 uint8_t mux_index;
6803
6804 /* USB_PD_MUX_*-encoded USB mux state to set */
6805 uint8_t mux_flags;
6806} __ec_align1;
6807
6808#define VDO_MAX_SIZE 7
6809
6810struct typec_vdm_req {
6811 /* VDM data, including VDM header */
6812 uint32_t vdm_data[VDO_MAX_SIZE];
6813 /* Number of 32-bit fields filled in */
6814 uint8_t vdm_data_objects;
6815 /* Partner to address - see enum typec_partner_type */
6816 uint8_t partner_type;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006817} __ec_align1;
6818
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006819struct ec_params_typec_control {
6820 uint8_t port;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006821 uint8_t command; /* enum typec_control_command */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006822 uint16_t reserved;
6823
6824 /*
6825 * This section will be interpreted based on |command|. Define a
6826 * placeholder structure to avoid having to increase the size and bump
6827 * the command version when adding new sub-commands.
6828 */
6829 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006830 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006831 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006832 /* Used for ENTER_MODE - enum typec_mode */
6833 uint8_t mode_to_enter;
6834 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
6835 uint8_t tbt_ufp_reply;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006836 /* Used for USB_MUX_SET */
6837 struct typec_usb_mux_set mux_params;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006838 /* Used for BIST_SHARE_MODE */
6839 uint8_t bist_share_mode;
6840 /* Used for VMD_REQ */
6841 struct typec_vdm_req vdm_req_params;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006842 uint8_t placeholder[128];
6843 };
6844} __ec_align1;
6845
6846/*
6847 * Gather all status information for a port.
6848 *
6849 * Note: this covers many of the return fields from the deprecated
6850 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6851 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6852 * EC_CMD_USB_PD_CONTROL command.
6853 *
6854 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006855 */
6856#define EC_CMD_TYPEC_STATUS 0x0133
6857
6858/*
6859 * Power role.
6860 *
6861 * Note this is also used for PD header creation, and values align to those in
6862 * the Power Delivery Specification Revision 3.0 (See
6863 * 6.2.1.1.4 Port Power Role).
6864 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006865enum pd_power_role {
6866 PD_ROLE_SINK = 0,
6867 PD_ROLE_SOURCE = 1,
6868};
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006869
6870/*
6871 * Data role.
6872 *
6873 * Note this is also used for PD header creation, and the first two values
6874 * align to those in the Power Delivery Specification Revision 3.0 (See
6875 * 6.2.1.1.6 Port Data Role).
6876 */
6877enum pd_data_role {
6878 PD_ROLE_UFP = 0,
6879 PD_ROLE_DFP = 1,
6880 PD_ROLE_DISCONNECTED = 2,
6881};
6882
6883enum pd_vconn_role {
6884 PD_ROLE_VCONN_OFF = 0,
6885 PD_ROLE_VCONN_SRC = 1,
6886};
6887
6888/*
6889 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6890 * regardless of whether a debug accessory is connected.
6891 */
6892enum tcpc_cc_polarity {
6893 /*
6894 * _CCx: is used to indicate the polarity while not connected to
6895 * a Debug Accessory. Only one CC line will assert a resistor and
6896 * the other will be open.
6897 */
6898 POLARITY_CC1 = 0,
6899 POLARITY_CC2 = 1,
6900
6901 /*
6902 * _CCx_DTS is used to indicate the polarity while connected to a
6903 * SRC Debug Accessory. Assert resistors on both lines.
6904 */
6905 POLARITY_CC1_DTS = 2,
6906 POLARITY_CC2_DTS = 3,
6907
6908 /*
6909 * The current TCPC code relies on these specific POLARITY values.
6910 * Adding in a check to verify if the list grows for any reason
6911 * that this will give a hint that other places need to be
6912 * adjusted.
6913 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006914 POLARITY_COUNT,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006915};
6916
Caveh Jalali024ffe32023-01-30 14:35:19 -08006917#define MODE_DP_PIN_A BIT(0)
6918#define MODE_DP_PIN_B BIT(1)
6919#define MODE_DP_PIN_C BIT(2)
6920#define MODE_DP_PIN_D BIT(3)
6921#define MODE_DP_PIN_E BIT(4)
6922#define MODE_DP_PIN_F BIT(5)
6923#define MODE_DP_PIN_ALL GENMASK(5, 0)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006924
Caveh Jalali024ffe32023-01-30 14:35:19 -08006925#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6926#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
6927#define PD_STATUS_EVENT_HARD_RESET BIT(2)
6928#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
6929#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
6930#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006931#define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
6932#define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
6933#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006934
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006935/*
6936 * Encode and decode for BCD revision response
6937 *
6938 * Note: the major revision set is written assuming that the value given is the
6939 * Specification Revision from the PD header, which currently only maps to PD
6940 * 1.0-3.0 with the major revision being one greater than the binary value.
6941 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006942#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6943#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6944#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006945
6946/*
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006947 * Encode revision from partner RMDO
6948 *
6949 * Unlike the specification revision given in the PD header, specification and
6950 * version information returned in the revision message data object (RMDO) is
6951 * not offset.
6952 */
6953#define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
6954#define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
6955#define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
6956#define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
6957
6958/*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006959 * Decode helpers for Source and Sink Capability PDOs
6960 *
6961 * Note: The Power Delivery Specification should be considered the ultimate
6962 * source of truth on the decoding of these PDOs
6963 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006964#define PDO_TYPE_FIXED (0 << 30)
6965#define PDO_TYPE_BATTERY (1 << 30)
6966#define PDO_TYPE_VARIABLE (2 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006967#define PDO_TYPE_AUGMENTED (3 << 30)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006968#define PDO_TYPE_MASK (3 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006969
6970/*
6971 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6972 *
6973 * <31:30> : Fixed Supply
6974 * <29> : Dual-Role Power
6975 * <28> : SNK/SRC dependent
6976 * <27> : Unconstrained Power
6977 * <26> : USB Communications Capable
6978 * <25> : Dual-Role Data
6979 * <24:20> : SNK/SRC dependent
6980 * <19:10> : Voltage in 50mV Units
6981 * <9:0> : Maximum Current in 10mA units
6982 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006983#define PDO_FIXED_DUAL_ROLE BIT(29)
6984#define PDO_FIXED_UNCONSTRAINED BIT(27)
6985#define PDO_FIXED_COMM_CAP BIT(26)
6986#define PDO_FIXED_DATA_SWAP BIT(25)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006987#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006988#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6989#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006990
6991/*
6992 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
6993 *
6994 * <31:30> : Battery
6995 * <29:20> : Maximum Voltage in 50mV units
6996 * <19:10> : Minimum Voltage in 50mV units
6997 * <9:0> : Maximum Allowable Power in 250mW units
6998 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006999#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7000#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7001#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007002
7003/*
7004 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7005 *
7006 * <31:30> : Variable Supply (non-Battery)
7007 * <29:20> : Maximum Voltage in 50mV units
7008 * <19:10> : Minimum Voltage in 50mV units
7009 * <9:0> : Operational Current in 10mA units
7010 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007011#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7012#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7013#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007014
7015/*
7016 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7017 *
7018 * Note this type is reserved in PD 2.0, and only one type of APDO is
7019 * supported as of the cited version.
7020 *
7021 * <31:30> : Augmented Power Data Object
7022 * <29:28> : Programmable Power Supply
7023 * <27> : PPS Power Limited
7024 * <26:25> : Reserved
7025 * <24:17> : Maximum Voltage in 100mV increments
7026 * <16> : Reserved
7027 * <15:8> : Minimum Voltage in 100mV increments
7028 * <7> : Reserved
7029 * <6:0> : Maximum Current in 50mA increments
7030 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007031#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7032#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7033#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007034
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007035struct ec_params_typec_status {
7036 uint8_t port;
7037} __ec_align1;
7038
7039struct ec_response_typec_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007040 uint8_t pd_enabled; /* PD communication enabled - bool */
7041 uint8_t dev_connected; /* Device connected - bool */
7042 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7043 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007044
Caveh Jalali024ffe32023-01-30 14:35:19 -08007045 uint8_t power_role; /* enum pd_power_role */
7046 uint8_t data_role; /* enum pd_data_role */
7047 uint8_t vconn_role; /* enum pd_vconn_role */
7048 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007049
Caveh Jalali024ffe32023-01-30 14:35:19 -08007050 uint8_t polarity; /* enum tcpc_cc_polarity */
7051 uint8_t cc_state; /* enum pd_cc_states */
7052 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7053 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007054
Caveh Jalali024ffe32023-01-30 14:35:19 -08007055 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007056
Caveh Jalali024ffe32023-01-30 14:35:19 -08007057 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007058
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007059 /*
7060 * BCD PD revisions for partners
7061 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007062 * The format has the PD major revision in the upper nibble, and the PD
7063 * minor revision in the next nibble. The following two nibbles hold the
7064 * major and minor specification version. If a partner does not support
7065 * the Revision message, only the major revision will be given.
7066 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007067 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007068 * PD revision/version will be 0 if no PD device is connected.
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007069 */
7070 uint16_t sop_revision;
7071 uint16_t sop_prime_revision;
7072
Caveh Jalali024ffe32023-01-30 14:35:19 -08007073 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007074
Caveh Jalali024ffe32023-01-30 14:35:19 -08007075 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007076} __ec_align1;
7077
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007078/**
7079 * Get the number of peripheral charge ports
7080 */
7081#define EC_CMD_PCHG_COUNT 0x0134
7082
7083#define EC_PCHG_MAX_PORTS 8
7084
7085struct ec_response_pchg_count {
7086 uint8_t port_count;
7087} __ec_align1;
7088
7089/**
7090 * Get the status of a peripheral charge port
7091 */
7092#define EC_CMD_PCHG 0x0135
7093
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007094/* For v1 and v2 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007095struct ec_params_pchg {
7096 uint8_t port;
7097} __ec_align1;
7098
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007099struct ec_params_pchg_v3 {
7100 uint8_t port;
7101 /* Below are new in v3. */
7102 uint8_t reserved1;
7103 uint8_t reserved2;
7104 uint8_t reserved3;
7105 /* Errors acked by the host (thus to be cleared) */
7106 uint32_t error;
7107} __ec_align1;
7108
7109/* For v1 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007110struct ec_response_pchg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007111 uint32_t error; /* enum pchg_error */
7112 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007113 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007114 uint8_t unused0;
7115 uint8_t unused1;
7116 /* Fields added in version 1 */
7117 uint32_t fw_version;
7118 uint32_t dropped_event_count;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007119} __ec_align4;
7120
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007121/* For v2 and v3 */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007122struct ec_response_pchg_v2 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007123 uint32_t error; /* enum pchg_error */
7124 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007125 uint8_t battery_percentage;
7126 uint8_t unused0;
7127 uint8_t unused1;
7128 /* Fields added in version 1 */
7129 uint32_t fw_version;
7130 uint32_t dropped_event_count;
7131 /* Fields added in version 2 */
7132 uint32_t dropped_host_event_count;
7133} __ec_align4;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007134
7135enum pchg_state {
7136 /* Charger is reset and not initialized. */
7137 PCHG_STATE_RESET = 0,
7138 /* Charger is initialized or disabled. */
7139 PCHG_STATE_INITIALIZED,
7140 /* Charger is enabled and ready to detect a device. */
7141 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007142 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007143 PCHG_STATE_DETECTED,
7144 /* Device is being charged. */
7145 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007146 /* Device is fully charged. It implies DETECTED (& not charging). */
7147 PCHG_STATE_FULL,
7148 /* In download (a.k.a. firmware update) mode */
7149 PCHG_STATE_DOWNLOAD,
7150 /* In download mode. Ready for receiving data. */
7151 PCHG_STATE_DOWNLOADING,
7152 /* Device is ready for data communication. */
7153 PCHG_STATE_CONNECTED,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007154 /* Charger is in Built-In Self Test mode. */
7155 PCHG_STATE_BIST,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007156 /* Put no more entry below */
7157 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007158};
7159
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007160/* clang-format off */
7161#define EC_PCHG_STATE_TEXT \
7162 { \
7163 [PCHG_STATE_RESET] = "RESET", \
7164 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7165 [PCHG_STATE_ENABLED] = "ENABLED", \
7166 [PCHG_STATE_DETECTED] = "DETECTED", \
7167 [PCHG_STATE_CHARGING] = "CHARGING", \
7168 [PCHG_STATE_FULL] = "FULL", \
7169 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7170 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7171 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7172 [PCHG_STATE_BIST] = "BIST", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007173 }
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007174/* clang-format on */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007175
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007176/**
7177 * Update firmware of peripheral chip
7178 */
7179#define EC_CMD_PCHG_UPDATE 0x0136
7180
7181/* Port number is encoded in bit[28:31]. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007182#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007183/* Utility macros for converting MKBP event <-> port number. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007184#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7185#define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007186/* Utility macro for extracting event bits. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007187#define EC_MKBP_PCHG_EVENT_MASK(e) ((e)&GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007188
Caveh Jalali024ffe32023-01-30 14:35:19 -08007189#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7190#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7191#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7192#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7193#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007194
7195enum ec_pchg_update_cmd {
7196 /* Reset chip to normal mode. */
7197 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7198 /* Reset and put a chip in update (a.k.a. download) mode. */
7199 EC_PCHG_UPDATE_CMD_OPEN,
7200 /* Write a block of data containing FW image. */
7201 EC_PCHG_UPDATE_CMD_WRITE,
7202 /* Close update session. */
7203 EC_PCHG_UPDATE_CMD_CLOSE,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007204 /* Reset chip (without mode change). */
7205 EC_PCHG_UPDATE_CMD_RESET,
7206 /* Enable pass-through mode. */
7207 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007208 /* End of commands */
7209 EC_PCHG_UPDATE_CMD_COUNT,
7210};
7211
7212struct ec_params_pchg_update {
7213 /* PCHG port number */
7214 uint8_t port;
7215 /* enum ec_pchg_update_cmd */
7216 uint8_t cmd;
7217 /* Padding */
7218 uint8_t reserved0;
7219 uint8_t reserved1;
7220 /* Version of new firmware */
7221 uint32_t version;
7222 /* CRC32 of new firmware */
7223 uint32_t crc32;
7224 /* Address in chip memory where <data> is written to */
7225 uint32_t addr;
7226 /* Size of <data> */
7227 uint32_t size;
7228 /* Partial data of new firmware */
7229 uint8_t data[];
7230} __ec_align4;
7231
Caveh Jalali024ffe32023-01-30 14:35:19 -08007232BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7233 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007234
7235struct ec_response_pchg_update {
7236 /* Block size */
7237 uint32_t block_size;
7238} __ec_align4;
7239
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007240#define EC_CMD_DISPLAY_SOC 0x0137
7241
7242struct ec_response_display_soc {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007243 /* Display charge in 10ths of a % (1000=100.0%) */
7244 int16_t display_soc;
7245 /* Full factor in 10ths of a % (1000=100.0%) */
7246 int16_t full_factor;
7247 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7248 int16_t shutdown_soc;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007249} __ec_align2;
7250
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007251#define EC_CMD_SET_BASE_STATE 0x0138
7252
7253struct ec_params_set_base_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007254 uint8_t cmd; /* enum ec_set_base_state_cmd */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007255} __ec_align1;
7256
7257enum ec_set_base_state_cmd {
7258 EC_SET_BASE_STATE_DETACH = 0,
7259 EC_SET_BASE_STATE_ATTACH,
7260 EC_SET_BASE_STATE_RESET,
7261};
7262
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007263#define EC_CMD_I2C_CONTROL 0x0139
7264
7265/* Subcommands for I2C control */
7266
7267enum ec_i2c_control_command {
7268 EC_I2C_CONTROL_GET_SPEED,
7269 EC_I2C_CONTROL_SET_SPEED,
7270};
7271
7272#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7273
7274struct ec_params_i2c_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007275 uint8_t port; /* I2C port number */
7276 uint8_t cmd; /* enum ec_i2c_control_command */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007277 union {
7278 uint16_t speed_khz;
7279 } cmd_params;
7280} __ec_align_size1;
7281
7282struct ec_response_i2c_control {
7283 union {
7284 uint16_t speed_khz;
7285 } cmd_response;
7286} __ec_align_size1;
7287
Caveh Jalali024ffe32023-01-30 14:35:19 -08007288#define EC_CMD_RGBKBD_SET_COLOR 0x013A
7289#define EC_CMD_RGBKBD 0x013B
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007290
Caveh Jalali024ffe32023-01-30 14:35:19 -08007291#define EC_RGBKBD_MAX_KEY_COUNT 128
7292#define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7293#define EC_RGBKBD_MAX_SCALE 0xFF
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007294
7295enum rgbkbd_state {
7296 /* RGB keyboard is reset and not initialized. */
7297 RGBKBD_STATE_RESET = 0,
7298 /* RGB keyboard is initialized but not enabled. */
7299 RGBKBD_STATE_INITIALIZED,
7300 /* RGB keyboard is disabled. */
7301 RGBKBD_STATE_DISABLED,
7302 /* RGB keyboard is enabled and ready to receive a command. */
7303 RGBKBD_STATE_ENABLED,
7304
7305 /* Put no more entry below */
7306 RGBKBD_STATE_COUNT,
7307};
7308
7309enum ec_rgbkbd_subcmd {
7310 EC_RGBKBD_SUBCMD_CLEAR = 1,
7311 EC_RGBKBD_SUBCMD_DEMO = 2,
7312 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007313 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007314 EC_RGBKBD_SUBCMD_COUNT
7315};
7316
7317enum ec_rgbkbd_demo {
7318 EC_RGBKBD_DEMO_OFF = 0,
7319 EC_RGBKBD_DEMO_FLOW = 1,
7320 EC_RGBKBD_DEMO_DOT = 2,
7321 EC_RGBKBD_DEMO_COUNT,
7322};
7323
7324BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7325
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007326enum ec_rgbkbd_type {
7327 EC_RGBKBD_TYPE_UNKNOWN = 0,
7328 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7329 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7330 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7331 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7332 EC_RGBKBD_TYPE_COUNT,
7333};
7334
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007335struct ec_rgbkbd_set_scale {
7336 uint8_t key;
7337 struct rgb_s scale;
7338};
7339
7340struct ec_params_rgbkbd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007341 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007342 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007343 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7344 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007345 struct ec_rgbkbd_set_scale set_scale;
7346 };
7347} __ec_align1;
7348
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007349struct ec_response_rgbkbd {
7350 /*
7351 * RGBKBD type supported by the device.
7352 */
7353
7354 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7355} __ec_align1;
7356
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007357struct ec_params_rgbkbd_set_color {
7358 /* Specifies the starting key ID whose color is being changed. */
7359 uint8_t start_key;
7360 /* Specifies # of elements in <color>. */
7361 uint8_t length;
7362 /* RGB color data array of length up to MAX_KEY_COUNT. */
7363 struct rgb_s color[];
7364} __ec_align1;
7365
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007366/*
7367 * Gather the response to the most recent VDM REQ from the AP, as well
7368 * as popping the oldest VDM:Attention from the DPM queue
7369 */
7370#define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7371
7372struct ec_params_typec_vdm_response {
7373 uint8_t port;
7374} __ec_align1;
7375
7376struct ec_response_typec_vdm_response {
7377 /* Number of 32-bit fields filled in */
7378 uint8_t vdm_data_objects;
7379 /* Partner to address - see enum typec_partner_type */
7380 uint8_t partner_type;
7381 /* enum ec_status describing VDM response */
7382 uint16_t vdm_response_err;
7383 /* VDM data, including VDM header */
7384 uint32_t vdm_response[VDO_MAX_SIZE];
7385 /* Number of 32-bit Attention fields filled in */
7386 uint8_t vdm_attention_objects;
7387 /* Number of remaining messages to consume */
7388 uint8_t vdm_attention_left;
7389 /* Reserved */
7390 uint16_t reserved1;
7391 /* VDM:Attention contents */
7392 uint32_t vdm_attention[2];
7393} __ec_align1;
7394
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007395/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007396/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007397
7398/*****************************************************************************/
7399/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007400 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007401 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007402#define EC_CMD_CR51_BASE 0x0300
7403#define EC_CMD_CR51_LAST 0x03FF
7404
7405/*****************************************************************************/
7406/* Fingerprint MCU commands: range 0x0400-0x040x */
7407
7408/* Fingerprint SPI sensor passthru command: prototyping ONLY */
7409#define EC_CMD_FP_PASSTHRU 0x0400
7410
7411#define EC_FP_FLAG_NOT_COMPLETE 0x1
7412
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007413struct ec_params_fp_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007414 uint16_t len; /* Number of bytes to write then read */
7415 uint16_t flags; /* EC_FP_FLAG_xxx */
7416 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007417} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007418
7419/* Configure the Fingerprint MCU behavior */
7420#define EC_CMD_FP_MODE 0x0402
7421
7422/* Put the sensor in its lowest power mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007423#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007424/* Wait to see a finger on the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007425#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007426/* Poll until the finger has left the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007427#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007428/* Capture the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007429#define FP_MODE_CAPTURE BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007430/* Finger enrollment session on-going */
7431#define FP_MODE_ENROLL_SESSION BIT(4)
7432/* Enroll the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007433#define FP_MODE_ENROLL_IMAGE BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007434/* Try to match the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007435#define FP_MODE_MATCH BIT(6)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007436/* Reset and re-initialize the sensor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007437#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007438/* Sensor maintenance for dead pixels. */
7439#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007440/* special value: don't change anything just read back current mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007441#define FP_MODE_DONT_CHANGE BIT(31)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007442
Caveh Jalali024ffe32023-01-30 14:35:19 -08007443#define FP_VALID_MODES \
7444 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
7445 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
7446 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
7447 FP_MODE_DONT_CHANGE)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007448
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007449/* Capture types defined in bits [30..28] */
7450#define FP_MODE_CAPTURE_TYPE_SHIFT 28
Caveh Jalali024ffe32023-01-30 14:35:19 -08007451#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007452/**
7453 * enum fp_capture_type - Specifies the "mode" when capturing images.
7454 *
7455 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
7456 * image (produces 'frame_size' bytes)
7457 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
7458 * bpp bits)
7459 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
7460 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
7461 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
7462 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
7463 * @FP_CAPTURE_TYPE_MAX: End of enum
7464 *
7465 * @note This enum must remain ordered, if you add new values you must ensure
7466 * that FP_CAPTURE_TYPE_MAX is still the last one.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007467 */
7468enum fp_capture_type {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007469 FP_CAPTURE_VENDOR_FORMAT = 0,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007470 FP_CAPTURE_SIMPLE_IMAGE = 1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007471 FP_CAPTURE_PATTERN0 = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007472 FP_CAPTURE_PATTERN1 = 3,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007473 FP_CAPTURE_QUALITY_TEST = 4,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007474 FP_CAPTURE_RESET_TEST = 5,
7475 FP_CAPTURE_TYPE_MAX,
7476};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007477/* Extracts the capture type from the sensor 'mode' word */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007478#define FP_CAPTURE_TYPE(mode) \
7479 (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007480
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007481struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007482 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007483} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007484
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007485struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007486 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007487} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007488
7489/* Retrieve Fingerprint sensor information */
7490#define EC_CMD_FP_INFO 0x0403
7491
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007492/* Number of dead pixels detected on the last maintenance */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007493#define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007494/* Unknown number of dead pixels detected on the last maintenance */
7495#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007496/* No interrupt from the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007497#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007498/* SPI communication error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007499#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007500/* Invalid sensor Hardware ID */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007501#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007502/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007503#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007504
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007505struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007506 /* Sensor identification */
7507 uint32_t vendor_id;
7508 uint32_t product_id;
7509 uint32_t model_id;
7510 uint32_t version;
7511 /* Image frame characteristics */
7512 uint32_t frame_size;
7513 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7514 uint16_t width;
7515 uint16_t height;
7516 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007517 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007518} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007519
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007520struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007521 /* Sensor identification */
7522 uint32_t vendor_id;
7523 uint32_t product_id;
7524 uint32_t model_id;
7525 uint32_t version;
7526 /* Image frame characteristics */
7527 uint32_t frame_size;
7528 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7529 uint16_t width;
7530 uint16_t height;
7531 uint16_t bpp;
7532 uint16_t errors; /* see FP_ERROR_ flags above */
7533 /* Template/finger current information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007534 uint32_t template_size; /* max template size in bytes */
7535 uint16_t template_max; /* maximum number of fingers/templates */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007536 uint16_t template_valid; /* number of valid fingers/templates */
7537 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007538 uint32_t template_version; /* version of the template format */
7539} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007540
7541/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007542#define EC_CMD_FP_FRAME 0x0404
7543
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007544/* constants defining the 'offset' field which also contains the frame index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007545#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007546/* Frame buffer where the captured image is stored */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007547#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007548/* First frame buffer holding a template */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007549#define FP_FRAME_INDEX_TEMPLATE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007550#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007551#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007552
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007553/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007554#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007555
7556/* Constants for encryption parameters */
7557#define FP_CONTEXT_NONCE_BYTES 12
7558#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7559#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007560#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007561#define FP_CONTEXT_TPM_BYTES 32
7562
Jett Rinkba2edaf2020-01-14 11:49:06 -07007563/* Constants for positive match parameters. */
7564#define FP_POSITIVE_MATCH_SALT_BYTES 16
7565
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007566struct ec_fp_template_encryption_metadata {
7567 /*
7568 * Version of the structure format (N=3).
7569 */
7570 uint16_t struct_version;
7571 /* Reserved bytes, set to 0. */
7572 uint16_t reserved;
7573 /*
7574 * The salt is *only* ever used for key derivation. The nonce is unique,
7575 * a different one is used for every message.
7576 */
7577 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007578 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007579 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7580};
7581
7582struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007583 /*
7584 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7585 * in the high nibble, and the real offset within the frame in
7586 * FP_FRAME_OFFSET_MASK.
7587 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007588 uint32_t offset;
7589 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007590} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007591
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007592/* Load a template into the MCU */
7593#define EC_CMD_FP_TEMPLATE 0x0405
7594
7595/* Flag in the 'size' field indicating that the full template has been sent */
7596#define FP_TEMPLATE_COMMIT 0x80000000
7597
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007598struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007599 uint32_t offset;
7600 uint32_t size;
7601 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007602} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007603
7604/* Clear the current fingerprint user context and set a new one */
7605#define EC_CMD_FP_CONTEXT 0x0406
7606
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007607struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007608 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007609} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007610
Jett Rinkba2edaf2020-01-14 11:49:06 -07007611enum fp_context_action {
7612 FP_CONTEXT_ASYNC = 0,
7613 FP_CONTEXT_GET_RESULT = 1,
7614};
7615
7616/* Version 1 of the command is "asynchronous". */
7617struct ec_params_fp_context_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007618 uint8_t action; /**< enum fp_context_action */
7619 uint8_t reserved[3]; /**< padding for alignment */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007620 uint32_t userid[FP_CONTEXT_USERID_WORDS];
7621} __ec_align4;
7622
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007623#define EC_CMD_FP_STATS 0x0407
7624
Caveh Jalali024ffe32023-01-30 14:35:19 -08007625#define FPSTATS_CAPTURE_INV BIT(0)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007626#define FPSTATS_MATCHING_INV BIT(1)
7627
7628struct ec_response_fp_stats {
7629 uint32_t capture_time_us;
7630 uint32_t matching_time_us;
7631 uint32_t overall_time_us;
7632 struct {
7633 uint32_t lo;
7634 uint32_t hi;
7635 } overall_t0;
7636 uint8_t timestamps_invalid;
7637 int8_t template_matched;
7638} __ec_align2;
7639
7640#define EC_CMD_FP_SEED 0x0408
7641struct ec_params_fp_seed {
7642 /*
7643 * Version of the structure format (N=3).
7644 */
7645 uint16_t struct_version;
7646 /* Reserved bytes, set to 0. */
7647 uint16_t reserved;
7648 /* Seed from the TPM. */
7649 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7650} __ec_align4;
7651
7652#define EC_CMD_FP_ENC_STATUS 0x0409
7653
7654/* FP TPM seed has been set or not */
7655#define FP_ENC_STATUS_SEED_SET BIT(0)
7656
7657struct ec_response_fp_encryption_status {
7658 /* Used bits in encryption engine status */
7659 uint32_t valid_flags;
7660 /* Encryption engine status */
7661 uint32_t status;
7662} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007663
Jett Rinkba2edaf2020-01-14 11:49:06 -07007664#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7665struct ec_params_fp_read_match_secret {
7666 uint16_t fgr;
7667} __ec_align4;
7668
7669/* The positive match secret has the length of the SHA256 digest. */
7670#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7671struct ec_response_fp_read_match_secret {
7672 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7673} __ec_align4;
7674
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007675/*****************************************************************************/
7676/* Touchpad MCU commands: range 0x0500-0x05FF */
7677
7678/* Perform touchpad self test */
7679#define EC_CMD_TP_SELF_TEST 0x0500
7680
7681/* Get number of frame types, and the size of each type */
7682#define EC_CMD_TP_FRAME_INFO 0x0501
7683
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007684struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007685 uint32_t n_frames;
7686 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007687} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007688
7689/* Create a snapshot of current frame readings */
7690#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7691
7692/* Read the frame */
7693#define EC_CMD_TP_FRAME_GET 0x0503
7694
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007695struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007696 uint32_t frame_index;
7697 uint32_t offset;
7698 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007699} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007700
7701/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007702/* EC-EC communication commands: range 0x0600-0x06FF */
7703
7704#define EC_COMM_TEXT_MAX 8
7705
7706/*
7707 * Get battery static information, i.e. information that never changes, or
7708 * very infrequently.
7709 */
7710#define EC_CMD_BATTERY_GET_STATIC 0x0600
7711
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007712/**
7713 * struct ec_params_battery_static_info - Battery static info parameters
7714 * @index: Battery index.
7715 */
7716struct ec_params_battery_static_info {
7717 uint8_t index;
7718} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007719
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007720/**
7721 * struct ec_response_battery_static_info - Battery static info response
7722 * @design_capacity: Battery Design Capacity (mAh)
7723 * @design_voltage: Battery Design Voltage (mV)
7724 * @manufacturer: Battery Manufacturer String
7725 * @model: Battery Model Number String
7726 * @serial: Battery Serial Number String
7727 * @type: Battery Type String
7728 * @cycle_count: Battery Cycle Count
7729 */
7730struct ec_response_battery_static_info {
7731 uint16_t design_capacity;
7732 uint16_t design_voltage;
7733 char manufacturer[EC_COMM_TEXT_MAX];
7734 char model[EC_COMM_TEXT_MAX];
7735 char serial[EC_COMM_TEXT_MAX];
7736 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007737 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007738 uint32_t cycle_count;
7739} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007740
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007741/**
7742 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7743 * Equivalent to struct ec_response_battery_static_info, but with longer
7744 * strings.
7745 * @design_capacity: battery design capacity (in mAh)
7746 * @design_voltage: battery design voltage (in mV)
7747 * @cycle_count: battery cycle count
7748 * @manufacturer_ext: battery manufacturer string
7749 * @model_ext: battery model string
7750 * @serial_ext: battery serial number string
7751 * @type_ext: battery type string
7752 */
7753struct ec_response_battery_static_info_v1 {
7754 uint16_t design_capacity;
7755 uint16_t design_voltage;
7756 uint32_t cycle_count;
7757 char manufacturer_ext[12];
7758 char model_ext[12];
7759 char serial_ext[12];
7760 char type_ext[12];
7761} __ec_align4;
7762
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007763/**
7764 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
7765 *
7766 * Equivalent to struct ec_response_battery_static_info, but with strings
7767 * further lengthened (relative to v1) to accommodate the maximum string length
7768 * permitted by the Smart Battery Data Specification revision 1.1 and fields
7769 * renamed to better match that specification.
7770 *
7771 * @design_capacity: battery design capacity (in mAh)
7772 * @design_voltage: battery design voltage (in mV)
7773 * @cycle_count: battery cycle count
7774 * @manufacturer: battery manufacturer string
7775 * @device_name: battery model string
7776 * @serial: battery serial number string
7777 * @chemistry: battery type string
7778 */
7779struct ec_response_battery_static_info_v2 {
7780 uint16_t design_capacity;
7781 uint16_t design_voltage;
7782 uint32_t cycle_count;
7783 char manufacturer[32];
7784 char device_name[32];
7785 char serial[32];
7786 char chemistry[32];
7787} __ec_align4;
7788
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007789/*
7790 * Get battery dynamic information, i.e. information that is likely to change
7791 * every time it is read.
7792 */
7793#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007795/**
7796 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7797 * @index: Battery index.
7798 */
7799struct ec_params_battery_dynamic_info {
7800 uint8_t index;
7801} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007802
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007803/**
7804 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7805 * @actual_voltage: Battery voltage (mV)
7806 * @actual_current: Battery current (mA); negative=discharging
7807 * @remaining_capacity: Remaining capacity (mAh)
7808 * @full_capacity: Capacity (mAh, might change occasionally)
7809 * @flags: Flags, see EC_BATT_FLAG_*
7810 * @desired_voltage: Charging voltage desired by battery (mV)
7811 * @desired_current: Charging current desired by battery (mA)
7812 */
7813struct ec_response_battery_dynamic_info {
7814 int16_t actual_voltage;
7815 int16_t actual_current;
7816 int16_t remaining_capacity;
7817 int16_t full_capacity;
7818 int16_t flags;
7819 int16_t desired_voltage;
7820 int16_t desired_current;
7821} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007822
7823/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007824 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007825 */
7826#define EC_CMD_CHARGER_CONTROL 0x0602
7827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007828/**
7829 * struct ec_params_charger_control - Charger control parameters
7830 * @max_current: Charger current (mA). Positive to allow base to draw up to
7831 * max_current and (possibly) charge battery, negative to request current
7832 * from base (OTG).
7833 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7834 * >= 0.
7835 * @allow_charging: Allow base battery charging (only makes sense if
7836 * max_current > 0).
7837 */
7838struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007839 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007840 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007841 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007842} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007843
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007844/* Get ACK from the USB-C SS muxes */
7845#define EC_CMD_USB_PD_MUX_ACK 0x0603
7846
7847struct ec_params_usb_pd_mux_ack {
7848 uint8_t port; /* USB-C port number */
7849} __ec_align1;
7850
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007851/* Get boot time */
7852#define EC_CMD_GET_BOOT_TIME 0x0604
7853
7854enum boot_time_param {
7855 ARAIL = 0,
7856 RSMRST,
7857 ESPIRST,
7858 PLTRST_LOW,
7859 PLTRST_HIGH,
7860 EC_CUR_TIME,
7861 RESET_CNT,
7862};
7863
7864struct ec_response_get_boot_time {
7865 uint64_t timestamp[RESET_CNT];
7866 uint16_t cnt;
7867} __ec_align4;
7868
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007869/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007870/*
7871 * Reserve a range of host commands for board-specific, experimental, or
7872 * special purpose features. These can be (re)used without updating this file.
7873 *
7874 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7875 * their EC commands for easier development, testing, debugging, and support.
7876 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007877 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7878 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7879 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007880 * In your experimental code, you may want to do something like this:
7881 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007882 * #define EC_CMD_MAGIC_FOO 0x0000
7883 * #define EC_CMD_MAGIC_BAR 0x0001
7884 * #define EC_CMD_MAGIC_HEY 0x0002
7885 *
7886 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7887 * EC_VER_MASK(0);
7888 *
7889 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7890 * EC_VER_MASK(0);
7891 *
7892 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7893 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007894 */
7895#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7896#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7897
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007898/*
7899 * Given the private host command offset, calculate the true private host
7900 * command value.
7901 */
7902#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7903 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7904
Duncan Laurie93e24442014-01-06 12:30:52 -08007905/*****************************************************************************/
7906/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007907 * Passthru commands
7908 *
7909 * Some platforms have sub-processors chained to each other. For example.
7910 *
7911 * AP <--> EC <--> PD MCU
7912 *
7913 * The top 2 bits of the command number are used to indicate which device the
7914 * command is intended for. Device 0 is always the device receiving the
7915 * command; other device mapping is board-specific.
7916 *
7917 * When a device receives a command to be passed to a sub-processor, it passes
7918 * it on with the device number set back to 0. This allows the sub-processor
7919 * to remain blissfully unaware of whether the command originated on the next
7920 * device up the chain, or was passed through from the AP.
7921 *
7922 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7923 * AP sends command 0x4002 to the EC
7924 * EC sends command 0x0002 to the PD MCU
7925 * EC forwards PD MCU response back to the AP
7926 */
7927
7928/* Offset and max command number for sub-device n */
7929#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7930#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7931
7932/*****************************************************************************/
7933/*
Duncan Laurie93e24442014-01-06 12:30:52 -08007934 * Deprecated constants. These constants have been renamed for clarity. The
7935 * meaning and size has not changed. Programs that use the old names should
7936 * switch to the new names soon, as the old names may not be carried forward
7937 * forever.
7938 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007939#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
7940#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
7941#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
Duncan Laurie93e24442014-01-06 12:30:52 -08007942
Caveh Jalali024ffe32023-01-30 14:35:19 -08007943#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007944
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007945#ifdef __cplusplus
7946}
7947#endif
7948
Caveh Jalali024ffe32023-01-30 14:35:19 -08007949#endif /* __CROS_EC_EC_COMMANDS_H */