blob: 1066cccce8f32a306d39b1391cec89814bf51f1d [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 */
Tim Van Pattencab60602023-02-24 12:27:04 -0700252#define EC_FAN_SPEED_STALLED 0x0
253/* This should be used only for ectool to support old ECs. */
254#define EC_FAN_SPEED_STALLED_DEPRECATED 0xfffe
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800255
256/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800257#define EC_BATT_FLAG_AC_PRESENT 0x01
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800258#define EC_BATT_FLAG_BATT_PRESENT 0x02
Caveh Jalali024ffe32023-01-30 14:35:19 -0800259#define EC_BATT_FLAG_DISCHARGING 0x04
260#define EC_BATT_FLAG_CHARGING 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800261#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600262/* Set if some of the static/dynamic data is invalid (or outdated). */
263#define EC_BATT_FLAG_INVALID_DATA 0x20
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800264#define EC_BATT_FLAG_CUT_OFF 0x40
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800265
266/* Switch flags at EC_MEMMAP_SWITCHES */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800267#define EC_SWITCH_LID_OPEN 0x01
268#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800269#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700270/* Was recovery requested via keyboard; now unused. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800271#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800272/* Recovery requested via dedicated signal (from servo board) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800273#define EC_SWITCH_DEDICATED_RECOVERY 0x10
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800274/* Was fake developer mode switch; now unused. Remove in next refactor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800275#define EC_SWITCH_IGNORE0 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800276
277/* Host command interface flags */
278/* Host command interface supports LPC args (LPC interface only) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800279#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800280/* Host command interface supports version 3 protocol */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800281#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800282
283/* Wireless switch flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800284#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
285#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
286#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
287#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
288#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800289
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700290/*****************************************************************************/
291/*
292 * ACPI commands
293 *
294 * These are valid ONLY on the ACPI command/data port.
295 */
296
297/*
298 * ACPI Read Embedded Controller
299 *
300 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
301 *
302 * Use the following sequence:
303 *
304 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
305 * - Wait for EC_LPC_CMDR_PENDING bit to clear
306 * - Write address to EC_LPC_ADDR_ACPI_DATA
307 * - Wait for EC_LPC_CMDR_DATA bit to set
308 * - Read value from EC_LPC_ADDR_ACPI_DATA
309 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700310#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700311
312/*
313 * ACPI Write Embedded Controller
314 *
315 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
316 *
317 * Use the following sequence:
318 *
319 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
320 * - Wait for EC_LPC_CMDR_PENDING bit to clear
321 * - Write address to EC_LPC_ADDR_ACPI_DATA
322 * - Wait for EC_LPC_CMDR_PENDING bit to clear
323 * - Write value to EC_LPC_ADDR_ACPI_DATA
324 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700325#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700326
327/*
328 * ACPI Burst Enable Embedded Controller
329 *
330 * This enables burst mode on the EC to allow the host to issue several
331 * commands back-to-back. While in this mode, writes to mapped multi-byte
332 * data are locked out to ensure data consistency.
333 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700334#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700335
336/*
337 * ACPI Burst Disable Embedded Controller
338 *
339 * This disables burst mode on the EC and stops preventing EC writes to mapped
340 * multi-byte data.
341 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700342#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700343
344/*
345 * ACPI Query Embedded Controller
346 *
347 * This clears the lowest-order bit in the currently pending host events, and
348 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
349 * event 0x80000000 = 32), or 0 if no event was pending.
350 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700351#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700352
353/* Valid addresses in ACPI memory space, for read/write commands */
354
355/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800356#define EC_ACPI_MEM_VERSION 0x00
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700357/*
358 * Test location; writing value here updates test compliment byte to (0xff -
359 * value).
360 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800361#define EC_ACPI_MEM_TEST 0x01
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700362/* Test compliment; writes here are ignored. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800363#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700364
365/* Keyboard backlight brightness percent (0 - 100) */
366#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
367/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800368#define EC_ACPI_MEM_FAN_DUTY 0x04
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700369
370/*
371 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
372 * independent thresholds attached to them. The current value of the ID
373 * register determines which sensor is affected by the THRESHOLD and COMMIT
374 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
375 * as the memory-mapped sensors. The COMMIT register applies those settings.
376 *
377 * The spec does not mandate any way to read back the threshold settings
378 * themselves, but when a threshold is crossed the AP needs a way to determine
379 * which sensor(s) are responsible. Each reading of the ID register clears and
380 * returns one sensor ID that has crossed one of its threshold (in either
381 * direction) since the last read. A value of 0xFF means "no new thresholds
382 * have tripped". Setting or enabling the thresholds for a sensor will clear
383 * the unread event count for that sensor.
384 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800385#define EC_ACPI_MEM_TEMP_ID 0x05
386#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
387#define EC_ACPI_MEM_TEMP_COMMIT 0x07
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700388/*
389 * Here are the bits for the COMMIT register:
390 * bit 0 selects the threshold index for the chosen sensor (0/1)
391 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
392 * Each write to the commit register affects one threshold.
393 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800394#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
395#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700396/*
397 * Example:
398 *
399 * Set the thresholds for sensor 2 to 50 C and 60 C:
400 * write 2 to [0x05] -- select temp sensor 2
401 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
402 * write 0x2 to [0x07] -- enable threshold 0 with this value
403 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
404 * write 0x3 to [0x07] -- enable threshold 1 with this value
405 *
406 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
407 * write 2 to [0x05] -- select temp sensor 2
408 * write 0x1 to [0x07] -- disable threshold 1
409 */
410
411/* DPTF battery charging current limit */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800412#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700413
414/* Charging limit is specified in 64 mA steps */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800415#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700416/* Value to disable DPTF battery charging limit */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800417#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700418
jiazi Yang51fc93f2016-07-28 05:15:01 -0400419/*
420 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800421 * Bits Definition
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800422 * 4 Off Body/On Body status: 0 = Off Body.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800423 * 3:1 Device DPTF Profile Number (DDPN)
424 * 0 = Reserved for backward compatibility (indicates no valid
425 * profile number. Host should fall back to using TBMD).
426 * 1..7 = DPTF Profile number to indicate to host which table needs
427 * to be loaded.
428 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400429 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700430#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
Caveh Jalali024ffe32023-01-30 14:35:19 -0800431#define EC_ACPI_MEM_TBMD_SHIFT 0
432#define EC_ACPI_MEM_TBMD_MASK 0x1
433#define EC_ACPI_MEM_DDPN_SHIFT 1
434#define EC_ACPI_MEM_DDPN_MASK 0x7
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800435#define EC_ACPI_MEM_STTB_SHIFT 4
436#define EC_ACPI_MEM_STTB_MASK 0x1
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700437
438/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600439 * Report device features. Uses the same format as the host command, except:
440 *
441 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
442 * of features", which is of limited interest when the system is already
443 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
444 * these are supported, it defaults to 0.
445 * This allows detecting the presence of this field since older versions of
446 * the EC codebase would simply return 0xff to that unknown address. Check
447 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
448 * are valid.
449 */
450#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
451#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
452#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
453#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
454#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
455#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
456#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
457#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
458
Caveh Jalali024ffe32023-01-30 14:35:19 -0800459#define EC_ACPI_MEM_BATTERY_INDEX 0x12
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600460
461/*
462 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
463 * is enabled (1) or disabled (0).
464 * bit 0 USB port ID 0
465 * ...
466 * bit 7 USB port ID 7
467 */
468#define EC_ACPI_MEM_USB_PORT_POWER 0x13
469
470/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600471 * USB Retimer firmware update.
472 * Read:
473 * Result of last operation AP requested
474 * Write:
475 * bits[3:0]: USB-C port number
476 * bits[7:4]: Operation requested by AP
477 *
478 * NDA (no device attached) case:
479 * To update retimer firmware, AP needs set up TBT Alt mode.
480 * AP requests operations in this sequence:
481 * 1. Get port information about which ports support retimer firmware update.
482 * In the query result, each bit represents one port.
483 * 2. Get current MUX mode, it's NDA.
484 * 3. Suspend specified PD port's task.
485 * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode ->
486 * update firmware -> disconnect MUX -> resume PD task.
487 *
488 * DA (device attached) cases:
489 * Retimer firmware update is not supported in DA cases.
490 * 1. Get port information about which ports support retimer firmware update
491 * 2. Get current MUX mode, it's DA.
492 * 3. AP continues. No more retimer firmware update activities.
493 *
494 */
495#define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14
496
497#define USB_RETIMER_FW_UPDATE_OP_SHIFT 4
Caveh Jalali024ffe32023-01-30 14:35:19 -0800498#define USB_RETIMER_FW_UPDATE_ERR 0xfe
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600499#define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff
Scott Chao18141d8c2021-07-30 10:40:57 +0800500/* Mask to clear unused MUX bits in retimer firmware update */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800501#define USB_RETIMER_FW_UPDATE_MUX_MASK \
502 (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED | \
503 USB_PD_MUX_SAFE_MODE | USB_PD_MUX_TBT_COMPAT_ENABLED | \
504 USB_PD_MUX_USB4_ENABLED)
Scott Chao18141d8c2021-07-30 10:40:57 +0800505
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600506/* Retimer firmware update operations */
507#define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
508#define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800509#define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
510#define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
511#define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
512#define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
513#define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600514#define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
515
Caveh Jalali024ffe32023-01-30 14:35:19 -0800516#define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x)&0x0f)
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600517#define EC_ACPI_MEM_USB_RETIMER_OP(x) \
Caveh Jalali024ffe32023-01-30 14:35:19 -0800518 (((x)&0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600519
520/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700521 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
522 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
523 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800524#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
525#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700526
527/* Current version of ACPI memory address space */
528#define EC_ACPI_MEM_VERSION_CURRENT 2
529
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800530/*
531 * This header file is used in coreboot both in C and ACPI code. The ACPI code
532 * is pre-processed to handle constants but the ASL compiler is unable to
533 * handle actual C code so keep it separate.
534 */
535#ifndef __ACPI__
536
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800537#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800538/*
539 * Define __packed if someone hasn't beat us to it. Linux kernel style
540 * checking prefers __packed over __attribute__((packed)).
541 */
542#ifndef __packed
543#define __packed __attribute__((packed))
544#endif
545
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700546#ifndef __aligned
547#define __aligned(x) __attribute__((aligned(x)))
548#endif
Caveh Jalali024ffe32023-01-30 14:35:19 -0800549#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700550
551/*
552 * Attributes for EC request and response packets. Just defining __packed
553 * results in inefficient assembly code on ARM, if the structure is actually
554 * 32-bit aligned, as it should be for all buffers.
555 *
556 * Be very careful when adding these to existing structures. They will round
557 * up the structure size to the specified boundary.
558 *
559 * Also be very careful to make that if a structure is included in some other
560 * parent structure that the alignment will still be true given the packing of
561 * the parent structure. This is particularly important if the sub-structure
562 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200563 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700564 *
565 * Also be very careful using __packed - particularly when nesting non-packed
566 * structures inside packed ones. In fact, DO NOT use __packed directly;
567 * always use one of these attributes.
568 *
569 * Once everything is annotated properly, the following search strings should
570 * not return ANY matches in this file other than right here:
571 *
572 * "__packed" - generates inefficient code; all sub-structs must also be packed
573 *
574 * "struct [^_]" - all structs should be annotated, except for structs that are
575 * members of other structs/unions (and their original declarations should be
576 * annotated).
577 */
578#ifdef CONFIG_HOSTCMD_ALIGNED
579
580/*
581 * Packed structures where offset and size are always aligned to 1, 2, or 4
582 * byte boundary.
583 */
584#define __ec_align1 __packed
585#define __ec_align2 __packed __aligned(2)
586#define __ec_align4 __packed __aligned(4)
587
588/*
589 * Packed structure which must be under-aligned, because its size is not a
590 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
591 * of all multi-byte fields in it, even though they are themselves aligned.
592 *
593 * In theory, we could duplicate the structure with __aligned(4) for accessing
594 * its members, but use the __packed version for sizeof().
595 */
596#define __ec_align_size1 __packed
597
598/*
599 * Packed structure which must be under-aligned, because its offset inside a
600 * parent structure is not a 4-byte multiple.
601 */
602#define __ec_align_offset1 __packed
603#define __ec_align_offset2 __packed __aligned(2)
604
605/*
606 * Structures which are complicated enough that I'm skipping them on the first
607 * pass. They are effectively unchanged from their previous definitions.
608 *
609 * TODO(rspangler): Figure out what to do with these. It's likely necessary
610 * to work out the size and offset of each member and add explicit padding to
611 * maintain those.
612 */
613#define __ec_todo_packed __packed
614#define __ec_todo_unpacked
615
Caveh Jalali024ffe32023-01-30 14:35:19 -0800616#else /* !CONFIG_HOSTCMD_ALIGNED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700617
618/*
619 * Packed structures make no assumption about alignment, so they do inefficient
620 * byte-wise reads.
621 */
622#define __ec_align1 __packed
623#define __ec_align2 __packed
624#define __ec_align4 __packed
625#define __ec_align_size1 __packed
626#define __ec_align_offset1 __packed
627#define __ec_align_offset2 __packed
628#define __ec_todo_packed __packed
629#define __ec_todo_unpacked
630
Caveh Jalali024ffe32023-01-30 14:35:19 -0800631#endif /* !CONFIG_HOSTCMD_ALIGNED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700632
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800633/* LPC command status byte masks */
634/* EC has written a byte in the data register and host hasn't read it yet */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800635#define EC_LPC_STATUS_TO_HOST 0x01
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800636/* Host has written a command/data byte and the EC hasn't read it yet */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800637#define EC_LPC_STATUS_FROM_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800638/* EC is processing a command */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800639#define EC_LPC_STATUS_PROCESSING 0x04
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800640/* Last write to EC was a command, not data */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800641#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700642/* EC is in burst mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800643#define EC_LPC_STATUS_BURST_MODE 0x10
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800644/* SCI event is pending (requesting SCI query) */
645#define EC_LPC_STATUS_SCI_PENDING 0x20
646/* SMI event is pending (requesting SMI query) */
647#define EC_LPC_STATUS_SMI_PENDING 0x40
648/* (reserved) */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800649#define EC_LPC_STATUS_RESERVED 0x80
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800650
651/*
652 * EC is busy. This covers both the EC processing a command, and the host has
653 * written a new command but the EC hasn't picked it up yet.
654 */
655#define EC_LPC_STATUS_BUSY_MASK \
656 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
657
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800658/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700659 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700660 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800661enum ec_status {
662 EC_RES_SUCCESS = 0,
663 EC_RES_INVALID_COMMAND = 1,
664 EC_RES_ERROR = 2,
665 EC_RES_INVALID_PARAM = 3,
666 EC_RES_ACCESS_DENIED = 4,
667 EC_RES_INVALID_RESPONSE = 5,
668 EC_RES_INVALID_VERSION = 6,
669 EC_RES_INVALID_CHECKSUM = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -0800670 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
671 EC_RES_UNAVAILABLE = 9, /* No response available */
672 EC_RES_TIMEOUT = 10, /* We got a timeout */
673 EC_RES_OVERFLOW = 11, /* Table / data overflow */
674 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
675 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
676 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
677 EC_RES_BUS_ERROR = 15, /* Communications bus error */
678 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
679 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
680 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
681 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
682 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700683
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800684 EC_RES_MAX = UINT16_MAX, /**< Force enum to be 16 bits */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700685} __packed;
686BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800687
688/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600689 * Host event codes. ACPI query EC command uses code 0 to mean "no event
690 * pending". We explicitly specify each value in the enum listing so they won't
691 * change if we delete/insert an item or rearrange the list (it needs to be
692 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800693 */
694enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600695 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800696 EC_HOST_EVENT_LID_CLOSED = 1,
697 EC_HOST_EVENT_LID_OPEN = 2,
698 EC_HOST_EVENT_POWER_BUTTON = 3,
699 EC_HOST_EVENT_AC_CONNECTED = 4,
700 EC_HOST_EVENT_AC_DISCONNECTED = 5,
701 EC_HOST_EVENT_BATTERY_LOW = 6,
702 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
703 EC_HOST_EVENT_BATTERY = 8,
704 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700705 /* Event generated by a device attached to the EC */
706 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800707 EC_HOST_EVENT_THERMAL = 11,
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800708 /* GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. */
709 EC_HOST_EVENT_GPU = 12,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800710 EC_HOST_EVENT_KEY_PRESSED = 13,
711 /*
712 * EC has finished initializing the host interface. The host can check
713 * for this event following sending a EC_CMD_REBOOT_EC command to
714 * determine when the EC is ready to accept subsequent commands.
715 */
716 EC_HOST_EVENT_INTERFACE_READY = 14,
717 /* Keyboard recovery combo has been pressed */
718 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
719
720 /* Shutdown due to thermal overload */
721 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
722 /* Shutdown due to battery level too low */
723 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
724
Duncan Laurie93e24442014-01-06 12:30:52 -0800725 /* Suggest that the AP throttle itself */
726 EC_HOST_EVENT_THROTTLE_START = 18,
727 /* Suggest that the AP resume normal speed */
728 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700729
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800730 /* Hang detect logic detected a hang and host event timeout expired */
731 EC_HOST_EVENT_HANG_DETECT = 20,
732 /* Hang detect logic detected a hang and warm rebooted the AP */
733 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700734
735 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700736 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800737
Duncan Lauried8401182014-09-29 08:32:19 -0700738 /* Battery Status flags have changed */
739 EC_HOST_EVENT_BATTERY_STATUS = 23,
740
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700741 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800742 EC_HOST_EVENT_PANIC = 24,
743
Furquan Shaikh066cc852015-06-20 15:53:03 -0700744 /* Keyboard fastboot combo has been pressed */
745 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
746
Gwendal Grignou880b4582016-06-20 08:49:25 -0700747 /* EC RTC event occurred */
748 EC_HOST_EVENT_RTC = 26,
749
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700750 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700751 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700752
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700753 /* EC desires to change state of host-controlled USB mux */
754 EC_HOST_EVENT_USB_MUX = 28,
755
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800756 /*
757 * The device has changed "modes". This can be one of the following:
758 *
759 * - TABLET/LAPTOP mode
760 * - detachable base attach/detach event
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800761 * - on body/off body transition event
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800762 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400763 EC_HOST_EVENT_MODE_CHANGE = 29,
764
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700765 /* Keyboard recovery combo with hardware reinitialization */
766 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
767
Jett Rinkba2edaf2020-01-14 11:49:06 -0700768 /* WoV */
769 EC_HOST_EVENT_WOV = 31,
770
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700771 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800772 * The high bit of the event mask is not used as a host event code. If
773 * it reads back as set, then the entire event mask should be
774 * considered invalid by the host. This can happen when reading the
775 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
776 * not initialized on the EC, or improperly configured on the host.
777 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800778 EC_HOST_EVENT_INVALID = 32,
Tim Van Pattencab60602023-02-24 12:27:04 -0700779
780 /* Body detect (lap/desk) change event */
781 EC_HOST_EVENT_BODY_DETECT_CHANGE = 33,
782
783 /*
784 * Only 64 host events are supported. This enum uses 1-based counting so
785 * it can skip 0 (NONE), so the last legal host event number is 64.
786 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800787};
Tim Van Pattencab60602023-02-24 12:27:04 -0700788
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800789/* Host event mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800790#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code)-1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800791
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800792/* clang-format off */
793#define HOST_EVENT_TEXT \
794 { \
795 [EC_HOST_EVENT_NONE] = "NONE", \
796 [EC_HOST_EVENT_LID_CLOSED] = "LID_CLOSED", \
797 [EC_HOST_EVENT_LID_OPEN] = "LID_OPEN", \
798 [EC_HOST_EVENT_POWER_BUTTON] = "POWER_BUTTON", \
799 [EC_HOST_EVENT_AC_CONNECTED] = "AC_CONNECTED", \
800 [EC_HOST_EVENT_AC_DISCONNECTED] = "AC_DISCONNECTED", \
801 [EC_HOST_EVENT_BATTERY_LOW] = "BATTERY_LOW", \
802 [EC_HOST_EVENT_BATTERY_CRITICAL] = "BATTERY_CRITICAL", \
803 [EC_HOST_EVENT_BATTERY] = "BATTERY", \
804 [EC_HOST_EVENT_THERMAL_THRESHOLD] = "THERMAL_THRESHOLD", \
805 [EC_HOST_EVENT_DEVICE] = "DEVICE", \
806 [EC_HOST_EVENT_THERMAL] = "THERMAL", \
807 [EC_HOST_EVENT_GPU] = "GPU", \
808 [EC_HOST_EVENT_KEY_PRESSED] = "KEY_PRESSED", \
809 [EC_HOST_EVENT_INTERFACE_READY] = "INTERFACE_READY", \
810 [EC_HOST_EVENT_KEYBOARD_RECOVERY] = "KEYBOARD_RECOVERY", \
811 [EC_HOST_EVENT_THERMAL_SHUTDOWN] = "THERMAL_SHUTDOWN", \
812 [EC_HOST_EVENT_BATTERY_SHUTDOWN] = "BATTERY_SHUTDOWN", \
813 [EC_HOST_EVENT_THROTTLE_START] = "THROTTLE_START", \
814 [EC_HOST_EVENT_THROTTLE_STOP] = "THROTTLE_STOP", \
815 [EC_HOST_EVENT_HANG_DETECT] = "HANG_DETECT", \
816 [EC_HOST_EVENT_HANG_REBOOT] = "HANG_REBOOT", \
817 [EC_HOST_EVENT_PD_MCU] = "PD_MCU", \
818 [EC_HOST_EVENT_BATTERY_STATUS] = "BATTERY_STATUS", \
819 [EC_HOST_EVENT_PANIC] = "PANIC", \
820 [EC_HOST_EVENT_KEYBOARD_FASTBOOT] = "KEYBOARD_FASTBOOT", \
821 [EC_HOST_EVENT_RTC] = "RTC", \
822 [EC_HOST_EVENT_MKBP] = "MKBP", \
823 [EC_HOST_EVENT_USB_MUX] = "USB_MUX", \
824 [EC_HOST_EVENT_MODE_CHANGE] = "MODE_CHANGE", \
825 [EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT] = \
826 "KEYBOARD_RECOVERY_HW_REINIT", \
827 [EC_HOST_EVENT_WOV] = "WOV", \
828 [EC_HOST_EVENT_INVALID] = "INVALID", \
Tim Van Pattencab60602023-02-24 12:27:04 -0700829 [EC_HOST_EVENT_BODY_DETECT_CHANGE] = "BODY_DETECT_CHANGE", \
Caveh Jalali6bd733b2023-01-30 17:06:31 -0800830 }
831/* clang-format on */
832
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800833/**
834 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
835 * @flags: The host argument flags.
836 * @command_version: Command version.
837 * @data_size: The length of data.
838 * @checksum: Checksum; sum of command + flags + command_version + data_size +
839 * all params/response data bytes.
840 */
841struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800842 uint8_t flags;
843 uint8_t command_version;
844 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800845 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800846} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800847
848/* Flags for ec_lpc_host_args.flags */
849/*
850 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
851 * params.
852 *
853 * If EC gets a command and this flag is not set, this is an old-style command.
854 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
855 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700856 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800857 */
858#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
859/*
860 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
861 *
862 * If EC responds to a command and this flag is not set, this is an old-style
863 * response. Command version is 0 and response data from EC is at
864 * EC_LPC_ADDR_OLD_PARAM with unknown length.
865 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800866#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800867
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800868/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800869/*
870 * Byte codes returned by EC over SPI interface.
871 *
872 * These can be used by the AP to debug the EC interface, and to determine
873 * when the EC is not in a state where it will ever get around to responding
874 * to the AP.
875 *
876 * Example of sequence of bytes read from EC for a current good transfer:
877 * 1. - - AP asserts chip select (CS#)
878 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
879 * 3. - - EC starts handling CS# interrupt
880 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
881 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
882 * bytes looking for EC_SPI_FRAME_START
883 * 6. - - EC finishes processing and sets up response
884 * 7. EC_SPI_FRAME_START - AP reads frame byte
885 * 8. (response packet) - AP reads response packet
886 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
887 * 10 - - AP deasserts chip select
888 * 11 - - EC processes CS# interrupt and sets up DMA for
889 * next request
890 *
891 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
892 * the following byte values:
893 * EC_SPI_OLD_READY
894 * EC_SPI_RX_READY
895 * EC_SPI_RECEIVING
896 * EC_SPI_PROCESSING
897 *
898 * Then the EC found an error in the request, or was not ready for the request
899 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
900 * because the EC is unable to tell when the AP is done sending its request.
901 */
902
903/*
904 * Framing byte which precedes a response packet from the EC. After sending a
905 * request, the AP will clock in bytes until it sees the framing byte, then
906 * clock in the response packet.
907 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800908#define EC_SPI_FRAME_START 0xec
Duncan Laurie93e24442014-01-06 12:30:52 -0800909
910/*
911 * Padding bytes which are clocked out after the end of a response packet.
912 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800913#define EC_SPI_PAST_END 0xed
Duncan Laurie93e24442014-01-06 12:30:52 -0800914
915/*
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800916 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
Duncan Laurie93e24442014-01-06 12:30:52 -0800917 * that the AP will send a valid packet header (starting with
918 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +0800919 *
920 * NOTE: Some SPI configurations place the Most Significant Bit on SDO when
921 * CS goes low. This macro has the Most Significant Bit set to zero,
922 * so SDO will not be driven high when CS goes low.
Duncan Laurie93e24442014-01-06 12:30:52 -0800923 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800924#define EC_SPI_RX_READY 0x78
Duncan Laurie93e24442014-01-06 12:30:52 -0800925
926/*
927 * EC has started receiving the request from the AP, but hasn't started
928 * processing it yet.
929 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800930#define EC_SPI_RECEIVING 0xf9
Duncan Laurie93e24442014-01-06 12:30:52 -0800931
932/* EC has received the entire request from the AP and is processing it. */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800933#define EC_SPI_PROCESSING 0xfa
Duncan Laurie93e24442014-01-06 12:30:52 -0800934
935/*
936 * EC received bad data from the AP, such as a packet header with an invalid
937 * length. EC will ignore all data until chip select deasserts.
938 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800939#define EC_SPI_RX_BAD_DATA 0xfb
Duncan Laurie93e24442014-01-06 12:30:52 -0800940
941/*
942 * EC received data from the AP before it was ready. That is, the AP asserted
943 * chip select and started clocking data before the EC was ready to receive it.
944 * EC will ignore all data until chip select deasserts.
945 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800946#define EC_SPI_NOT_READY 0xfc
Duncan Laurie93e24442014-01-06 12:30:52 -0800947
948/*
949 * EC was ready to receive a request from the AP. EC has treated the byte sent
950 * by the AP as part of a request packet, or (for old-style ECs) is processing
951 * a fully received packet but is not ready to respond yet.
952 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800953#define EC_SPI_OLD_READY 0xfd
Duncan Laurie93e24442014-01-06 12:30:52 -0800954
955/*****************************************************************************/
956
957/*
958 * Protocol version 2 for I2C and SPI send a request this way:
959 *
960 * 0 EC_CMD_VERSION0 + (command version)
961 * 1 Command number
962 * 2 Length of params = N
963 * 3..N+2 Params, if any
964 * N+3 8-bit checksum of bytes 0..N+2
965 *
966 * The corresponding response is:
967 *
968 * 0 Result code (EC_RES_*)
969 * 1 Length of params = M
970 * 2..M+1 Params, if any
971 * M+2 8-bit checksum of bytes 0..M+1
972 */
973#define EC_PROTO2_REQUEST_HEADER_BYTES 3
974#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -0800975#define EC_PROTO2_REQUEST_OVERHEAD \
976 (EC_PROTO2_REQUEST_HEADER_BYTES + EC_PROTO2_REQUEST_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -0800977
978#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
979#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
Caveh Jalali024ffe32023-01-30 14:35:19 -0800980#define EC_PROTO2_RESPONSE_OVERHEAD \
981 (EC_PROTO2_RESPONSE_HEADER_BYTES + EC_PROTO2_RESPONSE_TRAILER_BYTES)
Duncan Laurie93e24442014-01-06 12:30:52 -0800982
983/* Parameter length was limited by the LPC interface */
984#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
985
986/* Maximum request and response packet sizes for protocol version 2 */
Caveh Jalali024ffe32023-01-30 14:35:19 -0800987#define EC_PROTO2_MAX_REQUEST_SIZE \
988 (EC_PROTO2_REQUEST_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
989#define EC_PROTO2_MAX_RESPONSE_SIZE \
990 (EC_PROTO2_RESPONSE_OVERHEAD + EC_PROTO2_MAX_PARAM_SIZE)
Duncan Laurie93e24442014-01-06 12:30:52 -0800991
992/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800993
994/*
995 * Value written to legacy command port / prefix byte to indicate protocol
996 * 3+ structs are being used. Usage is bus-dependent.
997 */
998#define EC_COMMAND_PROTOCOL_3 0xda
999
1000#define EC_HOST_REQUEST_VERSION 3
1001
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001002/**
1003 * struct ec_host_request - Version 3 request from host.
1004 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
1005 * receives a header with a version it doesn't know how to
1006 * parse.
1007 * @checksum: Checksum of request and data; sum of all bytes including checksum
1008 * should total to 0.
1009 * @command: Command to send (EC_CMD_...)
1010 * @command_version: Command version.
1011 * @reserved: Unused byte in current protocol version; set to 0.
1012 * @data_len: Length of data which follows this header.
1013 */
1014struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001015 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001016 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001017 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001018 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001019 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001020 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001021} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001022
1023#define EC_HOST_RESPONSE_VERSION 3
1024
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001025/**
1026 * struct ec_host_response - Version 3 response from EC.
1027 * @struct_version: Struct version (=3).
1028 * @checksum: Checksum of response and data; sum of all bytes including
1029 * checksum should total to 0.
1030 * @result: EC's response to the command (separate from communication failure)
1031 * @data_len: Length of data which follows this header.
1032 * @reserved: Unused bytes in current protocol version; set to 0.
1033 */
1034struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001035 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001036 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001037 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001038 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001039 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001040} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +08001041
1042/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001043
1044/*
1045 * Host command protocol V4.
1046 *
1047 * Packets always start with a request or response header. They are followed
1048 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +01001049 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001050 * polynomial.
1051 *
1052 * Host algorithm when sending a request q:
1053 *
1054 * 101) tries_left=(some value, e.g. 3);
1055 * 102) q.seq_num++
1056 * 103) q.seq_dup=0
1057 * 104) Calculate q.header_crc.
1058 * 105) Send request q to EC.
1059 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
1060 *
1061 * 201) If r.struct_version != 4, go to 301.
1062 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
1063 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
1064 * 204) If r.seq_num != q.seq_num, go to 301.
1065 * 205) If r.seq_dup == q.seq_dup, return success.
1066 * 207) If r.seq_dup == 1, go to 301.
1067 * 208) Return error.
1068 *
1069 * 301) If --tries_left <= 0, return error.
1070 * 302) If q.seq_dup == 1, go to 105.
1071 * 303) q.seq_dup = 1
1072 * 304) Go to 104.
1073 *
1074 * EC algorithm when receiving a request q.
1075 * EC has response buffer r, error buffer e.
1076 *
1077 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
1078 * and go to 301
1079 * 102) If q.header_crc mismatches calculated CRC, set e.result =
1080 * EC_RES_INVALID_HEADER_CRC and go to 301
1081 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
1082 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
1083 * and go to 301.
1084 * 104) If q.seq_dup == 0, go to 201.
1085 * 105) If q.seq_num != r.seq_num, go to 201.
1086 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
1087 *
1088 * 201) Process request q into response r.
1089 * 202) r.seq_num = q.seq_num
1090 * 203) r.seq_dup = q.seq_dup
1091 * 204) Calculate r.header_crc
1092 * 205) If r.data_len > 0 and data is no longer available, set e.result =
1093 * EC_RES_DUP_UNAVAILABLE and go to 301.
1094 * 206) Send response r.
1095 *
1096 * 301) e.seq_num = q.seq_num
1097 * 302) e.seq_dup = q.seq_dup
1098 * 303) Calculate e.header_crc.
1099 * 304) Send error response e.
1100 */
1101
1102/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001103struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001104 /*
1105 * bits 0-3: struct_version: Structure version (=4)
1106 * bit 4: is_response: Is response (=0)
1107 * bits 5-6: seq_num: Sequence number
1108 * bit 7: seq_dup: Sequence duplicate flag
1109 */
1110 uint8_t fields0;
1111
1112 /*
1113 * bits 0-4: command_version: Command version
1114 * bits 5-6: Reserved (set 0, ignore on read)
1115 * bit 7: data_crc_present: Is data CRC present after data
1116 */
1117 uint8_t fields1;
1118
1119 /* Command code (EC_CMD_*) */
1120 uint16_t command;
1121
1122 /* Length of data which follows this header (not including data CRC) */
1123 uint16_t data_len;
1124
1125 /* Reserved (set 0, ignore on read) */
1126 uint8_t reserved;
1127
1128 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1129 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001130} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001131
1132/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001133struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001134 /*
1135 * bits 0-3: struct_version: Structure version (=4)
1136 * bit 4: is_response: Is response (=1)
1137 * bits 5-6: seq_num: Sequence number
1138 * bit 7: seq_dup: Sequence duplicate flag
1139 */
1140 uint8_t fields0;
1141
1142 /*
1143 * bits 0-6: Reserved (set 0, ignore on read)
1144 * bit 7: data_crc_present: Is data CRC present after data
1145 */
1146 uint8_t fields1;
1147
1148 /* Result code (EC_RES_*) */
1149 uint16_t result;
1150
1151 /* Length of data which follows this header (not including data CRC) */
1152 uint16_t data_len;
1153
1154 /* Reserved (set 0, ignore on read) */
1155 uint8_t reserved;
1156
1157 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1158 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001159} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001160
1161/* Fields in fields0 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001162#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1163#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1164#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1165#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1166#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001167
1168/* Fields in fields1 byte */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001169#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1170#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001171
1172/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001173/*
1174 * Notes on commands:
1175 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001176 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001177 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001178 * specified, the command does not input or output data, respectively.
1179 * Parameter/response length is implicit in the structs. Some underlying
1180 * communication protocols (I2C, SPI) may add length or checksum headers, but
1181 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001182 *
1183 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1184 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001185 */
1186
1187/*****************************************************************************/
1188/* General / test commands */
1189
1190/*
1191 * Get protocol version, used to deal with non-backward compatible protocol
1192 * changes.
1193 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001194#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001195
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001196/**
1197 * struct ec_response_proto_version - Response to the proto version command.
1198 * @version: The protocol version.
1199 */
1200struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001201 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001202} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001203
1204/*
1205 * Hello. This is a simple command to test the EC is responsive to
1206 * commands.
1207 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001208#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001209
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001210/**
1211 * struct ec_params_hello - Parameters to the hello command.
1212 * @in_data: Pass anything here.
1213 */
1214struct ec_params_hello {
1215 uint32_t in_data;
1216} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001218/**
1219 * struct ec_response_hello - Response to the hello command.
1220 * @out_data: Output will be in_data + 0x01020304.
1221 */
1222struct ec_response_hello {
1223 uint32_t out_data;
1224} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001225
1226/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001227#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001228
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001229enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001230 EC_IMAGE_UNKNOWN = 0,
1231 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001232 EC_IMAGE_RW,
1233 EC_IMAGE_RW_A = EC_IMAGE_RW,
1234 EC_IMAGE_RO_B,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001235 EC_IMAGE_RW_B,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001236};
1237
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001238/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001239 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001240 * @version_string_ro: Null-terminated RO firmware version string.
1241 * @version_string_rw: Null-terminated RW firmware version string.
1242 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001243 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001244 */
1245struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001246 char version_string_ro[32];
1247 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001248 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001249 uint32_t current_image;
1250} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001251
Rob Barnes5ab14662021-09-17 10:24:45 -06001252/**
1253 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1254 *
1255 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1256 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1257 * and adds one additional field (cros_fwid_rw).
1258 *
1259 * @version_string_ro: Null-terminated RO firmware version string.
1260 * @version_string_rw: Null-terminated RW firmware version string.
1261 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1262 * @current_image: One of ec_image.
1263 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1264 */
1265struct ec_response_get_version_v1 {
1266 char version_string_ro[32];
1267 char version_string_rw[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08001268 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
Rob Barnes5ab14662021-09-17 10:24:45 -06001269 uint32_t current_image;
Caveh Jalali024ffe32023-01-30 14:35:19 -08001270 char cros_fwid_rw[32]; /* Added in version 1 */
Rob Barnes5ab14662021-09-17 10:24:45 -06001271} __ec_align4;
1272
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001273/* Read test - DEPRECATED */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001274#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001275
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001276/*
1277 * Get build information
1278 *
1279 * Response is null-terminated string.
1280 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001281#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001282
1283/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001284#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001285
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001286/**
1287 * struct ec_response_get_chip_info - Response to the get chip info command.
1288 * @vendor: Null-terminated string for chip vendor.
1289 * @name: Null-terminated string for chip name.
1290 * @revision: Null-terminated string for chip mask version.
1291 */
1292struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001293 char vendor[32];
1294 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001295 char revision[32];
1296} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001297
1298/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001299#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001301/**
1302 * struct ec_response_board_version - Response to the board version command.
1303 * @board_version: A monotonously incrementing number.
1304 */
1305struct ec_response_board_version {
1306 uint16_t board_version;
1307} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001308
1309/*
1310 * Read memory-mapped data.
1311 *
1312 * This is an alternate interface to memory-mapped data for bus protocols
1313 * which don't support direct-mapped memory - I2C, SPI, etc.
1314 *
1315 * Response is params.size bytes of data.
1316 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001317#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001318
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001319/**
1320 * struct ec_params_read_memmap - Parameters for the read memory map command.
1321 * @offset: Offset in memmap (EC_MEMMAP_*).
1322 * @size: Size to read in bytes.
1323 */
1324struct ec_params_read_memmap {
1325 uint8_t offset;
1326 uint8_t size;
1327} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001328
1329/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001330#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001331
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001332/**
1333 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1334 * @cmd: Command to check.
1335 */
1336struct ec_params_get_cmd_versions {
1337 uint8_t cmd;
1338} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001339
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001340/**
1341 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1342 * versions (v1)
1343 * @cmd: Command to check.
1344 */
1345struct ec_params_get_cmd_versions_v1 {
1346 uint16_t cmd;
1347} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001348
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001349/**
1350 * struct ec_response_get_cmd_version - Response to the get command versions.
1351 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1352 * a desired version.
1353 */
1354struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001355 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001356} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001357
Duncan Laurie433432b2013-06-03 10:38:22 -07001358/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001359 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001360 * on lpc since it has its own out-of-band busy indicator.
1361 *
1362 * lpc must read the status from the command register. Attempting this on
1363 * lpc will overwrite the args/parameter space and corrupt its data.
1364 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001365#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001366
1367/* Avoid using ec_status which is for return values */
1368enum ec_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001369 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001370};
1371
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001372/**
1373 * struct ec_response_get_comms_status - Response to the get comms status
1374 * command.
1375 * @flags: Mask of enum ec_comms_status.
1376 */
1377struct ec_response_get_comms_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001378 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001379} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001380
Duncan Laurie93e24442014-01-06 12:30:52 -08001381/* Fake a variety of responses, purely for testing purposes. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001382#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001383
1384/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001385struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001386 uint32_t ec_result;
1387 uint32_t ret_len;
1388 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001389} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001390
1391/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001392struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001393 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001394} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001395
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001396/* Get protocol information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001397#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001398
1399/* Flags for ec_response_get_protocol_info.flags */
1400/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001401#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001402
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001403/**
1404 * struct ec_response_get_protocol_info - Response to the get protocol info.
1405 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1406 * version n).
1407 * @max_request_packet_size: Maximum request packet size in bytes.
1408 * @max_response_packet_size: Maximum response packet size in bytes.
1409 * @flags: see EC_PROTOCOL_INFO_*
1410 */
1411struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001412 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001413 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001414 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001415 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001416 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001417} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001418
Duncan Laurie93e24442014-01-06 12:30:52 -08001419/*****************************************************************************/
1420/* Get/Set miscellaneous values */
1421
1422/* The upper byte of .flags tells what to do (nothing means "get") */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001423#define EC_GSV_SET 0x80000000
Duncan Laurie93e24442014-01-06 12:30:52 -08001424
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001425/*
1426 * The lower three bytes of .flags identifies the parameter, if that has
1427 * meaning for an individual command.
1428 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001429#define EC_GSV_PARAM_MASK 0x00ffffff
1430
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001431struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001432 uint32_t flags;
1433 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001434} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001435
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001436struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001437 uint32_t flags;
1438 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001439} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001440
Duncan Laurieeb316852015-12-01 18:51:18 -08001441/* More than one command can use these structs to get/set parameters. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001442#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001443
Duncan Laurieeb316852015-12-01 18:51:18 -08001444/*****************************************************************************/
1445/* List the features supported by the firmware */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001446#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001447
1448/* Supported features */
1449enum ec_feature_code {
1450 /*
1451 * This image contains a limited set of features. Another image
1452 * in RW partition may support more features.
1453 */
1454 EC_FEATURE_LIMITED = 0,
1455 /*
1456 * Commands for probing/reading/writing/erasing the flash in the
1457 * EC are present.
1458 */
1459 EC_FEATURE_FLASH = 1,
1460 /*
1461 * Can control the fan speed directly.
1462 */
1463 EC_FEATURE_PWM_FAN = 2,
1464 /*
1465 * Can control the intensity of the keyboard backlight.
1466 */
1467 EC_FEATURE_PWM_KEYB = 3,
1468 /*
1469 * Support Google lightbar, introduced on Pixel.
1470 */
1471 EC_FEATURE_LIGHTBAR = 4,
1472 /* Control of LEDs */
1473 EC_FEATURE_LED = 5,
1474 /* Exposes an interface to control gyro and sensors.
1475 * The host goes through the EC to access these sensors.
1476 * In addition, the EC may provide composite sensors, like lid angle.
1477 */
1478 EC_FEATURE_MOTION_SENSE = 6,
1479 /* The keyboard is controlled by the EC */
1480 EC_FEATURE_KEYB = 7,
1481 /* The AP can use part of the EC flash as persistent storage. */
1482 EC_FEATURE_PSTORE = 8,
1483 /* The EC monitors BIOS port 80h, and can return POST codes. */
1484 EC_FEATURE_PORT80 = 9,
1485 /*
1486 * Thermal management: include TMP specific commands.
1487 * Higher level than direct fan control.
1488 */
1489 EC_FEATURE_THERMAL = 10,
1490 /* Can switch the screen backlight on/off */
1491 EC_FEATURE_BKLIGHT_SWITCH = 11,
1492 /* Can switch the wifi module on/off */
1493 EC_FEATURE_WIFI_SWITCH = 12,
1494 /* Monitor host events, through for example SMI or SCI */
1495 EC_FEATURE_HOST_EVENTS = 13,
1496 /* The EC exposes GPIO commands to control/monitor connected devices. */
1497 EC_FEATURE_GPIO = 14,
1498 /* The EC can send i2c messages to downstream devices. */
1499 EC_FEATURE_I2C = 15,
1500 /* Command to control charger are included */
1501 EC_FEATURE_CHARGER = 16,
1502 /* Simple battery support. */
1503 EC_FEATURE_BATTERY = 17,
1504 /*
1505 * Support Smart battery protocol
1506 * (Common Smart Battery System Interface Specification)
1507 */
1508 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001509 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001510 EC_FEATURE_HANG_DETECT = 19,
1511 /* Report power information, for pit only */
1512 EC_FEATURE_PMU = 20,
1513 /* Another Cros EC device is present downstream of this one */
1514 EC_FEATURE_SUB_MCU = 21,
1515 /* Support USB Power delivery (PD) commands */
1516 EC_FEATURE_USB_PD = 22,
1517 /* Control USB multiplexer, for audio through USB port for instance. */
1518 EC_FEATURE_USB_MUX = 23,
1519 /* Motion Sensor code has an internal software FIFO */
1520 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1521 /* Support temporary secure vstore */
1522 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001523 /* EC decides on USB-C SS mux state, muxes configured by host */
1524 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1525 /* EC has RTC feature that can be controlled by host commands */
1526 EC_FEATURE_RTC = 27,
1527 /* The MCU exposes a Fingerprint sensor */
1528 EC_FEATURE_FINGERPRINT = 28,
1529 /* The MCU exposes a Touchpad */
1530 EC_FEATURE_TOUCHPAD = 29,
1531 /* The MCU has RWSIG task enabled */
1532 EC_FEATURE_RWSIG = 30,
1533 /* EC has device events support */
1534 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001535 /* EC supports the unified wake masks for LPC/eSPI systems */
1536 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001537 /* EC supports 64-bit host events */
1538 EC_FEATURE_HOST_EVENT64 = 33,
1539 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1540 EC_FEATURE_EXEC_IN_RAM = 34,
1541 /* EC supports CEC commands */
1542 EC_FEATURE_CEC = 35,
1543 /* EC supports tight sensor timestamping. */
1544 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001545 /*
1546 * EC supports tablet mode detection aligned to Chrome and allows
1547 * setting of threshold by host command using
1548 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1549 */
1550 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001551 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001552 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001553 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1554 * be sent to RO to be precise.
1555 */
1556 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001557 /* The MCU is a System Companion Processor (SCP). */
1558 EC_FEATURE_SCP = 39,
1559 /* The MCU is an Integrated Sensor Hub */
1560 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001561 /* New TCPMv2 TYPEC_ prefaced commands supported */
1562 EC_FEATURE_TYPEC_CMD = 41,
1563 /*
1564 * The EC will wait for direction from the AP to enter Type-C alternate
1565 * modes or USB4.
1566 */
1567 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1568 /*
1569 * The EC will wait for an acknowledge from the AP after setting the
1570 * mux.
1571 */
1572 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001573 /*
1574 * The EC supports entering and residing in S4.
1575 */
1576 EC_FEATURE_S4_RESIDENCY = 44,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08001577 /*
1578 * The EC supports the AP directing mux sets for the board.
1579 */
1580 EC_FEATURE_TYPEC_AP_MUX_SET = 45,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001581 /*
1582 * The EC supports the AP composing VDMs for us to send.
1583 */
1584 EC_FEATURE_TYPEC_AP_VDM_SEND = 46,
Duncan Laurieeb316852015-12-01 18:51:18 -08001585};
1586
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001587#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1588#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1589
1590struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001591 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001592} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001593
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001594/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001595/* Get the board's SKU ID from EC */
1596#define EC_CMD_GET_SKU_ID 0x000E
1597
Kevin Chiue2bb0592017-09-12 09:13:41 +08001598/* Set SKU ID from AP */
1599#define EC_CMD_SET_SKU_ID 0x000F
1600
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001601struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001602 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001603} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001604
1605/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001606/* Flash commands */
1607
1608/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001609#define EC_CMD_FLASH_INFO 0x0010
1610#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001611
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001612/**
1613 * struct ec_response_flash_info - Response to the flash info command.
1614 * @flash_size: Usable flash size in bytes.
1615 * @write_block_size: Write block size. Write offset and size must be a
1616 * multiple of this.
1617 * @erase_block_size: Erase block size. Erase offset and size must be a
1618 * multiple of this.
1619 * @protect_block_size: Protection block size. Protection offset and size
1620 * must be a multiple of this.
1621 *
1622 * Version 0 returns these fields.
1623 */
1624struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001625 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001626 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001627 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001628 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001629} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001630
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001631/*
1632 * Flags for version 1+ flash info command
1633 * EC flash erases bits to 0 instead of 1.
1634 */
1635#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001636
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001637/*
1638 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001639 * be necessary on a chip where write/erase can be corrupted by other board
1640 * activity, or where the chip needs to enable some sort of programming voltage,
1641 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001642 * chip functionality.
1643 */
1644#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001645
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001646/**
1647 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1648 * @flash_size: Usable flash size in bytes.
1649 * @write_block_size: Write block size. Write offset and size must be a
1650 * multiple of this.
1651 * @erase_block_size: Erase block size. Erase offset and size must be a
1652 * multiple of this.
1653 * @protect_block_size: Protection block size. Protection offset and size
1654 * must be a multiple of this.
1655 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1656 * size is exactly this and offset is a multiple of this.
1657 * For example, an EC may have a write buffer which can do
1658 * half-page operations if data is aligned, and a slower
1659 * word-at-a-time write mode.
1660 * @flags: Flags; see EC_FLASH_INFO_*
1661 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001662 * Version 1 returns the same initial fields as version 0, with additional
1663 * fields following.
1664 *
1665 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001666 * if they did we'd define the version 0 structure as a sub-structure of this
1667 * one.
1668 *
1669 * Version 2 supports flash banks of different sizes:
1670 * The caller specified the number of banks it has preallocated
1671 * (num_banks_desc)
1672 * The EC returns the number of banks describing the flash memory.
1673 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001674 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001675struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001676 /* Version 0 fields; see above for description */
1677 uint32_t flash_size;
1678 uint32_t write_block_size;
1679 uint32_t erase_block_size;
1680 uint32_t protect_block_size;
1681
1682 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001683 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001684 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001685} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001686
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001687struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001688 /* Number of banks to describe */
1689 uint16_t num_banks_desc;
1690 /* Reserved; set 0; ignore on read */
1691 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001692} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001693
1694struct ec_flash_bank {
1695 /* Number of sector is in this bank. */
1696 uint16_t count;
1697 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1698 uint8_t size_exp;
1699 /* Minimal write size for the sectors in this bank */
1700 uint8_t write_size_exp;
1701 /* Erase size for the sectors in this bank */
1702 uint8_t erase_size_exp;
1703 /* Size for write protection, usually identical to erase size. */
1704 uint8_t protect_size_exp;
1705 /* Reserved; set 0; ignore on read */
1706 uint8_t reserved[2];
1707};
1708
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001709struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001710 /* Total flash in the EC. */
1711 uint32_t flash_size;
1712 /* Flags; see EC_FLASH_INFO_* */
1713 uint32_t flags;
1714 /* Maximum size to use to send data to write to the EC. */
1715 uint32_t write_ideal_size;
1716 /* Number of banks present in the EC. */
1717 uint16_t num_banks_total;
1718 /* Number of banks described in banks array. */
1719 uint16_t num_banks_desc;
1720 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001721} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001722
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001723/*
1724 * Read flash
1725 *
1726 * Response is params.size bytes of data.
1727 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001728#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001729
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001730/**
1731 * struct ec_params_flash_read - Parameters for the flash read command.
1732 * @offset: Byte offset to read.
1733 * @size: Size to read in bytes.
1734 */
1735struct ec_params_flash_read {
1736 uint32_t offset;
1737 uint32_t size;
1738} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001739
1740/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001741#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001742#define EC_VER_FLASH_WRITE 1
1743
1744/* Version 0 of the flash command supported only 64 bytes of data */
1745#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001746
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001747/**
1748 * struct ec_params_flash_write - Parameters for the flash write command.
1749 * @offset: Byte offset to write.
1750 * @size: Size to write in bytes.
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001751 * @data: Data to write.
1752 * @data.words32: uint32_t data to write.
1753 * @data.bytes: uint8_t data to write.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001754 */
1755struct ec_params_flash_write {
1756 uint32_t offset;
1757 uint32_t size;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001758 /* Followed by data to write. This union allows accessing an
1759 * underlying buffer as uint32s or uint8s for convenience.
1760 */
1761 union {
1762 uint32_t words32[FLEXIBLE_ARRAY_MEMBER_SIZE];
1763 uint8_t bytes[FLEXIBLE_ARRAY_MEMBER_SIZE];
1764 } data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001765} __ec_align4;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001766BUILD_ASSERT(member_size(struct ec_params_flash_write, data) == 0);
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001767
1768/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001769#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001770
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001771/**
1772 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1773 * @offset: Byte offset to erase.
1774 * @size: Size to erase in bytes.
1775 */
1776struct ec_params_flash_erase {
1777 uint32_t offset;
1778 uint32_t size;
1779} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001780
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001781/*
1782 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001783 * subcommands can returns:
1784 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1785 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1786 * EC_RES_ERROR : other errors.
1787 * EC_RES_BUSY : an existing erase operation is in progress.
1788 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1789 *
1790 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1791 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1792 * the proper result.
1793 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1794 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1795 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1796 * permitted while erasing. (For instance, STM32F4).
1797 */
1798enum ec_flash_erase_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001799 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1800 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1801 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001802};
1803
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001804/**
1805 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1806 * @cmd: One of ec_flash_erase_cmd.
1807 * @reserved: Pad byte; currently always contains 0.
1808 * @flag: No flags defined yet; set to 0.
1809 * @params: Same as v0 parameters.
1810 */
1811struct ec_params_flash_erase_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001812 uint8_t cmd;
1813 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001814 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001815 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001816} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001817
1818/*
1819 * Get/set flash protection.
1820 *
1821 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1822 * firmware write protect GPIO, not all flags will take effect immediately;
1823 * some flags require a subsequent hard reset to take effect. Check the
1824 * returned flags bits to see what actually happened.
1825 *
1826 * If mask=0, simply returns the current flags state.
1827 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001828#define EC_CMD_FLASH_PROTECT 0x0015
Caveh Jalali024ffe32023-01-30 14:35:19 -08001829#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001830
1831/* Flags for flash protection */
1832/* RO flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001833#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001834/*
1835 * RO flash code protected now. If this bit is set, at-boot status cannot
1836 * be changed.
1837 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001838#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001839/* Entire flash code protected now, until reboot. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001840#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001841/* Flash write protect GPIO is asserted now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001842#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001843/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001844#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001845/*
1846 * Error - flash protection is in inconsistent state. At least one bank of
1847 * flash which should be protected is not protected. Usually fixed by
1848 * re-requesting the desired flags, or by a hard reset if that fails.
1849 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001850#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001851/* Entire flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001852#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001853/* RW flash code protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001854#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001855/* RW flash code protected now. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001856#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001857/* Rollback information flash region protected when the EC boots */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001858#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001859/* Rollback information flash region protected now */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001860#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001861/* Error - Unknown error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001862#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001863
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001864/**
1865 * struct ec_params_flash_protect - Parameters for the flash protect command.
1866 * @mask: Bits in flags to apply.
1867 * @flags: New flags to apply.
1868 */
1869struct ec_params_flash_protect {
1870 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001871 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001872} __ec_align4;
1873
1874/**
1875 * struct ec_response_flash_protect - Response to the flash protect command.
1876 * @flags: Current value of flash protect flags.
1877 * @valid_flags: Flags which are valid on this platform. This allows the
1878 * caller to distinguish between flags which aren't set vs. flags
1879 * which can't be set on this platform.
1880 * @writable_flags: Flags which can be changed given the current protection
1881 * state.
1882 */
1883struct ec_response_flash_protect {
1884 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001885 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001886 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001887} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001888
1889/*
1890 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1891 * write protect. These commands may be reused with version > 0.
1892 */
1893
1894/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001895#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001896#define EC_VER_FLASH_REGION_INFO 1
1897
1898enum ec_flash_region {
1899 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001900 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001901 /*
1902 * Region which holds active RW image. 'Active' is different from
1903 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1904 * scheduled to run, active/non-active applies only to RW images (for
1905 * the same reason 'update' applies only to RW images. It's a state of
1906 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1907 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1908 * doesn't enter 'running' state but it's still active on a flash.
1909 */
1910 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001911 /*
1912 * Region which should be write-protected in the factory (a superset of
1913 * EC_FLASH_REGION_RO)
1914 */
1915 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001916 /* Region which holds updatable (non-active) RW image */
1917 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001918 /* Number of regions */
1919 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001920};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001921/*
1922 * 'RW' is vague if there are multiple RW images; we mean the active one,
1923 * so the old constant is deprecated.
1924 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001925#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001926
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001927/**
1928 * struct ec_params_flash_region_info - Parameters for the flash region info
1929 * command.
1930 * @region: Flash region; see EC_FLASH_REGION_*
1931 */
1932struct ec_params_flash_region_info {
1933 uint32_t region;
1934} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001935
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001936struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001937 uint32_t offset;
1938 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001939} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001940
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001941/* Get SPI flash information */
1942#define EC_CMD_FLASH_SPI_INFO 0x0018
1943
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001944struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001945 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1946 uint8_t jedec[3];
1947
1948 /* Pad byte; currently always contains 0 */
1949 uint8_t reserved0;
1950
1951 /* Manufacturer / device ID from command 0x90 */
1952 uint8_t mfr_dev_id[2];
1953
1954 /* Status registers from command 0x05 and 0x35 */
1955 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001956} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001957
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001958/* Select flash during flash operations */
1959#define EC_CMD_FLASH_SELECT 0x0019
1960
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001961/**
1962 * struct ec_params_flash_select - Parameters for the flash select command.
1963 * @select: 1 to select flash, 0 to deselect flash
1964 */
1965struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001966 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001967} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001968
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001969/**
1970 * Request random numbers to be generated and returned.
1971 * Can be used to test the random number generator is truly random.
1972 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1973 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1974 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08001975#define EC_CMD_RAND_NUM 0x001A
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001976#define EC_VER_RAND_NUM 0
1977
1978struct ec_params_rand_num {
Caveh Jalali024ffe32023-01-30 14:35:19 -08001979 uint16_t num_rand_bytes; /**< num random bytes to generate */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001980} __ec_align4;
1981
1982struct ec_response_rand_num {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08001983 /**
1984 * generated random numbers in the range of 1 to EC_MAX_INSIZE. The true
1985 * size of rand is determined by ec_params_rand_num's num_rand_bytes.
1986 */
1987 uint8_t rand[FLEXIBLE_ARRAY_MEMBER_SIZE];
1988} __ec_align1;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001989BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1990
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001991/**
1992 * Get information about the key used to sign the RW firmware.
1993 * For more details on the fields, see "struct vb21_packed_key".
1994 */
1995#define EC_CMD_RWSIG_INFO 0x001B
1996#define EC_VER_RWSIG_INFO 0
1997
1998#define VBOOT2_KEY_ID_BYTES 20
1999
2000#ifdef CHROMIUM_EC
2001/* Don't force external projects to depend on the vboot headers. */
2002#include "vb21_struct.h"
2003BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
2004#endif
2005
2006struct ec_response_rwsig_info {
2007 /**
2008 * Signature algorithm used by the key
2009 * (enum vb2_signature_algorithm).
2010 */
2011 uint16_t sig_alg;
2012
2013 /**
2014 * Hash digest algorithm used with the key
2015 * (enum vb2_hash_algorithm).
2016 */
2017 uint16_t hash_alg;
2018
2019 /** Key version. */
2020 uint32_t key_version;
2021
2022 /** Key ID (struct vb2_id). */
2023 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
2024
2025 uint8_t key_is_valid;
2026
2027 /** Alignment padding. */
2028 uint8_t reserved[3];
2029} __ec_align4;
2030
2031BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
2032
2033/**
2034 * Get information about the system, such as reset flags, locked state, etc.
2035 */
2036#define EC_CMD_SYSINFO 0x001C
2037#define EC_VER_SYSINFO 0
2038
2039enum sysinfo_flags {
2040 SYSTEM_IS_LOCKED = BIT(0),
2041 SYSTEM_IS_FORCE_LOCKED = BIT(1),
2042 SYSTEM_JUMP_ENABLED = BIT(2),
2043 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08002044 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
2045 /*
2046 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
2047 * set and cleared when the system shuts down (not when the host event
2048 * flag is cleared).
2049 */
2050 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002051};
2052
2053struct ec_response_sysinfo {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002054 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002055 uint32_t current_image; /**< enum ec_image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002056 uint32_t flags; /**< enum sysinfo_flags */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002057} __ec_align4;
2058
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002059/*****************************************************************************/
2060/* PWM commands */
2061
2062/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002063#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002064
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002065struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002066 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002067} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002068
2069/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002070#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002071
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002072/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002073struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002074 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002075} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002076
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002077/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002078struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002079 uint32_t rpm;
2080 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002081} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002082
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002083/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002084/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002085#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002086
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002087struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002088 uint8_t percent;
2089 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002090} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002091
2092/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002093/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002094#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002095
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002096struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002097 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002098} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002099
2100/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002101#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002103/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002104struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002105 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002106} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002107
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002108/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002109struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002110 uint32_t percent;
2111 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002112} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002113
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002114#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002115/* 16 bit duty cycle, 0xffff = 100% */
2116#define EC_PWM_MAX_DUTY 0xffff
2117
2118enum ec_pwm_type {
2119 /* All types, indexed by board-specific enum pwm_channel */
2120 EC_PWM_TYPE_GENERIC = 0,
2121 /* Keyboard backlight */
2122 EC_PWM_TYPE_KB_LIGHT,
2123 /* Display backlight */
2124 EC_PWM_TYPE_DISPLAY_LIGHT,
2125 EC_PWM_TYPE_COUNT,
2126};
2127
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002128struct ec_params_pwm_set_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002129 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2130 uint8_t pwm_type; /* ec_pwm_type */
2131 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002132} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002133
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002134#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002135
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002136struct ec_params_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002137 uint8_t pwm_type; /* ec_pwm_type */
2138 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002139} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002140
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002141struct ec_response_pwm_get_duty {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002142 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002143} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002144
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002145/*****************************************************************************/
2146/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002147 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002148 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2149 * into a subcommand. We'll make separate structs for subcommands with
2150 * different input args, so that we know how much to expect.
2151 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002152#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002153
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002154struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002155 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002156} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002157
Duncan Laurie433432b2013-06-03 10:38:22 -07002158#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002159
2160/*
2161 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002162 * host command, but the alignment is the same regardless. Keep it that way.
2163 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002164struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002165 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002166 int32_t google_ramp_up;
2167 int32_t google_ramp_down;
2168 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002169 int32_t s0_tick_delay[2]; /* AC=0/1 */
2170 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie93e24442014-01-06 12:30:52 -08002171 int32_t s0s3_ramp_down;
2172 int32_t s3_sleep_for;
2173 int32_t s3_ramp_up;
2174 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002175
2176 /* Oscillation */
2177 uint8_t new_s0;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002178 uint8_t osc_min[2]; /* AC=0/1 */
2179 uint8_t osc_max[2]; /* AC=0/1 */
2180 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002181
2182 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002183 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2184 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2185 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002186
2187 /* Battery level thresholds */
2188 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2189
2190 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002191 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2192 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie433432b2013-06-03 10:38:22 -07002193
2194 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002195 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002196} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002197
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002198struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002199 /* Timing */
2200 int32_t google_ramp_up;
2201 int32_t google_ramp_down;
2202 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002203 int32_t s0_tick_delay[2]; /* AC=0/1 */
2204 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002205 int32_t s0s3_ramp_down;
2206 int32_t s3_sleep_for;
2207 int32_t s3_ramp_up;
2208 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002209 int32_t s5_ramp_up;
2210 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002211 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002212 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002213 int32_t tap_display_time;
2214
2215 /* Tap-for-battery params */
2216 uint8_t tap_pct_red;
2217 uint8_t tap_pct_green;
2218 uint8_t tap_seg_min_on;
2219 uint8_t tap_seg_max_on;
2220 uint8_t tap_seg_osc;
2221 uint8_t tap_idx[3];
2222
2223 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002224 uint8_t osc_min[2]; /* AC=0/1 */
2225 uint8_t osc_max[2]; /* AC=0/1 */
2226 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002227
2228 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002229 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2230 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2231 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002232
2233 /* Battery level thresholds */
2234 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2235
2236 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002237 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2238 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002239
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002240 /* s5: single color pulse on inhibited power-up */
2241 uint8_t s5_idx;
2242
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002243 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002244 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002245} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002246
Duncan Laurieeb316852015-12-01 18:51:18 -08002247/* Lightbar command params v2
2248 * crbug.com/467716
2249 *
2250 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2251 * logical groups to make it more manageable ( < 120 bytes).
2252 *
2253 * NOTE: Each of these groups must be less than 120 bytes.
2254 */
2255
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002256struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002257 /* Timing */
2258 int32_t google_ramp_up;
2259 int32_t google_ramp_down;
2260 int32_t s3s0_ramp_up;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002261 int32_t s0_tick_delay[2]; /* AC=0/1 */
2262 int32_t s0a_tick_delay[2]; /* AC=0/1 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002263 int32_t s0s3_ramp_down;
2264 int32_t s3_sleep_for;
2265 int32_t s3_ramp_up;
2266 int32_t s3_ramp_down;
2267 int32_t s5_ramp_up;
2268 int32_t s5_ramp_down;
2269 int32_t tap_tick_delay;
2270 int32_t tap_gate_delay;
2271 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002272} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002273
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002274struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002275 /* Tap-for-battery params */
2276 uint8_t tap_pct_red;
2277 uint8_t tap_pct_green;
2278 uint8_t tap_seg_min_on;
2279 uint8_t tap_seg_max_on;
2280 uint8_t tap_seg_osc;
2281 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002282} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002283
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002284struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002285 /* Oscillation */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002286 uint8_t osc_min[2]; /* AC=0/1 */
2287 uint8_t osc_max[2]; /* AC=0/1 */
2288 uint8_t w_ofs[2]; /* AC=0/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_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002292 /* Brightness limits based on the backlight and AC. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002293 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2294 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2295 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002296} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002297
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002298struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002299 /* Battery level thresholds */
2300 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
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 +08002303struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002304 /* Map [AC][battery_level] to color index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002305 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2306 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
Duncan Laurieeb316852015-12-01 18:51:18 -08002307
2308 /* s5: single color pulse on inhibited power-up */
2309 uint8_t s5_idx;
2310
2311 /* Color palette */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002312 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002313} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002314
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002315/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002316#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002317struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002318 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002319 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002320} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002321
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002322struct ec_params_lightbar {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002323 uint8_t cmd; /* Command (see enum lightbar_command) */
Duncan Laurie433432b2013-06-03 10:38:22 -07002324 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002325 /*
2326 * The following commands have no args:
2327 *
2328 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2329 * version, get_brightness, get_demo, suspend, resume,
2330 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2331 * get_params_v2_bright, get_params_v2_thlds,
2332 * get_params_v2_colors
2333 *
2334 * Don't use an empty struct, because C++ hates that.
2335 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002336
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002337 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002338 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002339 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002340
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002341 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002342 uint8_t ctrl, reg, value;
2343 } reg;
2344
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002345 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002346 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002347 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002348
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002349 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002350 uint8_t led;
2351 } get_rgb;
2352
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002353 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002354 uint8_t enable;
2355 } manual_suspend_ctrl;
2356
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002357 struct lightbar_params_v0 set_params_v0;
2358 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002359
2360 struct lightbar_params_v2_timing set_v2par_timing;
2361 struct lightbar_params_v2_tap set_v2par_tap;
2362 struct lightbar_params_v2_oscillation set_v2par_osc;
2363 struct lightbar_params_v2_brightness set_v2par_bright;
2364 struct lightbar_params_v2_thresholds set_v2par_thlds;
2365 struct lightbar_params_v2_colors set_v2par_colors;
2366
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002367 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002368 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002369} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002370
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002371struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002372 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002373 struct __ec_todo_unpacked {
2374 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002375 uint8_t reg;
2376 uint8_t ic0;
2377 uint8_t ic1;
2378 } vals[23];
2379 } dump;
2380
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002381 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002382 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002383 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002384
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002385 struct lightbar_params_v0 get_params_v0;
2386 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002387
Duncan Laurieeb316852015-12-01 18:51:18 -08002388 struct lightbar_params_v2_timing get_params_v2_timing;
2389 struct lightbar_params_v2_tap get_params_v2_tap;
2390 struct lightbar_params_v2_oscillation get_params_v2_osc;
2391 struct lightbar_params_v2_brightness get_params_v2_bright;
2392 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2393 struct lightbar_params_v2_colors get_params_v2_colors;
2394
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002395 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002396 uint32_t num;
2397 uint32_t flags;
2398 } version;
2399
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002400 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002401 uint8_t red, green, blue;
2402 } get_rgb;
2403
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002404 /*
2405 * The following commands have no response:
2406 *
2407 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2408 * set_params_v0, set_params_v1, set_program,
2409 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2410 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2411 * set_v2par_thlds, set_v2par_colors
2412 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002413 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002414} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002415
2416/* Lightbar commands */
2417enum lightbar_command {
2418 LIGHTBAR_CMD_DUMP = 0,
2419 LIGHTBAR_CMD_OFF = 1,
2420 LIGHTBAR_CMD_ON = 2,
2421 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002422 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002423 LIGHTBAR_CMD_SEQ = 5,
2424 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002425 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002426 LIGHTBAR_CMD_GET_SEQ = 8,
2427 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002428 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2429 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002430 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002431 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2432 LIGHTBAR_CMD_GET_RGB = 14,
2433 LIGHTBAR_CMD_GET_DEMO = 15,
2434 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2435 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002436 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002437 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2438 LIGHTBAR_CMD_SUSPEND = 20,
2439 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002440 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2441 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2442 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2443 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2444 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2445 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2446 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2447 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2448 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2449 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2450 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2451 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002452 LIGHTBAR_NUM_CMDS,
Duncan Laurie433432b2013-06-03 10:38:22 -07002453};
2454
2455/*****************************************************************************/
2456/* LED control commands */
2457
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002458#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002459
Bill Richardsone221aad2013-06-12 10:50:41 -07002460enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002461 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002462 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002463 /*
2464 * LED to indicate system power state (on or in suspend).
2465 * May be on power button or on C-panel.
2466 */
2467 EC_LED_ID_POWER_LED,
2468 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002469 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002470 /* LED to indicate left side */
2471 EC_LED_ID_LEFT_LED,
2472 /* LED to indicate right side */
2473 EC_LED_ID_RIGHT_LED,
2474 /* LED to indicate recovery mode with HW_REINIT */
2475 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2476 /* LED to indicate sysrq debug mode. */
2477 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002478
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002479 EC_LED_ID_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002480};
Duncan Laurie433432b2013-06-03 10:38:22 -07002481
Bill Richardsone221aad2013-06-12 10:50:41 -07002482/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002483#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002484#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002485
2486enum ec_led_colors {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002487 EC_LED_COLOR_INVALID = -1,
Bill Richardsone221aad2013-06-12 10:50:41 -07002488 EC_LED_COLOR_RED = 0,
2489 EC_LED_COLOR_GREEN,
2490 EC_LED_COLOR_BLUE,
2491 EC_LED_COLOR_YELLOW,
2492 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002493 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002494
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002495 EC_LED_COLOR_COUNT,
Bill Richardsone221aad2013-06-12 10:50:41 -07002496};
2497
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002498struct ec_params_led_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002499 uint8_t led_id; /* Which LED to control */
2500 uint8_t flags; /* Control flags */
Bill Richardsone221aad2013-06-12 10:50:41 -07002501
2502 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002503} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002504
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002505struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002506 /*
2507 * Available brightness value range.
2508 *
2509 * Range 0 means color channel not present.
2510 * Range 1 means on/off control.
2511 * Other values means the LED is control by PWM.
2512 */
2513 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002514} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002515
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002516/*****************************************************************************/
2517/* Verified boot commands */
2518
2519/*
2520 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2521 * reused for other purposes with version > 0.
2522 */
2523
2524/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002525#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002526
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002527struct ec_params_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002528 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2529 uint8_t hash_type; /* enum ec_vboot_hash_type */
2530 uint8_t nonce_size; /* Nonce size; may be 0 */
2531 uint8_t reserved0; /* Reserved; set 0 */
2532 uint32_t offset; /* Offset in flash to hash */
2533 uint32_t size; /* Number of bytes to hash */
2534 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002535} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002536
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002537struct ec_response_vboot_hash {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002538 uint8_t status; /* enum ec_vboot_hash_status */
2539 uint8_t hash_type; /* enum ec_vboot_hash_type */
2540 uint8_t digest_size; /* Size of hash digest in bytes */
2541 uint8_t reserved0; /* Ignore; will be 0 */
2542 uint32_t offset; /* Offset in flash which was hashed */
2543 uint32_t size; /* Number of bytes hashed */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002544 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002545} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002546
2547enum ec_vboot_hash_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002548 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2549 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2550 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2551 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002552};
2553
2554enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002555 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002556};
2557
2558enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002559 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2560 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2561 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002562};
2563
Duncan Laurie433432b2013-06-03 10:38:22 -07002564/*
2565 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2566 * If one of these is specified, the EC will automatically update offset and
2567 * size to the correct values for the specified image (RO or RW).
2568 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002569#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2570#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2571#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002572
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002573/*
2574 * 'RW' is vague if there are multiple RW images; we mean the active one,
2575 * so the old constant is deprecated.
2576 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002577#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002578
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002579/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002580/*
2581 * Motion sense commands. We'll make separate structs for sub-commands with
2582 * different input args, so that we know how much to expect.
2583 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002584#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002585
2586/* Motion sense commands */
2587enum motionsense_command {
2588 /*
2589 * Dump command returns all motion sensor data including motion sense
2590 * module flags and individual sensor flags.
2591 */
2592 MOTIONSENSE_CMD_DUMP = 0,
2593
2594 /*
2595 * Info command returns data describing the details of a given sensor,
2596 * including enum motionsensor_type, enum motionsensor_location, and
2597 * enum motionsensor_chip.
2598 */
2599 MOTIONSENSE_CMD_INFO = 1,
2600
2601 /*
2602 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002603 * in milliseconds.
2604 * It is per sensor, the EC run sample task at the minimum of all
2605 * sensors EC_RATE.
2606 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2607 * to collect all the sensor samples.
2608 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2609 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002610 */
2611 MOTIONSENSE_CMD_EC_RATE = 2,
2612
2613 /*
2614 * Sensor ODR command is a setter/getter command for the output data
2615 * rate of a specific motion sensor in millihertz.
2616 */
2617 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2618
2619 /*
2620 * Sensor range command is a setter/getter command for the range of
2621 * a specified motion sensor in +/-G's or +/- deg/s.
2622 */
2623 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2624
2625 /*
2626 * Setter/getter command for the keyboard wake angle. When the lid
2627 * angle is greater than this value, keyboard wake is disabled in S3,
2628 * and when the lid angle goes less than this value, keyboard wake is
2629 * enabled. Note, the lid angle measurement is an approximate,
2630 * un-calibrated value, hence the wake angle isn't exact.
2631 */
2632 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2633
Duncan Laurieeb316852015-12-01 18:51:18 -08002634 /*
2635 * Returns a single sensor data.
2636 */
2637 MOTIONSENSE_CMD_DATA = 6,
2638
2639 /*
2640 * Return sensor fifo info.
2641 */
2642 MOTIONSENSE_CMD_FIFO_INFO = 7,
2643
2644 /*
2645 * Insert a flush element in the fifo and return sensor fifo info.
2646 * The host can use that element to synchronize its operation.
2647 */
2648 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2649
2650 /*
2651 * Return a portion of the fifo.
2652 */
2653 MOTIONSENSE_CMD_FIFO_READ = 9,
2654
2655 /*
2656 * Perform low level calibration.
2657 * On sensors that support it, ask to do offset calibration.
2658 */
2659 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2660
2661 /*
2662 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002663 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002664 * The offsets can be calculated by the host, or via
2665 * PERFORM_CALIB command.
2666 */
2667 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2668
2669 /*
2670 * List available activities for a MOTION sensor.
2671 * Indicates if they are enabled or disabled.
2672 */
2673 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2674
2675 /*
2676 * Activity management
2677 * Enable/Disable activity recognition.
2678 */
2679 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2680
2681 /*
2682 * Lid Angle
2683 */
2684 MOTIONSENSE_CMD_LID_ANGLE = 14,
2685
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002686 /*
2687 * Allow the FIFO to trigger interrupt via MKBP events.
2688 * By default the FIFO does not send interrupt to process the FIFO
2689 * until the AP is ready or it is coming from a wakeup sensor.
2690 */
2691 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2692
2693 /*
2694 * Spoof the readings of the sensors. The spoofed readings can be set
2695 * to arbitrary values, or will lock to the last read actual values.
2696 */
2697 MOTIONSENSE_CMD_SPOOF = 16,
2698
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002699 /* Set lid angle for tablet mode detection. */
2700 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2701
2702 /*
2703 * Sensor Scale command is a setter/getter command for the calibration
2704 * scale.
2705 */
2706 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2707
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002708 /*
2709 * Read the current online calibration values (if available).
2710 */
2711 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2712
Yidi Lin42f79592020-09-21 18:04:10 +08002713 /*
2714 * Activity management
2715 * Retrieve current status of given activity.
2716 */
2717 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2718
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002719 /* Number of motionsense sub-commands. */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002720 MOTIONSENSE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002721};
2722
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002723/* List of motion sensor types. */
2724enum motionsensor_type {
2725 MOTIONSENSE_TYPE_ACCEL = 0,
2726 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002727 MOTIONSENSE_TYPE_MAG = 2,
2728 MOTIONSENSE_TYPE_PROX = 3,
2729 MOTIONSENSE_TYPE_LIGHT = 4,
2730 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002731 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002732 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002733 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002734 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002735};
2736
2737/* List of motion sensor locations. */
2738enum motionsensor_location {
2739 MOTIONSENSE_LOC_BASE = 0,
2740 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002741 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002742 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002743};
2744
2745/* List of motion sensor chips. */
2746enum motionsensor_chip {
2747 MOTIONSENSE_CHIP_KXCJ9 = 0,
2748 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002749 MOTIONSENSE_CHIP_BMI160 = 2,
2750 MOTIONSENSE_CHIP_SI1141 = 3,
2751 MOTIONSENSE_CHIP_SI1142 = 4,
2752 MOTIONSENSE_CHIP_SI1143 = 5,
2753 MOTIONSENSE_CHIP_KX022 = 6,
2754 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002755 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002756 MOTIONSENSE_CHIP_BMP280 = 9,
2757 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002758 MOTIONSENSE_CHIP_BH1730 = 11,
2759 MOTIONSENSE_CHIP_GPIO = 12,
2760 MOTIONSENSE_CHIP_LIS2DH = 13,
2761 MOTIONSENSE_CHIP_LSM6DSM = 14,
2762 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002763 MOTIONSENSE_CHIP_LIS2MDL = 16,
2764 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2765 MOTIONSENSE_CHIP_LSM6DSO = 18,
2766 MOTIONSENSE_CHIP_LNG2DM = 19,
2767 MOTIONSENSE_CHIP_TCS3400 = 20,
2768 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2769 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002770 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002771 MOTIONSENSE_CHIP_BMI260 = 24,
2772 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002773 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002774 MOTIONSENSE_CHIP_BMA422 = 27,
2775 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002776 MOTIONSENSE_CHIP_BMI220 = 29,
2777 MOTIONSENSE_CHIP_CM32183 = 30,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002778 MOTIONSENSE_CHIP_MAX,
2779};
2780
2781/* List of orientation positions */
2782enum motionsensor_orientation {
2783 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2784 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2785 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2786 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2787 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002788};
2789
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002790struct ec_response_activity_data {
2791 uint8_t activity; /* motionsensor_activity */
2792 uint8_t state;
2793} __ec_todo_packed;
2794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002795struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002796 /* Flags for each sensor. */
2797 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002798 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002799 uint8_t sensor_num;
2800 /* Each sensor is up to 3-axis. */
2801 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002802 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002803 /* for sensors using unsigned data */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002804 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002805 struct __ec_todo_packed {
Caveh Jalali024ffe32023-01-30 14:35:19 -08002806 uint16_t reserved;
2807 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002808 };
2809 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002810 struct ec_response_activity_data activity_data;
Caveh Jalali024ffe32023-01-30 14:35:19 -08002811 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002812 };
2813 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002814} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002815
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002816/* Response to AP reporting calibration data for a given sensor. */
2817struct ec_response_online_calibration_data {
2818 /** The calibration values. */
2819 int16_t data[3];
2820};
2821
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002822/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002823struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002824 /* Size of the fifo */
2825 uint16_t size;
2826 /* Amount of space used in the fifo */
2827 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002828 /* Timestamp recorded in us.
2829 * aka accurate timestamp when host event was triggered.
2830 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002831 uint32_t timestamp;
2832 /* Total amount of vector lost */
2833 uint16_t total_lost;
2834 /* Lost events since the last fifo_info, per sensors */
2835 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002836} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002837
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002838struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002839 uint32_t number_data;
2840 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002841} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002842
2843/* List supported activity recognition */
2844enum motionsensor_activity {
2845 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2846 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2847 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002848 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002849 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002850};
2851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002852struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002853 uint8_t sensor_num;
2854 uint8_t activity; /* one of enum motionsensor_activity */
Caveh Jalali024ffe32023-01-30 14:35:19 -08002855 uint8_t enable; /* 1: enable, 0: disable */
Duncan Laurieeb316852015-12-01 18:51:18 -08002856 uint8_t reserved;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002857 uint16_t parameters[4]; /* activity dependent parameters */
2858} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002859
2860/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002861#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002862
2863/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002864#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002865
2866/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002867 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002868 * data contains time stamp
2869 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002870#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2871#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2872#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2873#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2874#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002875
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002876#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2877
Duncan Laurieeb316852015-12-01 18:51:18 -08002878/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002879 * Send this value for the data element to only perform a read. If you
2880 * send any other value, the EC will interpret it as data to set and will
2881 * return the actual value set.
2882 */
2883#define EC_MOTION_SENSE_NO_VALUE -1
2884
Caveh Jalali6bd733b2023-01-30 17:06:31 -08002885#define EC_MOTION_SENSE_INVALID_CALIB_TEMP INT16_MIN
Duncan Laurieeb316852015-12-01 18:51:18 -08002886
2887/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2888/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002889#define MOTION_SENSE_SET_OFFSET BIT(0)
2890
2891/* Default Scale value, factor 1. */
2892#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002893
2894#define LID_ANGLE_UNRELIABLE 500
2895
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002896enum motionsense_spoof_mode {
2897 /* Disable spoof mode. */
2898 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2899
2900 /* Enable spoof mode, but use provided component values. */
2901 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2902
2903 /* Enable spoof mode, but use the current sensor values. */
2904 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2905
2906 /* Query the current spoof mode status for the sensor. */
2907 MOTIONSENSE_SPOOF_MODE_QUERY,
2908};
2909
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002910struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002911 uint8_t cmd;
2912 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002913 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002914 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002915 /*
2916 * Maximal number of sensor the host is expecting.
2917 * 0 means the host is only interested in the number
2918 * of sensors controlled by the EC.
2919 */
2920 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002921 } dump;
2922
2923 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002924 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002925 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002926 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002927 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002928 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08002929 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002930 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002931 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002932
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002933 /*
2934 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2935 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002936 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002937 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002938 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002939
2940 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002941 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2942 * Allow entering/exiting the calibration mode.
2943 */
2944 struct __ec_todo_unpacked {
2945 uint8_t sensor_num;
2946 uint8_t enable;
2947 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002948
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002949 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002950 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2951 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002952 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002953 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002954 uint8_t sensor_num;
2955
2956 /* Rounding flag, true for round-up, false for down. */
2957 uint8_t roundup;
2958
2959 uint16_t reserved;
2960
2961 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2962 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002963 } ec_rate, sensor_odr, sensor_range;
2964
2965 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002966 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002967 uint8_t sensor_num;
2968
2969 /*
2970 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2971 * the calibration information in the EC.
2972 * If unset, just retrieve calibration information.
2973 */
2974 uint16_t flags;
2975
2976 /*
2977 * Temperature at calibration, in units of 0.01 C
2978 * 0x8000: invalid / unknown.
2979 * 0x0: 0C
2980 * 0x7fff: +327.67C
2981 */
2982 int16_t temp;
2983
2984 /*
2985 * Offset for calibration.
2986 * Unit:
2987 * Accelerometer: 1/1024 g
2988 * Gyro: 1/1024 deg/s
2989 * Compass: 1/16 uT
2990 */
2991 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002992 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002993
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002994 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2995 struct __ec_todo_packed {
2996 uint8_t sensor_num;
2997
2998 /*
2999 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
3000 * the calibration information in the EC.
3001 * If unset, just retrieve calibration information.
3002 */
3003 uint16_t flags;
3004
3005 /*
3006 * Temperature at calibration, in units of 0.01 C
3007 * 0x8000: invalid / unknown.
3008 * 0x0: 0C
3009 * 0x7fff: +327.67C
3010 */
3011 int16_t temp;
3012
3013 /*
3014 * Scale for calibration:
3015 * By default scale is 1, it is encoded on 16bits:
3016 * 1 = BIT(15)
3017 * ~2 = 0xFFFF
3018 * ~0 = 0.
3019 */
3020 uint16_t scale[3];
3021 } sensor_scale;
3022
Duncan Laurieeb316852015-12-01 18:51:18 -08003023 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003024 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08003025
3026 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003027 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003028 /*
3029 * Number of expected vector to return.
3030 * EC may return less or 0 if none available.
3031 */
3032 uint32_t max_data_vector;
3033 } fifo_read;
3034
Yidi Lin42f79592020-09-21 18:04:10 +08003035 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08003036 struct ec_motion_sense_activity set_activity;
3037
3038 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003039 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003040
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003041 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
3042 struct __ec_todo_unpacked {
3043 /*
3044 * 1: enable, 0 disable fifo,
3045 * EC_MOTION_SENSE_NO_VALUE return value.
3046 */
3047 int8_t enable;
3048 } fifo_int_enable;
3049
3050 /* Used for MOTIONSENSE_CMD_SPOOF */
3051 struct __ec_todo_packed {
3052 uint8_t sensor_id;
3053
3054 /* See enum motionsense_spoof_mode. */
3055 uint8_t spoof_enable;
3056
3057 /* Ignored, used for alignment. */
3058 uint8_t reserved;
3059
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003060 union {
3061 /* Individual component values to spoof. */
3062 int16_t components[3];
3063
3064 /* Used when spoofing an activity */
3065 struct {
3066 /* enum motionsensor_activity */
3067 uint8_t activity_num;
3068
3069 /* spoof activity state */
3070 uint8_t activity_state;
3071 };
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003072 } __ec_todo_packed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003073 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003074
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003075 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3076 struct __ec_todo_unpacked {
3077 /*
3078 * Lid angle threshold for switching between tablet and
3079 * clamshell mode.
3080 */
3081 int16_t lid_angle;
3082
3083 /*
3084 * Hysteresis degree to prevent fluctuations between
3085 * clamshell and tablet mode if lid angle keeps
3086 * changing around the threshold. Lid motion driver will
3087 * use lid_angle + hys_degree to trigger tablet mode and
3088 * lid_angle - hys_degree to trigger clamshell mode.
3089 */
3090 int16_t hys_degree;
3091 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003092
3093 /*
3094 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3095 * Allow reading a single sensor's online calibration value.
3096 */
3097 struct __ec_todo_unpacked {
3098 uint8_t sensor_num;
3099 } online_calib_read;
3100
Yidi Lin42f79592020-09-21 18:04:10 +08003101 /*
3102 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3103 */
3104 struct __ec_todo_unpacked {
3105 uint8_t sensor_num;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003106 uint8_t activity; /* enum motionsensor_activity */
Yidi Lin42f79592020-09-21 18:04:10 +08003107 } get_activity;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003108 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003109} __ec_todo_packed;
3110
Jett Rinkba2edaf2020-01-14 11:49:06 -07003111enum motion_sense_cmd_info_flags {
3112 /* The sensor supports online calibration */
3113 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3114};
3115
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003116struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003117 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003118 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003119 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003120 /* Flags representing the motion sensor module. */
3121 uint8_t module_flags;
3122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003123 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003124 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003125
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003126 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003127 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003128 * for holding all the data.
3129 */
3130 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003131 } dump;
3132
3133 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003134 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003135 /* 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 } info;
3144
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003145 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3146 struct __ec_todo_unpacked {
3147 /* Should be element of enum motionsensor_type. */
3148 uint8_t type;
3149
3150 /* Should be element of enum motionsensor_location. */
3151 uint8_t location;
3152
3153 /* Should be element of enum motionsensor_chip. */
3154 uint8_t chip;
3155
3156 /* Minimum sensor sampling frequency */
3157 uint32_t min_frequency;
3158
3159 /* Maximum sensor sampling frequency */
3160 uint32_t max_frequency;
3161
3162 /* Max number of sensor events that could be in fifo */
3163 uint32_t fifo_max_event_count;
3164 } info_3;
3165
Jett Rinkba2edaf2020-01-14 11:49:06 -07003166 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3167 struct __ec_align4 {
3168 /* Should be element of enum motionsensor_type. */
3169 uint8_t type;
3170
3171 /* Should be element of enum motionsensor_location. */
3172 uint8_t location;
3173
3174 /* Should be element of enum motionsensor_chip. */
3175 uint8_t chip;
3176
3177 /* Minimum sensor sampling frequency */
3178 uint32_t min_frequency;
3179
3180 /* Maximum sensor sampling frequency */
3181 uint32_t max_frequency;
3182
3183 /* Max number of sensor events that could be in fifo */
3184 uint32_t fifo_max_event_count;
3185
3186 /*
3187 * Should be elements of
3188 * enum motion_sense_cmd_info_flags
3189 */
3190 uint32_t flags;
3191 } info_4;
3192
Duncan Laurieeb316852015-12-01 18:51:18 -08003193 /* Used for MOTIONSENSE_CMD_DATA */
3194 struct ec_response_motion_sensor_data data;
3195
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003196 /*
3197 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003198 * MOTIONSENSE_CMD_SENSOR_RANGE,
3199 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3200 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3201 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003202 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003203 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003204 /* Current value of the parameter queried. */
3205 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003206 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Caveh Jalali024ffe32023-01-30 14:35:19 -08003207 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003208
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003209 /*
3210 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3211 * PERFORM_CALIB.
3212 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003213 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003214 int16_t temp;
3215 int16_t offset[3];
3216 } sensor_offset, perform_calib;
3217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003218 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003219 struct __ec_todo_unpacked {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003220 int16_t temp;
3221 uint16_t scale[3];
3222 } sensor_scale;
3223
Duncan Laurieeb316852015-12-01 18:51:18 -08003224 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3225
3226 struct ec_response_motion_sense_fifo_data fifo_read;
3227
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003228 struct ec_response_online_calibration_data online_calib_read;
3229
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003230 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003231 uint16_t reserved;
3232 uint32_t enabled;
3233 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003234 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003235
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003236 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003237
Duncan Laurieeb316852015-12-01 18:51:18 -08003238 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003239 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003240 /*
3241 * Angle between 0 and 360 degree if available,
3242 * LID_ANGLE_UNRELIABLE otherwise.
3243 */
3244 uint16_t value;
3245 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003246
3247 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3248 struct __ec_todo_unpacked {
3249 /*
3250 * Lid angle threshold for switching between tablet and
3251 * clamshell mode.
3252 */
3253 uint16_t lid_angle;
3254
3255 /* Hysteresis degree. */
3256 uint16_t hys_degree;
3257 } tablet_mode_threshold;
3258
Yidi Lin42f79592020-09-21 18:04:10 +08003259 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3260 struct __ec_todo_unpacked {
3261 uint8_t state;
3262 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003263 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003264} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003265
3266/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003267/* Force lid open command */
3268
3269/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003270#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003272struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003273 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003274} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003275
3276/*****************************************************************************/
3277/* Configure the behavior of the power button */
3278#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3279
3280enum ec_config_power_button_flags {
3281 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003282 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003283};
3284
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003285struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003286 /* See enum ec_config_power_button_flags */
3287 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003288} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003289
3290/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003291/* USB charging control commands */
3292
3293/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003294#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003295
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003296enum usb_charge_mode {
3297 /* Disable USB port. */
3298 USB_CHARGE_MODE_DISABLED,
3299 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3300 USB_CHARGE_MODE_SDP2,
3301 /* Set USB port to Charging Downstream Port, BC 1.2. */
3302 USB_CHARGE_MODE_CDP,
3303 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3304 USB_CHARGE_MODE_DCP_SHORT,
3305 /* Enable USB port (for dumb ports). */
3306 USB_CHARGE_MODE_ENABLED,
3307 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3308 USB_CHARGE_MODE_DEFAULT,
3309
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003310 USB_CHARGE_MODE_COUNT,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003311};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003312
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003313enum usb_suspend_charge {
3314 /* Enable charging in suspend */
3315 USB_ALLOW_SUSPEND_CHARGE,
3316 /* Disable charging in suspend */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003317 USB_DISALLOW_SUSPEND_CHARGE,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003318};
3319
3320struct ec_params_usb_charge_set_mode {
3321 uint8_t usb_port_id;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003322 uint8_t mode : 7; /* enum usb_charge_mode */
3323 uint8_t inhibit_charge : 1; /* enum usb_suspend_charge */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003324} __ec_align1;
3325
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003326/*****************************************************************************/
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003327/* Tablet mode commands */
3328
3329/* Set tablet mode */
3330#define EC_CMD_SET_TABLET_MODE 0x0031
3331
3332enum tablet_mode_override {
3333 TABLET_MODE_DEFAULT,
3334 TABLET_MODE_FORCE_TABLET,
3335 TABLET_MODE_FORCE_CLAMSHELL,
3336};
3337
3338struct ec_params_set_tablet_mode {
3339 uint8_t tablet_mode; /* enum tablet_mode_override */
3340} __ec_align1;
3341
3342/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003343/* Persistent storage for host */
3344
3345/* Maximum bytes that can be read/written in a single command */
3346#define EC_PSTORE_SIZE_MAX 64
3347
3348/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003349#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003350
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003351struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003352 /* Persistent storage size, in bytes */
3353 uint32_t pstore_size;
3354 /* Access size; read/write offset and size must be a multiple of this */
3355 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003356} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003357
3358/*
3359 * Read persistent storage
3360 *
3361 * Response is params.size bytes of data.
3362 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003363#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003364
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003365struct ec_params_pstore_read {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003366 uint32_t offset; /* Byte offset to read */
3367 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003368} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003369
3370/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003371#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003372
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003373struct ec_params_pstore_write {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003374 uint32_t offset; /* Byte offset to write */
3375 uint32_t size; /* Size to write in bytes */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003376 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003377} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003378
3379/*****************************************************************************/
3380/* Real-time clock */
3381
3382/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003383struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003384 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003385} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003386
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003387struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003388 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003389} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003390
3391/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003392#define EC_CMD_RTC_GET_VALUE 0x0044
3393#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003394
3395/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003396#define EC_CMD_RTC_SET_VALUE 0x0046
3397#define EC_CMD_RTC_SET_ALARM 0x0047
3398
3399/* Pass as time param to SET_ALARM to clear the current alarm */
3400#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003401
3402/*****************************************************************************/
3403/* Port80 log access */
3404
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003405/* Maximum entries that can be read/written in a single command */
3406#define EC_PORT80_SIZE_MAX 32
3407
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003408/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003409#define EC_CMD_PORT80_LAST_BOOT 0x0048
3410#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003411
3412enum ec_port80_subcmd {
3413 EC_PORT80_GET_INFO = 0,
3414 EC_PORT80_READ_BUFFER,
3415};
3416
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003417struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003418 uint16_t subcmd;
3419 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003420 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003421 uint32_t offset;
3422 uint32_t num_entries;
3423 } read_buffer;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003424 } __ec_todo_packed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003425} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003426
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003427struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003428 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003429 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003430 uint32_t writes;
3431 uint32_t history_size;
3432 uint32_t last_boot;
3433 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003434 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003435 uint16_t codes[EC_PORT80_SIZE_MAX];
3436 } data;
3437 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003438} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003440struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003441 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003442} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003443
3444/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003445/* Temporary secure storage for host verified boot use */
3446
3447/* Number of bytes in a vstore slot */
3448#define EC_VSTORE_SLOT_SIZE 64
3449
3450/* Maximum number of vstore slots */
3451#define EC_VSTORE_SLOT_MAX 32
3452
3453/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003454#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003455struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003456 /* Indicates which slots are locked */
3457 uint32_t slot_locked;
3458 /* Total number of slots available */
3459 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003460} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003461
3462/*
3463 * Read temporary secure storage
3464 *
3465 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3466 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003467#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003468
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003469struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003470 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003471} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003472
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003473struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003474 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003475} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003476
3477/*
3478 * Write temporary secure storage and lock it.
3479 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003480#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003481
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003482struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003483 uint8_t slot; /* Slot to write to */
3484 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003485} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003486
3487/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003488/* Thermal engine commands. Note that there are two implementations. We'll
3489 * reuse the command number, but the data and behavior is incompatible.
3490 * Version 0 is what originally shipped on Link.
3491 * Version 1 separates the CPU thermal limits from the fan control.
3492 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003493
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003494#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3495#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003496
Duncan Laurie93e24442014-01-06 12:30:52 -08003497/* The version 0 structs are opaque. You have to know what they are for
3498 * the get/set commands to make any sense.
3499 */
3500
3501/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003502struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003503 uint8_t sensor_type;
3504 uint8_t threshold_id;
3505 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003506} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003507
Duncan Laurie93e24442014-01-06 12:30:52 -08003508/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003509struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003510 uint8_t sensor_type;
3511 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003512} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003513
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003514struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003515 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003516} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003517
Duncan Laurie93e24442014-01-06 12:30:52 -08003518/* The version 1 structs are visible. */
3519enum ec_temp_thresholds {
3520 EC_TEMP_THRESH_WARN = 0,
3521 EC_TEMP_THRESH_HIGH,
3522 EC_TEMP_THRESH_HALT,
3523
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003524 EC_TEMP_THRESH_COUNT,
Duncan Laurie93e24442014-01-06 12:30:52 -08003525};
3526
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003527/*
3528 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003529 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003530 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003531 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3532 * hysteresis.
3533 * For example,
3534 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3535 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3536 * EC will throttle ap when temperature >= 301 K, and release throttling when
3537 * temperature <= 299 K.
3538 *
3539 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3540 * For example,
3541 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3542 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3543 * EC will throttle ap when temperature >= 301 K, and release throttling when
3544 * temperature <= 294 K.
3545 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003546 * Note that this structure is a sub-structure of
3547 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003548 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003549struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003550 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003551 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003552 uint32_t temp_fan_off; /* no active cooling needed */
3553 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003554} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003555
3556/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003557struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003558 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003559} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003560/* This returns a struct ec_thermal_config */
3561
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003562/*
3563 * Version 1 - set config for one sensor.
3564 * Use read-modify-write for best results!
3565 */
3566struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003567 uint32_t sensor_num;
3568 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003569} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003570/* This returns no data */
3571
3572/****************************************************************************/
3573
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003574/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003575#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003576
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003577/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003578struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003579 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003580} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003581
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003582/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003583#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3584#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003585
3586/*
3587 * The original TMP006 calibration only needed four params, but now we need
3588 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3589 * the params opaque. The v1 "get" response will include the algorithm number
3590 * and how many params it requires. That way we can change the EC code without
3591 * needing to update this file. We can also use a different algorithm on each
3592 * sensor.
3593 */
3594
3595/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003596struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003597 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003598} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003599
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003600/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003601struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003602 float s0;
3603 float b0;
3604 float b1;
3605 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003606} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003607
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003608struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003609 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003610 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003611 float s0;
3612 float b0;
3613 float b1;
3614 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003615} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003616
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003617/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003618struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003619 uint8_t algorithm;
3620 uint8_t num_params;
3621 uint8_t reserved[2];
3622 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003623} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003625struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003626 uint8_t index;
3627 uint8_t algorithm;
3628 uint8_t num_params;
3629 uint8_t reserved;
3630 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003631} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003632
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003633/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003634#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003635
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003636struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003637 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003638} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003639
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003640struct ec_response_tmp006_get_raw {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003641 int32_t t; /* In 1/100 K */
3642 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003643} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003644
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003645/*****************************************************************************/
3646/* MKBP - Matrix KeyBoard Protocol */
3647
3648/*
3649 * Read key state
3650 *
3651 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3652 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003653 *
3654 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3655 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3656 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003657 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003658#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003659
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003660/*
3661 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3662 */
3663#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003664
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003665struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003666 uint32_t rows;
3667 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003668 /* Formerly "switches", which was 0. */
3669 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003670} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003671
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003672struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003673 uint8_t info_type;
3674 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003675} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003676
3677enum ec_mkbp_info_type {
3678 /*
3679 * Info about the keyboard matrix: number of rows and columns.
3680 *
3681 * Returns struct ec_response_mkbp_info.
3682 */
3683 EC_MKBP_INFO_KBD = 0,
3684
3685 /*
3686 * For buttons and switches, info about which specifically are
3687 * supported. event_type must be set to one of the values in enum
3688 * ec_mkbp_event.
3689 *
3690 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3691 * bitmask indicating which buttons or switches are present. See the
3692 * bit inidices below.
3693 */
3694 EC_MKBP_INFO_SUPPORTED = 1,
3695
3696 /*
3697 * Instantaneous state of buttons and switches.
3698 *
3699 * event_type must be set to one of the values in enum ec_mkbp_event.
3700 *
3701 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3702 * indicating the current state of the keyboard matrix.
3703 *
3704 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3705 * event state.
3706 *
3707 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3708 * state of supported buttons.
3709 *
3710 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3711 * state of supported switches.
3712 */
3713 EC_MKBP_INFO_CURRENT = 2,
3714};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003715
3716/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003717#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003718
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003719struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003720 uint8_t col;
3721 uint8_t row;
3722 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003723} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003724
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003725#define EC_CMD_GET_KEYBOARD_ID 0x0063
3726
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003727struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003728 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003729} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003730
3731enum keyboard_id {
3732 KEYBOARD_ID_UNSUPPORTED = 0,
3733 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3734};
3735
Duncan Laurie433432b2013-06-03 10:38:22 -07003736/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003737#define EC_CMD_MKBP_SET_CONFIG 0x0064
3738#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003739
3740/* flags */
3741enum mkbp_config_flags {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003742 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
Duncan Laurie433432b2013-06-03 10:38:22 -07003743};
3744
3745enum mkbp_config_valid {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003746 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3747 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3748 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3749 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3750 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3751 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3752 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003753};
3754
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003755/*
3756 * Configuration for our key scanning algorithm.
3757 *
3758 * Note that this is used as a sub-structure of
3759 * ec_{params/response}_mkbp_get_config.
3760 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003761struct ec_mkbp_config {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003762 uint32_t valid_mask; /* valid fields */
3763 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3764 uint8_t valid_flags; /* which flags are valid */
3765 uint16_t scan_period_us; /* period between start of scans */
Duncan Laurie433432b2013-06-03 10:38:22 -07003766 /* revert to interrupt mode after no activity for this long */
3767 uint32_t poll_timeout_us;
3768 /*
3769 * minimum post-scan relax time. Once we finish a scan we check
3770 * the time until we are due to start the next one. If this time is
3771 * shorter this field, we use this instead.
3772 */
3773 uint16_t min_post_scan_delay_us;
3774 /* delay between setting up output and waiting for it to settle */
3775 uint16_t output_settle_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003776 uint16_t debounce_down_us; /* time for debounce on key down */
3777 uint16_t debounce_up_us; /* time for debounce on key up */
Duncan Laurie433432b2013-06-03 10:38:22 -07003778 /* maximum depth to allow for fifo (0 = no keyscan output) */
3779 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003780} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003781
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003782struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003783 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003784} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003785
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003786struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003787 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003788} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003789
3790/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003791#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003792
3793enum ec_keyscan_seq_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003794 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3795 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3796 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3797 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3798 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003799};
3800
3801enum ec_collect_flags {
3802 /*
3803 * Indicates this scan was processed by the EC. Due to timing, some
3804 * scans may be skipped.
3805 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08003806 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003807};
3808
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003809struct ec_collect_item {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003810 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003811} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003812
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003813struct ec_params_keyscan_seq_ctrl {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003814 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
Duncan Laurie433432b2013-06-03 10:38:22 -07003815 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003816 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003817 uint8_t active; /* still active */
3818 uint8_t num_items; /* number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003819 /* Current item being presented */
3820 uint8_t cur_item;
3821 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003822 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003823 /*
3824 * Absolute time for this scan, measured from the
3825 * start of the sequence.
3826 */
3827 uint32_t time_us;
Caveh Jalali024ffe32023-01-30 14:35:19 -08003828 uint8_t scan[0]; /* keyscan data */
Duncan Laurie433432b2013-06-03 10:38:22 -07003829 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003830 struct __ec_align1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003831 uint8_t start_item; /* First item to return */
3832 uint8_t num_items; /* Number of items to return */
Duncan Laurie433432b2013-06-03 10:38:22 -07003833 } collect;
3834 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003835} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003836
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003837struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003838 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003839 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08003840 uint8_t num_items; /* Number of items */
Duncan Laurie433432b2013-06-03 10:38:22 -07003841 /* Data for each item */
3842 struct ec_collect_item item[0];
3843 } collect;
3844 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003845} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003846
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003847/*
3848 * Get the next pending MKBP event.
3849 *
3850 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3851 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003852#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003853
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003854#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3855
3856/*
3857 * We use the most significant bit of the event type to indicate to the host
3858 * that the EC has more MKBP events available to provide.
3859 */
3860#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3861
3862/* The mask to apply to get the raw event type */
3863#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3864
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003865enum ec_mkbp_event {
3866 /* Keyboard matrix changed. The event data is the new matrix state. */
3867 EC_MKBP_EVENT_KEY_MATRIX = 0,
3868
3869 /* New host event. The event data is 4 bytes of host event flags. */
3870 EC_MKBP_EVENT_HOST_EVENT = 1,
3871
Duncan Laurieeb316852015-12-01 18:51:18 -08003872 /* New Sensor FIFO data. The event data is fifo_info structure. */
3873 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3874
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003875 /* The state of the non-matrixed buttons have changed. */
3876 EC_MKBP_EVENT_BUTTON = 3,
3877
3878 /* The state of the switches have changed. */
3879 EC_MKBP_EVENT_SWITCH = 4,
3880
3881 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3882 EC_MKBP_EVENT_FINGERPRINT = 5,
3883
3884 /*
3885 * Sysrq event: send emulated sysrq. The event data is sysrq,
3886 * corresponding to the key to be pressed.
3887 */
3888 EC_MKBP_EVENT_SYSRQ = 6,
3889
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003890 /*
3891 * New 64-bit host event.
3892 * The event data is 8 bytes of host event flags.
3893 */
3894 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3895
3896 /* Notify the AP that something happened on CEC */
3897 EC_MKBP_EVENT_CEC_EVENT = 8,
3898
3899 /* Send an incoming CEC message to the AP */
3900 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3901
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003902 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3903 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3904
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003905 /* New online calibration values are available. */
3906 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3907
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003908 /* Peripheral device charger event */
3909 EC_MKBP_EVENT_PCHG = 12,
3910
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003911 /* Number of MKBP events */
3912 EC_MKBP_EVENT_COUNT,
3913};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003914BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003915
Caveh Jalali6bd733b2023-01-30 17:06:31 -08003916/* clang-format off */
3917#define EC_MKBP_EVENT_TEXT \
3918 { \
3919 [EC_MKBP_EVENT_KEY_MATRIX] = "KEY_MATRIX", \
3920 [EC_MKBP_EVENT_HOST_EVENT] = "HOST_EVENT", \
3921 [EC_MKBP_EVENT_SENSOR_FIFO] = "SENSOR_FIFO", \
3922 [EC_MKBP_EVENT_BUTTON] = "BUTTON", \
3923 [EC_MKBP_EVENT_SWITCH] = "SWITCH", \
3924 [EC_MKBP_EVENT_FINGERPRINT] = "FINGERPRINT", \
3925 [EC_MKBP_EVENT_SYSRQ] = "SYSRQ", \
3926 [EC_MKBP_EVENT_HOST_EVENT64] = "HOST_EVENT64", \
3927 [EC_MKBP_EVENT_CEC_EVENT] = "CEC_EVENT", \
3928 [EC_MKBP_EVENT_CEC_MESSAGE] = "CEC_MESSAGE", \
3929 [EC_MKBP_EVENT_DP_ALT_MODE_ENTERED] = "DP_ALT_MODE_ENTERED", \
3930 [EC_MKBP_EVENT_ONLINE_CALIBRATION] = "ONLINE_CALIBRATION", \
3931 [EC_MKBP_EVENT_PCHG] = "PCHG", \
3932 }
3933/* clang-format on */
3934
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003935union __ec_align_offset1 ec_response_get_next_data {
3936 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003937
3938 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003939 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003940 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003941
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003942 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003943 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003944 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003945 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003946 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003947
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003948 uint32_t buttons;
3949
3950 uint32_t switches;
3951
3952 uint32_t fp_events;
3953
3954 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003955
3956 /* CEC events from enum mkbp_cec_event */
3957 uint32_t cec_events;
3958};
3959
3960union __ec_align_offset1 ec_response_get_next_data_v1 {
3961 uint8_t key_matrix[16];
3962
3963 /* Unaligned */
3964 uint32_t host_event;
3965 uint64_t host_event64;
3966
3967 struct __ec_todo_unpacked {
3968 /* For aligning the fifo_info */
3969 uint8_t reserved[3];
3970 struct ec_response_motion_sense_fifo_info info;
3971 } sensor_fifo;
3972
3973 uint32_t buttons;
3974
3975 uint32_t switches;
3976
3977 uint32_t fp_events;
3978
3979 uint32_t sysrq;
3980
3981 /* CEC events from enum mkbp_cec_event */
3982 uint32_t cec_events;
3983
3984 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003985};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003986BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003987
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003988struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003989 uint8_t event_type;
3990 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003991 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003992} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003993
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003994struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003995 uint8_t event_type;
3996 /* Followed by event data if any */
3997 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003998} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003999
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004000/* Bit indices for buttons and switches.*/
4001/* Buttons */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004002#define EC_MKBP_POWER_BUTTON 0
4003#define EC_MKBP_VOL_UP 1
4004#define EC_MKBP_VOL_DOWN 2
4005#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004006
4007/* Switches */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004008#define EC_MKBP_LID_OPEN 0
4009#define EC_MKBP_TABLET_MODE 1
4010#define EC_MKBP_BASE_ATTACHED 2
4011#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004012
Gwendal Grignou880b4582016-06-20 08:49:25 -07004013/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004014#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07004015
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004016struct ec_response_keyboard_factory_test {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004017 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004018} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004019
4020/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004021#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events)&0x00FFFFFF)
4022#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events)&0x0000000F)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004023#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
Caveh Jalali024ffe32023-01-30 14:35:19 -08004024#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) \
4025 (((fpe)&0x00000FF0) >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004026#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
4027#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
Caveh Jalali024ffe32023-01-30 14:35:19 -08004028#define EC_MKBP_FP_MATCH_IDX(fpe) \
4029 (((fpe)&EC_MKBP_FP_MATCH_IDX_MASK) >> EC_MKBP_FP_MATCH_IDX_OFFSET)
4030#define EC_MKBP_FP_ENROLL BIT(27)
4031#define EC_MKBP_FP_MATCH BIT(28)
4032#define EC_MKBP_FP_FINGER_DOWN BIT(29)
4033#define EC_MKBP_FP_FINGER_UP BIT(30)
4034#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004035/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004036#define EC_MKBP_FP_ERR_ENROLL_OK 0
4037#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
4038#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
4039#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
4040#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004041/* Can be used to detect if image was usable for enrollment or not. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004042#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004043/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004044#define EC_MKBP_FP_ERR_MATCH_NO 0
4045#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
4046#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
4047#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
4048#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
4049#define EC_MKBP_FP_ERR_MATCH_YES 1
4050#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004051#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
4052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004053#define EC_CMD_MKBP_WAKE_MASK 0x0069
4054enum ec_mkbp_event_mask_action {
4055 /* Retrieve the value of a wake mask. */
4056 GET_WAKE_MASK = 0,
4057
4058 /* Set the value of a wake mask. */
4059 SET_WAKE_MASK,
4060};
4061
4062enum ec_mkbp_mask_type {
4063 /*
4064 * These are host events sent via MKBP.
4065 *
4066 * Some examples are:
4067 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
4068 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
4069 *
4070 * The only things that should be in this mask are:
4071 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
4072 */
4073 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
4074
4075 /*
4076 * These are MKBP events. Some examples are:
4077 *
4078 * EC_MKBP_EVENT_KEY_MATRIX
4079 * EC_MKBP_EVENT_SWITCH
4080 *
4081 * The only things that should be in this mask are EC_MKBP_EVENT_*.
4082 */
4083 EC_MKBP_EVENT_WAKE_MASK,
4084};
4085
4086struct ec_params_mkbp_event_wake_mask {
4087 /* One of enum ec_mkbp_event_mask_action */
4088 uint8_t action;
4089
4090 /*
4091 * Which MKBP mask are you interested in acting upon? This is one of
4092 * ec_mkbp_mask_type.
4093 */
4094 uint8_t mask_type;
4095
4096 /* If setting a new wake mask, this contains the mask to set. */
4097 uint32_t new_wake_mask;
4098};
4099
4100struct ec_response_mkbp_event_wake_mask {
4101 uint32_t wake_mask;
4102};
4103
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004104/*****************************************************************************/
4105/* Temperature sensor commands */
4106
4107/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004108#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004109
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004110struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004111 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004112} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004114struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004115 char sensor_name[32];
4116 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004117} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004118
4119/*****************************************************************************/
4120
4121/*
4122 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4123 * commands accidentally sent to the wrong interface. See the ACPI section
4124 * below.
4125 */
4126
4127/*****************************************************************************/
4128/* Host event commands */
4129
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004130/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004131/*
4132 * Host event mask params and response structures, shared by all of the host
4133 * event commands below.
4134 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004135struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004136 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004137} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004138
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004139struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004140 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004141} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004142
4143/* These all use ec_response_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004144#define EC_CMD_HOST_EVENT_GET_B 0x0087
4145#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4146#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004147#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004148
4149/* These all use ec_params_host_event_mask */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004150#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4151#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4152#define EC_CMD_HOST_EVENT_CLEAR 0x008C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004153#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
Caveh Jalali024ffe32023-01-30 14:35:19 -08004154#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004155
Jenny TC1dfc2c32017-12-14 14:24:39 +05304156/*
4157 * Unified host event programming interface - Should be used by newer versions
4158 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004159 *
4160 * EC returns:
4161 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4162 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304163 */
4164
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004165struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304166 /* Action requested by host - one of enum ec_host_event_action. */
4167 uint8_t action;
4168
4169 /*
4170 * Mask type that the host requested the action on - one of
4171 * enum ec_host_event_mask_type.
4172 */
4173 uint8_t mask_type;
4174
4175 /* Set to 0, ignore on read */
4176 uint16_t reserved;
4177
4178 /* Value to be used in case of set operations. */
4179 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004180} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304181
4182/*
4183 * Response structure returned by EC_CMD_HOST_EVENT.
4184 * Update the value on a GET request. Set to 0 on GET/CLEAR
4185 */
4186
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004187struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304188 /* Mask value in case of get operation */
4189 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004190} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304191
4192enum ec_host_event_action {
4193 /*
4194 * params.value is ignored. Value of mask_type populated
4195 * in response.value
4196 */
4197 EC_HOST_EVENT_GET,
4198
4199 /* Bits in params.value are set */
4200 EC_HOST_EVENT_SET,
4201
4202 /* Bits in params.value are cleared */
4203 EC_HOST_EVENT_CLEAR,
4204};
4205
4206enum ec_host_event_mask_type {
4207
4208 /* Main host event copy */
4209 EC_HOST_EVENT_MAIN,
4210
4211 /* Copy B of host events */
4212 EC_HOST_EVENT_B,
4213
4214 /* SCI Mask */
4215 EC_HOST_EVENT_SCI_MASK,
4216
4217 /* SMI Mask */
4218 EC_HOST_EVENT_SMI_MASK,
4219
4220 /* Mask of events that should be always reported in hostevents */
4221 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4222
4223 /* Active wake mask */
4224 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4225
4226 /* Lazy wake mask for S0ix */
4227 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4228
4229 /* Lazy wake mask for S3 */
4230 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4231
4232 /* Lazy wake mask for S5 */
4233 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4234};
4235
Caveh Jalali024ffe32023-01-30 14:35:19 -08004236#define EC_CMD_HOST_EVENT 0x00A4
Jenny TC1dfc2c32017-12-14 14:24:39 +05304237
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004238/*****************************************************************************/
4239/* Switch commands */
4240
4241/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004242#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004243
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004244struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004245 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004246} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004247
4248/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004249#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004250#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004251
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004252/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004253struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004254 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004255} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004256
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004257/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004258struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004259 /* Flags to enable now */
4260 uint8_t now_flags;
4261
4262 /* Which flags to copy from now_flags */
4263 uint8_t now_mask;
4264
4265 /*
4266 * Flags to leave enabled in S3, if they're on at the S0->S3
4267 * transition. (Other flags will be disabled by the S0->S3
4268 * transition.)
4269 */
4270 uint8_t suspend_flags;
4271
4272 /* Which flags to copy from suspend_flags */
4273 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004274} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004275
4276/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004277struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004278 /* Flags to enable now */
4279 uint8_t now_flags;
4280
4281 /* Flags to leave enabled in S3 */
4282 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004283} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004284
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004285/*****************************************************************************/
4286/* GPIO commands. Only available on EC if write protect has been disabled. */
4287
4288/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004289#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004290
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004291struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004292 char name[32];
4293 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004294} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004295
4296/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004297#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004298
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004299/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004300struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004301 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004302} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004303
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004304struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004305 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004306} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004307
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004308/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004309struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004310 uint8_t subcmd;
4311 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004312 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004313 char name[32];
4314 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004315 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004316 uint8_t index;
4317 } get_info;
4318 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004319} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004320
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004321struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004322 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004323 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004324 uint8_t val;
4325 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004326 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004327 uint8_t val;
4328 char name[32];
4329 uint32_t flags;
4330 } get_info;
4331 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004332} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004333
4334enum gpio_get_subcmd {
4335 EC_GPIO_GET_BY_NAME = 0,
4336 EC_GPIO_GET_COUNT = 1,
4337 EC_GPIO_GET_INFO = 2,
4338};
4339
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004340/*****************************************************************************/
4341/* I2C commands. Only available when flash write protect is unlocked. */
4342
Duncan Laurie93e24442014-01-06 12:30:52 -08004343/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004344 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4345 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4346 *
4347 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004348 */
4349
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004350/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004351#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004352
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004353struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004354 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004355 uint8_t read_size; /* Either 8 or 16. */
4356 uint8_t port;
4357 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004358} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004360struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004361 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004362} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004363
4364/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004365#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004366
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004367struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004368 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004369 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004370 uint8_t write_size; /* Either 8 or 16. */
4371 uint8_t port;
4372 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004373} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004374
4375/*****************************************************************************/
4376/* Charge state commands. Only available when flash write protect unlocked. */
4377
Duncan Laurie93e24442014-01-06 12:30:52 -08004378/* Force charge state machine to stop charging the battery or force it to
4379 * discharge the battery.
4380 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004381#define EC_CMD_CHARGE_CONTROL 0x0096
Scott Chao18141d8c2021-07-30 10:40:57 +08004382#define EC_VER_CHARGE_CONTROL 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004383
Duncan Laurie93e24442014-01-06 12:30:52 -08004384enum ec_charge_control_mode {
4385 CHARGE_CONTROL_NORMAL = 0,
4386 CHARGE_CONTROL_IDLE,
4387 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004388 /* Add no more entry below. */
4389 CHARGE_CONTROL_COUNT,
4390};
4391
Caveh Jalali024ffe32023-01-30 14:35:19 -08004392#define EC_CHARGE_MODE_TEXT \
4393 { \
4394 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4395 [CHARGE_CONTROL_IDLE] = "IDLE", \
4396 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
Scott Chao18141d8c2021-07-30 10:40:57 +08004397 }
4398
4399enum ec_charge_control_cmd {
4400 EC_CHARGE_CONTROL_CMD_SET = 0,
4401 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004402};
4403
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004404struct ec_params_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004405 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004406
4407 /* Below are the fields added in V2. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004408 uint8_t cmd; /* enum ec_charge_control_cmd. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004409 uint8_t reserved;
4410 /*
4411 * Lower and upper thresholds for battery sustainer. This struct isn't
4412 * named to avoid tainting foreign projects' name spaces.
4413 *
4414 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4415 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4416 * lower=-1, upper=-1.
4417 */
4418 struct {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004419 int8_t lower; /* Display SoC in percentage. */
4420 int8_t upper; /* Display SoC in percentage. */
Scott Chao18141d8c2021-07-30 10:40:57 +08004421 } sustain_soc;
4422} __ec_align4;
4423
4424/* Added in v2 */
4425struct ec_response_charge_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004426 uint32_t mode; /* enum charge_control_mode */
4427 struct { /* Battery sustainer thresholds */
Scott Chao18141d8c2021-07-30 10:40:57 +08004428 int8_t lower;
4429 int8_t upper;
4430 } sustain_soc;
4431 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004432} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004433
4434/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004435
4436/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004437#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004438
4439/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004440 * Read data from the saved snapshot. If the subcmd parameter is
4441 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4442 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4443 * end of the previous snapshot.
4444 *
4445 * The params are only looked at in version >= 1 of this command. Prior
4446 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004447 *
4448 * Response is null-terminated string. Empty string, if there is no more
4449 * remaining output.
4450 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004451#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004452
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004453enum ec_console_read_subcmd {
4454 CONSOLE_READ_NEXT = 0,
4455 CONSOLE_READ_RECENT,
4456};
Duncan Laurieeb316852015-12-01 18:51:18 -08004457
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004458struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004459 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004460} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004461
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004462/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004463
4464/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004465 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004466 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004467 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4468 * EC_RES_SUCCESS if the command was successful.
4469 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004470 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004471#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004472
Caveh Jalali024ffe32023-01-30 14:35:19 -08004473#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004474
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004475struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004476 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004477} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004478
Duncan Laurie433432b2013-06-03 10:38:22 -07004479/*****************************************************************************/
4480/* USB port mux control. */
4481
4482/*
4483 * Switch USB mux or return to automatic switching.
4484 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004485#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004486
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004487struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004488 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004489} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004490
4491/*****************************************************************************/
4492/* LDOs / FETs control. */
4493
4494enum ec_ldo_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004495 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4496 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
Duncan Laurie433432b2013-06-03 10:38:22 -07004497};
4498
4499/*
4500 * Switch on/off a LDO.
4501 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004502#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004503
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004504struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004505 uint8_t index;
4506 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004507} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004508
4509/*
4510 * Get LDO state.
4511 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004512#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004513
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004514struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004515 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004516} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004517
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004518struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004519 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004520} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004521
4522/*****************************************************************************/
4523/* Power info. */
4524
4525/*
4526 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004527 *
4528 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004529 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004530#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004531
Jett Rinkba2edaf2020-01-14 11:49:06 -07004532/*
4533 * v1 of EC_CMD_POWER_INFO
4534 */
4535enum system_power_source {
4536 /*
4537 * Haven't established which power source is used yet,
4538 * or no presence signals are available
4539 */
4540 POWER_SOURCE_UNKNOWN = 0,
4541 /* System is running on battery alone */
4542 POWER_SOURCE_BATTERY = 1,
4543 /* System is running on A/C alone */
4544 POWER_SOURCE_AC = 2,
4545 /* System is running on A/C and battery */
4546 POWER_SOURCE_AC_BATTERY = 3,
4547};
4548
4549struct ec_response_power_info_v1 {
4550 /* enum system_power_source */
4551 uint8_t system_power_source;
4552 /* Battery state-of-charge, 0-100, 0 if not present */
4553 uint8_t battery_soc;
4554 /* AC Adapter 100% rating, Watts */
4555 uint8_t ac_adapter_100pct;
4556 /* AC Adapter 10ms rating, Watts */
4557 uint8_t ac_adapter_10ms;
4558 /* Battery 1C rating, derated */
4559 uint8_t battery_1cd;
4560 /* Rest of Platform average, Watts */
4561 uint8_t rop_avg;
4562 /* Rest of Platform peak, Watts */
4563 uint8_t rop_peak;
4564 /* Nominal charger efficiency, % */
4565 uint8_t nominal_charger_eff;
4566 /* Rest of Platform VR Average Efficiency, % */
4567 uint8_t rop_avg_eff;
4568 /* Rest of Platform VR Peak Efficiency, % */
4569 uint8_t rop_peak_eff;
4570 /* SoC VR Efficiency at Average level, % */
4571 uint8_t soc_avg_eff;
4572 /* SoC VR Efficiency at Peak level, % */
4573 uint8_t soc_peak_eff;
4574 /* Intel-specific items */
4575 struct {
4576 /* Battery's level of DBPT support: 0, 2 */
4577 uint8_t batt_dbpt_support_level;
4578 /*
4579 * Maximum peak power from battery (10ms), Watts
4580 * If DBPT is not supported, this is 0
4581 */
4582 uint8_t batt_dbpt_max_peak_power;
4583 /*
4584 * Sustained peak power from battery, Watts
4585 * If DBPT is not supported, this is 0
4586 */
4587 uint8_t batt_dbpt_sus_peak_power;
4588 } intel;
4589} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004590
4591/*****************************************************************************/
4592/* I2C passthru command */
4593
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004594#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004595
Duncan Laurie433432b2013-06-03 10:38:22 -07004596/* Read data; if not present, message is a write */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004597#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004598
4599/* Mask for address */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004600#define EC_I2C_ADDR_MASK 0x3ff
Duncan Laurie433432b2013-06-03 10:38:22 -07004601
Caveh Jalali024ffe32023-01-30 14:35:19 -08004602#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4603#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004604
4605/* Any error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004606#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
Duncan Laurie433432b2013-06-03 10:38:22 -07004607
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004608struct ec_params_i2c_passthru_msg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004609 uint16_t addr_flags; /* I2C peripheral address and flags */
4610 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004611} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004612
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004613struct ec_params_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004614 uint8_t port; /* I2C port number */
4615 uint8_t num_msgs; /* Number of messages */
Duncan Laurie433432b2013-06-03 10:38:22 -07004616 struct ec_params_i2c_passthru_msg msg[];
4617 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004618} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004619
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004620struct ec_response_i2c_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004621 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4622 uint8_t num_msgs; /* Number of messages processed */
4623 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004624} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004625
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004626/*****************************************************************************/
4627/* Power button hang detect */
4628
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004629#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004630
4631/* Reasons to start hang detection timer */
4632/* Power button pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004633#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004634
4635/* Lid closed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004636#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004637
Caveh Jalali024ffe32023-01-30 14:35:19 -08004638/* Lid opened */
4639#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004640
4641/* Start of AP S3->S0 transition (booting or resuming from suspend) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004642#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004643
4644/* Reasons to cancel hang detection */
4645
4646/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004647#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004648
4649/* Any host command from AP received */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004650#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004651
4652/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004653#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004654
4655/*
4656 * If this flag is set, all the other fields are ignored, and the hang detect
4657 * timer is started. This provides the AP a way to start the hang timer
4658 * without reconfiguring any of the other hang detect settings. Note that
4659 * you must previously have configured the timeouts.
4660 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004661#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004662
4663/*
4664 * If this flag is set, all the other fields are ignored (including
4665 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4666 * without reconfiguring any of the other hang detect settings.
4667 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004668#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004669
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004670struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004671 /* Flags; see EC_HANG_* */
4672 uint32_t flags;
4673
4674 /* Timeout in msec before generating host event, if enabled */
4675 uint16_t host_event_timeout_msec;
4676
4677 /* Timeout in msec before generating warm reboot, if enabled */
4678 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004679} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004680
4681/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004682/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004683
4684/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004685 * This is the single catch-all host command to exchange data regarding the
4686 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004687 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004688#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004689
4690/* Subcommands for this host command */
4691enum charge_state_command {
4692 CHARGE_STATE_CMD_GET_STATE,
4693 CHARGE_STATE_CMD_GET_PARAM,
4694 CHARGE_STATE_CMD_SET_PARAM,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004695 CHARGE_STATE_NUM_CMDS,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004696};
4697
4698/*
4699 * Known param numbers are defined here. Ranges are reserved for board-specific
4700 * params, which are handled by the particular implementations.
4701 */
4702enum charge_state_params {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004703 /* charger voltage limit */
4704 CS_PARAM_CHG_VOLTAGE,
4705
4706 /* charger current limit */
4707 CS_PARAM_CHG_CURRENT,
4708
4709 /* charger input current limit */
4710 CS_PARAM_CHG_INPUT_CURRENT,
4711
4712 /* charger-specific status */
4713 CS_PARAM_CHG_STATUS,
4714
4715 /* charger-specific options */
4716 CS_PARAM_CHG_OPTION,
4717
4718 /*
4719 * Check if power is limited due to low battery and / or a
4720 * weak external charger. READ ONLY.
4721 */
4722 CS_PARAM_LIMIT_POWER,
4723
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004724 /* How many so far? */
4725 CS_NUM_BASE_PARAMS,
4726
4727 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4728 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4729 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4730
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004731 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4732 CS_PARAM_DEBUG_MIN = 0x20000,
4733 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4734 CS_PARAM_DEBUG_MANUAL_MODE,
4735 CS_PARAM_DEBUG_SEEMS_DEAD,
4736 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4737 CS_PARAM_DEBUG_BATT_REMOVED,
4738 CS_PARAM_DEBUG_MANUAL_CURRENT,
4739 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4740 CS_PARAM_DEBUG_MAX = 0x2ffff,
4741
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004742 /* Other custom param ranges go here... */
4743};
4744
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004745struct ec_params_charge_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004746 uint8_t cmd; /* enum charge_state_command */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004747 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004748 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004749
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004750 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004751 uint32_t param; /* enum charge_state_param */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004752 } get_param;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004753
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004754 struct __ec_todo_unpacked {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004755 uint32_t param; /* param to set */
4756 uint32_t value; /* value to set */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08004757 } set_param;
4758 } __ec_todo_packed;
Caveh Jalali024ffe32023-01-30 14:35:19 -08004759 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004760} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004761
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004762struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004763 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004764 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004765 int ac;
4766 int chg_voltage;
4767 int chg_current;
4768 int chg_input_current;
4769 int batt_state_of_charge;
4770 } get_state;
4771
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004772 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004773 uint32_t value;
4774 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004775
4776 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004777 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004778} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004779
Duncan Laurie433432b2013-06-03 10:38:22 -07004780/*
4781 * Set maximum battery charging current.
4782 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004783#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Tim Van Pattencab60602023-02-24 12:27:04 -07004784#define EC_VER_CHARGE_CURRENT_LIMIT 1
Duncan Laurie433432b2013-06-03 10:38:22 -07004785
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004786struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004787 uint32_t limit; /* in mA */
Tim Van Pattencab60602023-02-24 12:27:04 -07004788
4789 /* Added in v1 */
4790 /*
4791 * Battery state of charge is the minimum charge percentage at which
4792 * the battery charge current limit will apply.
4793 * When not set, the limit will apply regardless of state of charge.
4794 */
4795 uint8_t battery_soc; /* battery state of charge, 0-100 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004796} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004797
4798/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004799 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004800 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004801#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004802
Duncan Laurieeb316852015-12-01 18:51:18 -08004803/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004804struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004805 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4806 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004807} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004808
Duncan Laurieeb316852015-12-01 18:51:18 -08004809#define EC_POWER_LIMIT_NONE 0xffff
4810
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004811/*
4812 * Set maximum voltage & current of a dedicated charge port
4813 */
4814#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004816struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004817 uint16_t current_lim; /* in mA */
4818 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004819} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004820
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08004821/*
4822 * Get and set charging splashscreen variables
4823 */
4824#define EC_CMD_CHARGESPLASH 0x00A5
4825
4826enum ec_chargesplash_cmd {
4827 /* Get the current state variables */
4828 EC_CHARGESPLASH_GET_STATE = 0,
4829
4830 /* Indicate initialization of the display loop */
4831 EC_CHARGESPLASH_DISPLAY_READY,
4832
4833 /* Manually put the EC into the requested state */
4834 EC_CHARGESPLASH_REQUEST,
4835
4836 /* Reset all state variables */
4837 EC_CHARGESPLASH_RESET,
4838
4839 /* Manually trigger a lockout */
4840 EC_CHARGESPLASH_LOCKOUT,
4841};
4842
4843struct __ec_align1 ec_params_chargesplash {
4844 /* enum ec_chargesplash_cmd */
4845 uint8_t cmd;
4846};
4847
4848struct __ec_align1 ec_response_chargesplash {
4849 uint8_t requested;
4850 uint8_t display_initialized;
4851 uint8_t locked_out;
4852};
4853
Duncan Laurieeb316852015-12-01 18:51:18 -08004854/*****************************************************************************/
4855/* Hibernate/Deep Sleep Commands */
4856
4857/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004858#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004859
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004860struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004861 /*
4862 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4863 * current settings without changing them.
4864 */
4865 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004866} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004867
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004868struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004869 /*
4870 * The current time in seconds in which the system has been in the G3
4871 * state. This value is reset if the EC transitions out of G3.
4872 */
4873 uint32_t time_g3;
4874
4875 /*
4876 * The current time remaining in seconds until the EC should hibernate.
4877 * This value is also reset if the EC transitions out of G3.
4878 */
4879 uint32_t time_remaining;
4880
4881 /*
4882 * The current time in seconds that the EC should wait in G3 before
4883 * hibernating.
4884 */
4885 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004886} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004887
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004888/* Inform the EC when entering a sleep state */
4889#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4890
4891enum host_sleep_event {
Caveh Jalali024ffe32023-01-30 14:35:19 -08004892 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4893 HOST_SLEEP_EVENT_S3_RESUME = 2,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004894 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Caveh Jalali024ffe32023-01-30 14:35:19 -08004895 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004896 /* S3 suspend with additional enabled wake sources */
4897 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004898};
4899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004900struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004901 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004902} __ec_align1;
4903
4904/*
4905 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4906 * transition failures
4907 */
4908#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4909
4910/* Disable timeout detection for this sleep transition */
4911#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4912
4913struct ec_params_host_sleep_event_v1 {
4914 /* The type of sleep being entered or exited. */
4915 uint8_t sleep_event;
4916
4917 /* Padding */
4918 uint8_t reserved;
4919 union {
4920 /* Parameters that apply for suspend messages. */
4921 struct {
4922 /*
4923 * The timeout in milliseconds between when this message
4924 * is received and when the EC will declare sleep
4925 * transition failure if the sleep signal is not
4926 * asserted.
4927 */
4928 uint16_t sleep_timeout_ms;
4929 } suspend_params;
4930
4931 /* No parameters for non-suspend messages. */
4932 };
4933} __ec_align2;
4934
4935/* A timeout occurred when this bit is set */
4936#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4937
4938/*
4939 * The mask defining which bits correspond to the number of sleep transitions,
4940 * as well as the maximum number of suspend line transitions that will be
4941 * reported back to the host.
4942 */
4943#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4944
4945struct ec_response_host_sleep_event_v1 {
4946 union {
4947 /* Response fields that apply for resume messages. */
4948 struct {
4949 /*
4950 * The number of sleep power signal transitions that
4951 * occurred since the suspend message. The high bit
4952 * indicates a timeout occurred.
4953 */
4954 uint32_t sleep_transitions;
4955 } resume_response;
4956
4957 /* No response fields for non-resume messages. */
4958 };
4959} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004960
4961/*****************************************************************************/
4962/* Device events */
4963#define EC_CMD_DEVICE_EVENT 0x00AA
4964
4965enum ec_device_event {
4966 EC_DEVICE_EVENT_TRACKPAD,
4967 EC_DEVICE_EVENT_DSP,
4968 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004969 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004970};
4971
4972enum ec_device_event_param {
4973 /* Get and clear pending device events */
4974 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4975 /* Get device event mask */
4976 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4977 /* Set device event mask */
4978 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4979};
4980
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004981#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004982
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004983struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004984 uint32_t event_mask;
4985 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004986} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004987
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004988struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004989 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004990} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004991
Duncan Laurie433432b2013-06-03 10:38:22 -07004992/*****************************************************************************/
4993/* Smart battery pass-through */
4994
4995/* Get / Set 16-bit smart battery registers */
Caveh Jalali024ffe32023-01-30 14:35:19 -08004996#define EC_CMD_SB_READ_WORD 0x00B0
4997#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004998
4999/* Get / Set string smart battery parameters
5000 * formatted as SMBUS "block".
5001 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005002#define EC_CMD_SB_READ_BLOCK 0x00B2
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005003#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07005004
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005005struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07005006 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005007} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07005008
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005009struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07005010 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005011} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07005012
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005013struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07005014 uint8_t reg;
5015 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005016} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07005017
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005018struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07005019 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005020} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07005021
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005022struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07005023 uint8_t reg;
5024 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005025} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005026
5027/*****************************************************************************/
5028/* Battery vendor parameters
5029 *
5030 * Get or set vendor-specific parameters in the battery. Implementations may
5031 * differ between boards or batteries. On a set operation, the response
5032 * contains the actual value set, which may be rounded or clipped from the
5033 * requested value.
5034 */
5035
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005036#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005037
5038enum ec_battery_vendor_param_mode {
5039 BATTERY_VENDOR_PARAM_MODE_GET = 0,
5040 BATTERY_VENDOR_PARAM_MODE_SET,
5041};
5042
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005043struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005044 uint32_t param;
5045 uint32_t value;
5046 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005047} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005048
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005049struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005050 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005051} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005052
5053/*****************************************************************************/
5054/*
5055 * Smart Battery Firmware Update Commands
5056 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005057#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005058
5059enum ec_sb_fw_update_subcmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005060 EC_SB_FW_UPDATE_PREPARE = 0x0,
5061 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
5062 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
5063 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
5064 EC_SB_FW_UPDATE_END = 0x4,
5065 EC_SB_FW_UPDATE_STATUS = 0x5,
5066 EC_SB_FW_UPDATE_PROTECT = 0x6,
5067 EC_SB_FW_UPDATE_MAX = 0x7,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005068};
5069
5070#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
5071#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
5072#define SB_FW_UPDATE_CMD_INFO_SIZE 8
5073
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005074struct ec_sb_fw_update_header {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005075 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
5076 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005077} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005078
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005079struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005080 struct ec_sb_fw_update_header hdr;
5081 union {
5082 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
5083 /* EC_SB_FW_UPDATE_INFO = 0x1 */
5084 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
5085 /* EC_SB_FW_UPDATE_END = 0x4 */
5086 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
5087 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005088 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005089
5090 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005091 struct __ec_align4 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005092 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005093 } write;
5094 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005095} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005097struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005098 union {
5099 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005100 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005101 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
5102 } info;
5103
5104 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005105 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005106 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
5107 } status;
5108 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005109} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005110
5111/*
5112 * Entering Verified Boot Mode Command
5113 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
5114 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07005115 *
5116 * EC no longer needs to know what mode vboot has entered,
5117 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005118 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005119#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005120
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005121struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005122 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005123} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005124
Caveh Jalali024ffe32023-01-30 14:35:19 -08005125#define VBOOT_MODE_NORMAL 0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005126#define VBOOT_MODE_DEVELOPER 1
Caveh Jalali024ffe32023-01-30 14:35:19 -08005127#define VBOOT_MODE_RECOVERY 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005128
Duncan Laurie433432b2013-06-03 10:38:22 -07005129/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07005130/*
5131 * I2C passthru protection command: Protects I2C tunnels against access on
5132 * certain addresses (board-specific).
5133 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005134#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07005135
5136enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005137 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5138 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5139 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005140};
5141
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005142struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005143 uint8_t subcmd;
Caveh Jalali024ffe32023-01-30 14:35:19 -08005144 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005145} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005146
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005147struct ec_response_i2c_passthru_protect {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005148 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005149} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005150
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005151/*****************************************************************************/
5152/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005153 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005154 *
5155 * These commands are for sending and receiving message via HDMI CEC
5156 */
5157
5158#define MAX_CEC_MSG_LEN 16
5159
5160/* CEC message from the AP to be written on the CEC bus */
5161#define EC_CMD_CEC_WRITE_MSG 0x00B8
5162
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005163/**
5164 * struct ec_params_cec_write - Message to write to the CEC bus
5165 * @msg: message content to write to the CEC bus
5166 */
5167struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005168 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005169} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005170
5171/* Set various CEC parameters */
5172#define EC_CMD_CEC_SET 0x00BA
5173
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005174/**
5175 * struct ec_params_cec_set - CEC parameters set
5176 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5177 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5178 * or 1 to enable CEC functionality, in case cmd is
5179 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5180 * address between 0 and 15 or 0xff to unregister
5181 */
5182struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005183 uint8_t cmd; /* enum cec_command */
5184 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005185} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005186
5187/* Read various CEC parameters */
5188#define EC_CMD_CEC_GET 0x00BB
5189
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005190/**
5191 * struct ec_params_cec_get - CEC parameters get
5192 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5193 */
5194struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005195 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005196} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005197
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005198/**
5199 * struct ec_response_cec_get - CEC parameters get response
5200 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5201 * disabled or 1 if CEC functionality is enabled,
5202 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5203 * configured logical address between 0 and 15 or 0xff if unregistered
5204 */
5205struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005206 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005207} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005208
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005209/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005210enum cec_command {
5211 /* CEC reading, writing and events enable */
5212 CEC_CMD_ENABLE,
5213 /* CEC logical address */
5214 CEC_CMD_LOGICAL_ADDRESS,
5215};
5216
5217/* Events from CEC to AP */
5218enum mkbp_cec_event {
5219 /* Outgoing message was acknowledged by a follower */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005220 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005221 /* Outgoing message was not acknowledged */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005222 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005223};
5224
Gwendal Grignou880b4582016-06-20 08:49:25 -07005225/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005226
Jett Rinkba2edaf2020-01-14 11:49:06 -07005227/* Commands for audio codec. */
5228#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005229
Jett Rinkba2edaf2020-01-14 11:49:06 -07005230enum ec_codec_subcmd {
5231 EC_CODEC_GET_CAPABILITIES = 0x0,
5232 EC_CODEC_GET_SHM_ADDR = 0x1,
5233 EC_CODEC_SET_SHM_ADDR = 0x2,
5234 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005235};
5236
Jett Rinkba2edaf2020-01-14 11:49:06 -07005237enum ec_codec_cap {
5238 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5239 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5240 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005241};
5242
Jett Rinkba2edaf2020-01-14 11:49:06 -07005243enum ec_codec_shm_id {
5244 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5245 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5246 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005247};
5248
Jett Rinkba2edaf2020-01-14 11:49:06 -07005249enum ec_codec_shm_type {
5250 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5251 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005252};
5253
Jett Rinkba2edaf2020-01-14 11:49:06 -07005254struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5255 uint8_t shm_id;
5256 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005257};
5258
Jett Rinkba2edaf2020-01-14 11:49:06 -07005259struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5260 uint64_t phys_addr;
5261 uint32_t len;
5262 uint8_t shm_id;
5263 uint8_t reserved[3];
5264};
5265
5266struct __ec_align4 ec_param_ec_codec {
5267 uint8_t cmd; /* enum ec_codec_subcmd */
5268 uint8_t reserved[3];
5269
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005270 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005271 struct ec_param_ec_codec_get_shm_addr get_shm_addr_param;
5272 struct ec_param_ec_codec_set_shm_addr set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005273 };
5274};
5275
Jett Rinkba2edaf2020-01-14 11:49:06 -07005276struct __ec_align4 ec_response_ec_codec_get_capabilities {
5277 uint32_t capabilities;
5278};
5279
5280struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5281 uint64_t phys_addr;
5282 uint32_t len;
5283 uint8_t type;
5284 uint8_t reserved[3];
5285};
5286
5287/*****************************************************************************/
5288
5289/* Commands for DMIC on audio codec. */
5290#define EC_CMD_EC_CODEC_DMIC 0x00BD
5291
5292enum ec_codec_dmic_subcmd {
5293 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5294 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5295 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5296 EC_CODEC_DMIC_SUBCMD_COUNT,
5297};
5298
5299enum ec_codec_dmic_channel {
5300 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5301 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5302 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5303 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5304 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5305 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5306 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5307 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5308 EC_CODEC_DMIC_CHANNEL_COUNT,
5309};
5310
5311struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5312 uint8_t channel; /* enum ec_codec_dmic_channel */
5313 uint8_t gain;
5314 uint8_t reserved[2];
5315};
5316
5317struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5318 uint8_t channel; /* enum ec_codec_dmic_channel */
5319 uint8_t reserved[3];
5320};
5321
5322struct __ec_align4 ec_param_ec_codec_dmic {
5323 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5324 uint8_t reserved[3];
5325
5326 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005327 struct ec_param_ec_codec_dmic_set_gain_idx set_gain_idx_param;
5328 struct ec_param_ec_codec_dmic_get_gain_idx get_gain_idx_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005329 };
5330};
5331
5332struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5333 uint8_t max_gain;
5334};
5335
5336struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5337 uint8_t gain;
5338};
5339
5340/*****************************************************************************/
5341
5342/* Commands for I2S RX on audio codec. */
5343
5344#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5345
5346enum ec_codec_i2s_rx_subcmd {
5347 EC_CODEC_I2S_RX_ENABLE = 0x0,
5348 EC_CODEC_I2S_RX_DISABLE = 0x1,
5349 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5350 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5351 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005352 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005353 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5354};
5355
5356enum ec_codec_i2s_rx_sample_depth {
5357 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5358 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5359 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5360};
5361
5362enum ec_codec_i2s_rx_daifmt {
5363 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5364 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5365 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5366 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5367};
5368
5369struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5370 uint8_t depth;
5371 uint8_t reserved[3];
5372};
5373
5374struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5375 uint8_t left;
5376 uint8_t right;
5377 uint8_t reserved[2];
5378};
5379
5380struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5381 uint8_t daifmt;
5382 uint8_t reserved[3];
5383};
5384
5385struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5386 uint32_t bclk;
5387};
5388
5389struct __ec_align4 ec_param_ec_codec_i2s_rx {
5390 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5391 uint8_t reserved[3];
5392
5393 union {
5394 struct ec_param_ec_codec_i2s_rx_set_sample_depth
Caveh Jalali024ffe32023-01-30 14:35:19 -08005395 set_sample_depth_param;
5396 struct ec_param_ec_codec_i2s_rx_set_daifmt set_daifmt_param;
5397 struct ec_param_ec_codec_i2s_rx_set_bclk set_bclk_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005398 };
5399};
5400
5401/*****************************************************************************/
5402/* Commands for WoV on audio codec. */
5403
5404#define EC_CMD_EC_CODEC_WOV 0x00BF
5405
5406enum ec_codec_wov_subcmd {
5407 EC_CODEC_WOV_SET_LANG = 0x0,
5408 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5409 EC_CODEC_WOV_GET_LANG = 0x2,
5410 EC_CODEC_WOV_ENABLE = 0x3,
5411 EC_CODEC_WOV_DISABLE = 0x4,
5412 EC_CODEC_WOV_READ_AUDIO = 0x5,
5413 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5414 EC_CODEC_WOV_SUBCMD_COUNT,
5415};
5416
5417/*
5418 * @hash is SHA256 of the whole language model.
5419 * @total_len indicates the length of whole language model.
5420 * @offset is the cursor from the beginning of the model.
5421 * @buf is the packet buffer.
5422 * @len denotes how many bytes in the buf.
5423 */
5424struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5425 uint8_t hash[32];
5426 uint32_t total_len;
5427 uint32_t offset;
5428 uint8_t buf[128];
5429 uint32_t len;
5430};
5431
5432struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5433 uint8_t hash[32];
5434 uint32_t total_len;
5435};
5436
5437struct __ec_align4 ec_param_ec_codec_wov {
5438 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5439 uint8_t reserved[3];
5440
5441 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005442 struct ec_param_ec_codec_wov_set_lang set_lang_param;
5443 struct ec_param_ec_codec_wov_set_lang_shm set_lang_shm_param;
Jett Rinkba2edaf2020-01-14 11:49:06 -07005444 };
5445};
5446
5447struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5448 uint8_t hash[32];
5449};
5450
5451struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5452 uint8_t buf[128];
5453 uint32_t len;
5454};
5455
5456struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5457 uint32_t offset;
5458 uint32_t len;
5459};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005460
5461/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005462/* Commands for PoE PSE controller */
5463
5464#define EC_CMD_PSE 0x00C0
5465
5466enum ec_pse_subcmd {
5467 EC_PSE_STATUS = 0x0,
5468 EC_PSE_ENABLE = 0x1,
5469 EC_PSE_DISABLE = 0x2,
5470 EC_PSE_SUBCMD_COUNT,
5471};
5472
5473struct __ec_align1 ec_params_pse {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005474 uint8_t cmd; /* enum ec_pse_subcmd */
5475 uint8_t port; /* PSE port */
Yidi Lin42f79592020-09-21 18:04:10 +08005476};
5477
5478enum ec_pse_status {
5479 EC_PSE_STATUS_DISABLED = 0x0,
5480 EC_PSE_STATUS_ENABLED = 0x1,
5481 EC_PSE_STATUS_POWERED = 0x2,
5482};
5483
5484struct __ec_align1 ec_response_pse_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005485 uint8_t status; /* enum ec_pse_status */
Yidi Lin42f79592020-09-21 18:04:10 +08005486};
5487
5488/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005489/* System commands */
5490
5491/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005492 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5493 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005494 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005495#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005496
5497/* Command */
5498enum ec_reboot_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005499 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
5500 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
5501 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005502 /* (command 3 was jump to RW-B) */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005503 EC_REBOOT_COLD = 4, /* Cold-reboot */
5504 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
5505 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005506 /*
5507 * DEPRECATED: Hibernate EC and clears AP_IDLE flag.
5508 * Use EC_REBOOT_HIBERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE, instead.
5509 */
5510 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08005511 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
5512 EC_REBOOT_NO_OP = 9, /* Do nothing but apply the flags. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005513};
5514
5515/* Flags for ec_params_reboot_ec.reboot_flags */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005516#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5517#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5518#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
5519#define EC_REBOOT_FLAG_CLEAR_AP_IDLE BIT(3) /* Clear AP_IDLE flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005520
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005521struct ec_params_reboot_ec {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005522 uint8_t cmd; /* enum ec_reboot_cmd */
5523 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005524} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005525
Duncan Laurie433432b2013-06-03 10:38:22 -07005526/*
5527 * Get information on last EC panic.
5528 *
5529 * Returns variable-length platform-dependent panic information. See panic.h
5530 * for details.
5531 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005532#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005533
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005534/*****************************************************************************/
5535/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005536 * Special commands
5537 *
5538 * These do not follow the normal rules for commands. See each command for
5539 * details.
5540 */
5541
5542/*
5543 * Reboot NOW
5544 *
5545 * This command will work even when the EC LPC interface is busy, because the
5546 * reboot command is processed at interrupt level. Note that when the EC
5547 * reboots, the host will reboot too, so there is no response to this command.
5548 *
5549 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5550 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005551#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005552
5553/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005554 * Resend last response (not supported on LPC).
5555 *
5556 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5557 * there was no previous command, or the previous command's response was too
5558 * big to save.
5559 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005560#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005561
5562/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005563 * This header byte on a command indicate version 0. Any header byte less
5564 * than this means that we are talking to an old EC which doesn't support
5565 * versioning. In that case, we assume version 0.
5566 *
5567 * Header bytes greater than this indicate a later version. For example,
5568 * EC_CMD_VERSION0 + 1 means we are using version 1.
5569 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005570 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005571 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005572#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005573
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005574/*****************************************************************************/
5575/*
5576 * PD commands
5577 *
5578 * These commands are for PD MCU communication.
5579 */
5580
5581/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005582#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005583#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005584
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005585enum pd_charge_state {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005586 /* Don't change charge state */
5587 PD_CHARGE_NO_CHANGE = 0,
5588
5589 /* No charging allowed */
5590 PD_CHARGE_NONE,
5591
5592 /* 5V charging only */
5593 PD_CHARGE_5V,
5594
5595 /* Charge at max voltage */
5596 PD_CHARGE_MAX,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005597};
5598
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005599/* Status of EC being sent to PD */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005600#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005601
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005602struct ec_params_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005603 /* EC status */
5604 uint8_t status;
5605
5606 /* battery state of charge */
5607 int8_t batt_soc;
5608
5609 /* charging state (from enum pd_charge_state) */
5610 uint8_t charge_state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005611} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005612
5613/* Status of PD being sent back to EC */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005614#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5615#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005616#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005617#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5618#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5619#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5620#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
5621#define PD_STATUS_EC_INT_ACTIVE \
5622 (PD_STATUS_TCPC_ALERT_0 | PD_STATUS_TCPC_ALERT_1 | PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005623struct ec_response_pd_status {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005624 /* input current limit */
5625 uint32_t curr_lim_ma;
5626
5627 /* PD MCU status */
5628 uint16_t status;
5629
5630 /* active charging port */
5631 int8_t active_charge_port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005632} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005633
5634/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005635#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005636
5637/* PD MCU host event status bits */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005638#define PD_EVENT_UPDATE_DEVICE BIT(0)
5639#define PD_EVENT_POWER_CHANGE BIT(1)
5640#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5641#define PD_EVENT_DATA_SWAP BIT(3)
5642#define PD_EVENT_TYPEC BIT(4)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005643
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005644struct ec_response_host_event_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005645 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005646} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005647
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005648/*
5649 * Set USB type-C port role and muxes
5650 *
5651 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5652 *
5653 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5654 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005655#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005656
5657enum usb_pd_control_role {
5658 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5659 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5660 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5661 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5662 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005663 USB_PD_CTRL_ROLE_FREEZE = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005664 USB_PD_CTRL_ROLE_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005665};
5666
5667enum usb_pd_control_mux {
5668 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5669 USB_PD_CTRL_MUX_NONE = 1,
5670 USB_PD_CTRL_MUX_USB = 2,
5671 USB_PD_CTRL_MUX_DP = 3,
5672 USB_PD_CTRL_MUX_DOCK = 4,
5673 USB_PD_CTRL_MUX_AUTO = 5,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005674 USB_PD_CTRL_MUX_COUNT,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005675};
5676
Duncan Laurieeb316852015-12-01 18:51:18 -08005677enum usb_pd_control_swap {
5678 USB_PD_CTRL_SWAP_NONE = 0,
5679 USB_PD_CTRL_SWAP_DATA = 1,
5680 USB_PD_CTRL_SWAP_POWER = 2,
5681 USB_PD_CTRL_SWAP_VCONN = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005682 USB_PD_CTRL_SWAP_COUNT,
Duncan Laurieeb316852015-12-01 18:51:18 -08005683};
5684
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005685struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005686 uint8_t port;
5687 uint8_t role;
5688 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005689 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005690} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005691
Caveh Jalali024ffe32023-01-30 14:35:19 -08005692#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5693#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005694#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005695
Caveh Jalali024ffe32023-01-30 14:35:19 -08005696#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5697#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5698#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5699#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5700#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5701#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005702/* Partner unconstrained power */
5703#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6)
Duncan Laurieeb316852015-12-01 18:51:18 -08005704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005705struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005706 uint8_t enabled;
5707 uint8_t role;
5708 uint8_t polarity;
5709 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005710} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005711
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005712struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005713 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005714 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005715 uint8_t polarity;
5716 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005717} __ec_align1;
5718
Jett Rinkba2edaf2020-01-14 11:49:06 -07005719/* Possible port partner connections based on CC line states */
5720enum pd_cc_states {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005721 PD_CC_NONE = 0, /* No port partner attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005722
5723 /* From DFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005724 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
5725 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5726 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5727 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005728
5729 /* From UFP perspective */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005730 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
5731 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005732};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005733
Jett Rinkba2edaf2020-01-14 11:49:06 -07005734/* Active/Passive Cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005735#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005736/* Optical/Non-optical cable */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005737#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005738/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005739#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005740/* Active Link Uni-Direction */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005741#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005742
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005743struct ec_response_usb_pd_control_v2 {
5744 uint8_t enabled;
5745 uint8_t role;
5746 uint8_t polarity;
5747 char state[32];
Caveh Jalali024ffe32023-01-30 14:35:19 -08005748 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5749 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
5750 uint8_t reserved; /* Reserved for future use */
5751 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5752 uint8_t cable_speed; /* TBT_SS_* cable speed */
5753 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005754} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005755
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005756#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005757
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005758/* Maximum number of PD ports on a device, num_ports will be <= this */
5759#define EC_USB_PD_MAX_PORTS 8
5760
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005761struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005762 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005763} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005764
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005765#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005766
5767#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005768struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005769 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005770} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005771
5772enum usb_chg_type {
5773 USB_CHG_TYPE_NONE,
5774 USB_CHG_TYPE_PD,
5775 USB_CHG_TYPE_C,
5776 USB_CHG_TYPE_PROPRIETARY,
5777 USB_CHG_TYPE_BC12_DCP,
5778 USB_CHG_TYPE_BC12_CDP,
5779 USB_CHG_TYPE_BC12_SDP,
5780 USB_CHG_TYPE_OTHER,
5781 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005782 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005783 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005784};
5785enum usb_power_roles {
5786 USB_PD_PORT_POWER_DISCONNECTED,
5787 USB_PD_PORT_POWER_SOURCE,
5788 USB_PD_PORT_POWER_SINK,
5789 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5790};
5791
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005792struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005793 uint16_t voltage_max;
5794 uint16_t voltage_now;
5795 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005796 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005797} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005798
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005799struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005800 uint8_t role;
5801 uint8_t type;
5802 uint8_t dualrole;
5803 uint8_t reserved1;
5804 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005805 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005806} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005807
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005808/*
5809 * This command will return the number of USB PD charge port + the number
5810 * of dedicated port present.
5811 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5812 */
5813#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005814struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005815 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005816} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005817
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08005818/*
5819 * This command enable/disable dynamic PDO selection.
5820 */
5821#define EC_CMD_USB_PD_DPS_CONTROL 0x0106
5822
5823struct ec_params_usb_pd_dps_control {
5824 uint8_t enable;
5825} __ec_align1;
5826
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005827/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005828#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005829
5830enum usb_pd_fw_update_cmds {
5831 USB_PD_FW_REBOOT,
5832 USB_PD_FW_FLASH_ERASE,
5833 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005834 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005835};
5836
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005837struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005838 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005839 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005840 uint8_t port;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005841
5842 /* Size to write in bytes */
5843 uint32_t size;
5844
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005845 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005846} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005847
5848/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005849#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005850/* RW hash is first 20 bytes of SHA-256 of RW section */
5851#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005852struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005853 uint16_t dev_id;
5854 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Caveh Jalali6bd733b2023-01-30 17:06:31 -08005855
5856 /*
5857 * Reserved for alignment of current_image
5858 * TODO(rspangler) but it's not aligned!
5859 * Should have been reserved[2].
5860 */
5861 uint8_t reserved;
5862
5863 /* One of ec_image */
5864 uint32_t current_image;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005865} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005866
5867/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005868#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005869
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005870struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005871 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005872} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005873
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005874/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005875#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005876struct ec_params_usb_pd_discovery_entry {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005877 uint16_t vid; /* USB-IF VID */
5878 uint16_t pid; /* USB-IF PID */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005879 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005880} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005881
5882/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005883#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005884
5885/* Negative port parameters have special meaning */
5886enum usb_pd_override_ports {
5887 OVERRIDE_DONT_CHARGE = -2,
5888 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005889 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005890};
5891
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005892struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005893 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005894} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005895
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005896/*
5897 * Read (and delete) one entry of PD event log.
5898 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5899 * future non-PD logs that use the same internal EC event_log.
5900 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005901#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005902
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005903struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005904 uint32_t timestamp; /* relative timestamp in milliseconds */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005905 uint8_t type; /* event type : see PD_EVENT_xx below */
5906 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5907 uint16_t data; /* type-defined data payload */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005908 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005909} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005910
5911/* The timestamp is the microsecond counter shifted to get about a ms. */
5912#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5913
Caveh Jalali024ffe32023-01-30 14:35:19 -08005914#define PD_LOG_SIZE_MASK 0x1f
5915#define PD_LOG_PORT_MASK 0xe0
5916#define PD_LOG_PORT_SHIFT 5
5917#define PD_LOG_PORT_SIZE(port, size) \
5918 (((port) << PD_LOG_PORT_SHIFT) | ((size)&PD_LOG_SIZE_MASK))
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005919#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08005920#define PD_LOG_SIZE(size_port) ((size_port)&PD_LOG_SIZE_MASK)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005921
5922/* PD event log : entry types */
5923/* PD MCU events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005924#define PD_EVENT_MCU_BASE 0x00
5925#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE + 0)
5926#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005927/* Reserved for custom board event */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005928#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE + 2)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005929/* PD generic accessory events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005930#define PD_EVENT_ACC_BASE 0x20
5931#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE + 0)
5932#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005933/* PD power supply events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005934#define PD_EVENT_PS_BASE 0x40
5935#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE + 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005936/* PD video dongles events */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005937#define PD_EVENT_VIDEO_BASE 0x60
5938#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE + 0)
5939#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE + 1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005940/* Returned in the "type" field, when there is no entry available */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005941#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005942
5943/*
5944 * PD_EVENT_MCU_CHARGE event definition :
5945 * the payload is "struct usb_chg_measures"
5946 * the data field contains the port state flags as defined below :
5947 */
5948/* Port partner is a dual role device */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005949#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005950/* Port is the pending override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005951#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005952/* Port is the override port */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005953#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005954/* Charger type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005955#define CHARGE_FLAGS_TYPE_SHIFT 3
5956#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005957/* Power delivery role */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005958#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005959
5960/*
5961 * PD_EVENT_PS_FAULT data field flags definition :
5962 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005963#define PS_FAULT_OCP 1
5964#define PS_FAULT_FAST_OCP 2
5965#define PS_FAULT_OVP 3
5966#define PS_FAULT_DISCH 4
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005967
5968/*
5969 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5970 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005971struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005972 uint8_t major;
5973 uint8_t minor;
5974 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005975} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005976
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005977struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005978 uint8_t family[2];
5979 uint8_t chipid[2];
5980 struct mcdp_version irom;
5981 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005982} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005983
5984/* struct mcdp_info field decoding */
5985#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5986#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5987
5988/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005989#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005990struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005991 uint16_t svid_idx; /* SVID index to get */
Caveh Jalali024ffe32023-01-30 14:35:19 -08005992 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005993} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005994
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005995struct ec_params_usb_pd_get_mode_response {
Caveh Jalali024ffe32023-01-30 14:35:19 -08005996 uint16_t svid; /* SVID */
5997 uint16_t opos; /* Object Position */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005998 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005999} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006000
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006001#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006002
6003enum pd_mode_cmd {
6004 PD_EXIT_MODE = 0,
6005 PD_ENTER_MODE = 1,
6006 /* Not a command. Do NOT remove. */
6007 PD_MODE_CMD_COUNT,
6008};
6009
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006010struct ec_params_usb_pd_set_mode_request {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006011 uint32_t cmd; /* enum pd_mode_cmd */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006012 uint16_t svid; /* SVID to set */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006013 uint8_t opos; /* Object Position */
6014 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006015} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006016
6017/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006018#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006019
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006020struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006021 uint8_t type; /* event type : see PD_EVENT_xx above */
6022 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006023} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07006024
Gwendal Grignou880b4582016-06-20 08:49:25 -07006025/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006026#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07006027
6028enum ec_pd_control_cmd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006029 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
6030 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
6031 PD_RESET, /* Force reset the PD chip */
6032 PD_CONTROL_DISABLE, /* Disable further calls to this command */
6033 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006034};
6035
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006036struct ec_params_pd_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006037 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07006038 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006039} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07006040
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006041/* Get info about USB-C SS muxes */
6042#define EC_CMD_USB_PD_MUX_INFO 0x011A
6043
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006044struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006045 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006046} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006047
6048/* Flags representing mux state */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006049#define USB_PD_MUX_NONE 0 /* Open switch */
6050#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
6051#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
6052#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
6053#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
6054#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
6055#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
6056#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
6057#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006058#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006059#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006060
6061/* USB-C Dock connected */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006062#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006063
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006064struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006065 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006066} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006067
Caveh Jalali024ffe32023-01-30 14:35:19 -08006068#define EC_CMD_PD_CHIP_INFO 0x011B
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006069
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006070struct ec_params_pd_chip_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006071 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006072 /*
6073 * Fetch the live chip info or hard-coded + cached chip info
6074 * 0: hardcoded value for VID/PID, cached value for FW version
6075 * 1: live chip value for VID/PID/FW Version
6076 */
6077 uint8_t live;
6078} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006079
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006080struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006081 uint16_t vendor_id;
6082 uint16_t product_id;
6083 uint16_t device_id;
6084 union {
6085 uint8_t fw_version_string[8];
6086 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006087 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006088} __ec_align2;
6089
6090struct ec_response_pd_chip_info_v1 {
6091 uint16_t vendor_id;
6092 uint16_t product_id;
6093 uint16_t device_id;
6094 union {
6095 uint8_t fw_version_string[8];
6096 uint64_t fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006097 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006098 union {
6099 uint8_t min_req_fw_version_string[8];
6100 uint64_t min_req_fw_version_number;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006101 } __ec_align2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006102} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006103
6104/* Run RW signature verification and get status */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006105#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006106
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006107struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006108 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006109} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006110
6111/* For controlling RWSIG task */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006112#define EC_CMD_RWSIG_ACTION 0x011D
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006113
6114enum rwsig_action {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006115 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
6116 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006117};
6118
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006119struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006120 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006121} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006122
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006123/* Run verification on a slot */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006124#define EC_CMD_EFS_VERIFY 0x011E
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006126struct ec_params_efs_verify {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006127 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006128} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006129
6130/*
6131 * Retrieve info from Cros Board Info store. Response is based on the data
6132 * type. Integers return a uint32. Strings return a string, using the response
6133 * size to determine how big it is.
6134 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006135#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006136/*
6137 * Write info into Cros Board Info on EEPROM. Write fails if the board has
6138 * hardware write-protect enabled.
6139 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006140#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006141
Daisuke Nojirif984a052018-02-15 12:38:15 -08006142enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006143 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006144 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
6145 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06006146 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006147 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
6148 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
6149 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
6150 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08006151 /* Second Source Factory Cache */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006152 CBI_TAG_SSFC = 8, /* uint32_t bit field */
6153 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006154 CBI_TAG_FACTORY_CALIBRATION_DATA = 10, /* uint32_t bit field */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006155 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006156};
6157
6158/*
6159 * Flags to control read operation
6160 *
6161 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
6162 * write was successful without reboot.
6163 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006164#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006165
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006166struct ec_params_get_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006167 uint32_t tag; /* enum cbi_data_tag */
6168 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006169} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006170
6171/*
6172 * Flags to control write behavior.
6173 *
6174 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6175 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006176 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006177 * will be initialized to zero first.
6178 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006179#define CBI_SET_NO_SYNC BIT(0)
6180#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006181
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006182struct ec_params_set_cbi {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006183 uint32_t tag; /* enum cbi_data_tag */
6184 uint32_t flag; /* CBI_SET_* */
6185 uint32_t size; /* Data size */
6186 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006187} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006188
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006189/*
6190 * Information about resets of the AP by the EC and the EC's own uptime.
6191 */
6192#define EC_CMD_GET_UPTIME_INFO 0x0121
6193
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006194/* EC reset causes */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006195#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6196#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6197#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6198#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6199#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6200#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6201#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6202#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6203#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6204#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6205#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6206#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6207#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006208/* Some reset flags preserved from previous boot */
6209#define EC_RESET_FLAG_PRESERVED BIT(13)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006210#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6211#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6212#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6213#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006214/* AP experienced a watchdog reset */
6215#define EC_RESET_FLAG_AP_WATCHDOG BIT(18)
6216/* Do not select RW in EFS. This enables PD in RO for Chromebox. */
6217#define EC_RESET_FLAG_STAY_IN_RO BIT(19)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006218#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6219#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6220#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006221
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006222/*
6223 * Reason codes used by the AP after a shutdown to figure out why it was reset
6224 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6225 * compatibility:
6226 * - New entries must be inserted prior to the _COUNT field
6227 * - If an existing entry is no longer in service, it must be replaced with a
6228 * RESERVED entry instead.
6229 * - The semantic meaning of an entry should not change.
6230 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6231 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006232enum chipset_shutdown_reason {
6233 /*
6234 * Beginning of reset reasons.
6235 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006236 CHIPSET_RESET_BEGIN = 0,
6237 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6238 /* Custom reason defined by a board.c or baseboard.c file */
6239 CHIPSET_RESET_BOARD_CUSTOM,
6240 /* Believe that the AP has hung */
6241 CHIPSET_RESET_HANG_REBOOT,
6242 /* Reset by EC console command */
6243 CHIPSET_RESET_CONSOLE_CMD,
6244 /* Reset by EC host command */
6245 CHIPSET_RESET_HOST_CMD,
6246 /* Keyboard module reset key combination */
6247 CHIPSET_RESET_KB_SYSRESET,
6248 /* Keyboard module warm reboot */
6249 CHIPSET_RESET_KB_WARM_REBOOT,
6250 /* Debug module warm reboot */
6251 CHIPSET_RESET_DBG_WARM_REBOOT,
6252 /* I cannot self-terminate. You must lower me into the steel. */
6253 CHIPSET_RESET_AP_REQ,
6254 /* Reset as side-effect of startup sequence */
6255 CHIPSET_RESET_INIT,
6256 /* EC detected an AP watchdog event. */
6257 CHIPSET_RESET_AP_WATCHDOG,
6258
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006259 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006260
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006261 /*
6262 * Beginning of shutdown reasons.
6263 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006264 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6265 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6266 /* Forcing a shutdown as part of EC initialization */
6267 CHIPSET_SHUTDOWN_INIT,
6268 /* Custom reason on a per-board basis. */
6269 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6270 /* This is a reason to inhibit startup, not cause shut down. */
6271 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6272 /* A power_wait_signal is being asserted */
6273 CHIPSET_SHUTDOWN_WAIT,
6274 /* Critical battery level. */
6275 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6276 /* Because you told me to. */
6277 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6278 /* Forcing a shutdown to effect entry to G3. */
6279 CHIPSET_SHUTDOWN_G3,
6280 /* Force shutdown due to over-temperature. */
6281 CHIPSET_SHUTDOWN_THERMAL,
6282 /* Force a chipset shutdown from the power button through EC */
6283 CHIPSET_SHUTDOWN_BUTTON,
6284
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006285 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006286};
6287
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006288struct ec_response_uptime_info {
6289 /*
6290 * Number of milliseconds since the last EC boot. Sysjump resets
6291 * typically do not restart the EC's time_since_boot epoch.
6292 *
6293 * WARNING: The EC's sense of time is much less accurate than the AP's
6294 * sense of time, in both phase and frequency. This timebase is similar
6295 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6296 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006297 uint32_t time_since_ec_boot_ms;
6298
6299 /*
6300 * Number of times the AP was reset by the EC since the last EC boot.
6301 * Note that the AP may be held in reset by the EC during the initial
6302 * boot sequence, such that the very first AP boot may count as more
6303 * than one here.
6304 */
6305 uint32_t ap_resets_since_ec_boot;
6306
6307 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006308 * The set of flags which describe the EC's most recent reset.
6309 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006310 */
6311 uint32_t ec_reset_flags;
6312
6313 /* Empty log entries have both the cause and timestamp set to zero. */
6314 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006315 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006316 uint16_t reset_cause;
6317
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006318 /* Reserved for protocol growth. */
6319 uint16_t reserved;
6320
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006321 /*
6322 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006323 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6324 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006325 */
6326 uint32_t reset_time_ms;
6327 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006328} __ec_align4;
6329
6330/*
6331 * Add entropy to the device secret (stored in the rollback region).
6332 *
6333 * Depending on the chip, the operation may take a long time (e.g. to erase
6334 * flash), so the commands are asynchronous.
6335 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006336#define EC_CMD_ADD_ENTROPY 0x0122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006337
6338enum add_entropy_action {
6339 /* Add entropy to the current secret. */
6340 ADD_ENTROPY_ASYNC = 0,
6341 /*
6342 * Add entropy, and also make sure that the previous secret is erased.
6343 * (this can be implemented by adding entropy multiple times until
6344 * all rolback blocks have been overwritten).
6345 */
6346 ADD_ENTROPY_RESET_ASYNC = 1,
6347 /* Read back result from the previous operation. */
6348 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006349};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006350
6351struct ec_params_rollback_add_entropy {
6352 uint8_t action;
6353} __ec_align1;
6354
6355/*
6356 * Perform a single read of a given ADC channel.
6357 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006358#define EC_CMD_ADC_READ 0x0123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006359
6360struct ec_params_adc_read {
6361 uint8_t adc_channel;
6362} __ec_align1;
6363
6364struct ec_response_adc_read {
6365 int32_t adc_value;
6366} __ec_align4;
6367
6368/*
6369 * Read back rollback info
6370 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006371#define EC_CMD_ROLLBACK_INFO 0x0124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006372
6373struct ec_response_rollback_info {
6374 int32_t id; /* Incrementing number to indicate which region to use. */
6375 int32_t rollback_min_version;
6376 int32_t rw_rollback_version;
6377} __ec_align4;
6378
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006379/* Issue AP reset */
6380#define EC_CMD_AP_RESET 0x0125
6381
6382/*****************************************************************************/
6383/* Locate peripheral chips
6384 *
6385 * Return values:
6386 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6387 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6388 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6389 */
6390#define EC_CMD_LOCATE_CHIP 0x0126
6391
6392enum ec_chip_type {
6393 EC_CHIP_TYPE_CBI_EEPROM = 0,
6394 EC_CHIP_TYPE_TCPC = 1,
6395 EC_CHIP_TYPE_COUNT,
6396 EC_CHIP_TYPE_MAX = 0xFF,
6397};
6398
6399enum ec_bus_type {
6400 EC_BUS_TYPE_I2C = 0,
6401 EC_BUS_TYPE_EMBEDDED = 1,
6402 EC_BUS_TYPE_COUNT,
6403 EC_BUS_TYPE_MAX = 0xFF,
6404};
6405
6406struct ec_i2c_info {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006407 uint16_t port; /* Physical port for device */
6408 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006409};
6410
6411struct ec_params_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006412 uint8_t type; /* enum ec_chip_type */
6413 uint8_t index; /* Specifies one instance of chip type */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006414 /* Used for type specific parameters in future */
6415 union {
6416 uint16_t reserved;
6417 };
6418} __ec_align2;
6419
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006420struct ec_response_locate_chip {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006421 uint8_t bus_type; /* enum ec_bus_type */
6422 uint8_t reserved; /* Aligning the following union to 2 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006423 union {
6424 struct ec_i2c_info i2c_info;
6425 };
6426} __ec_align2;
6427
Jett Rinkba2edaf2020-01-14 11:49:06 -07006428/*
6429 * Reboot AP on G3
6430 *
6431 * This command is used for validation purpose, where the AP needs to be
6432 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006433 * wake events.
6434 * - With command version 0:
6435 * AP reboots immediately from G3
6436 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6437 * - With command version 1:
6438 * AP reboots after the user specified delay
6439 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006440 */
6441#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6442
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006443struct ec_params_reboot_ap_on_g3_v1 {
6444 /* configurable delay in seconds in G3 state */
6445 uint32_t reboot_ap_at_g3_delay;
6446} __ec_align4;
6447
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006448/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006449/* Get PD port capabilities
6450 *
6451 * Returns the following static *capabilities* of the given port:
6452 * 1) Power role: source, sink, or dual. It is not anticipated that
6453 * future CrOS devices would ever be only a source, so the options are
6454 * sink or dual.
6455 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6456 * believe any CrOS device would support Try.SNK, so this would be source
6457 * or none).
6458 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6459 * for CrOS devices.
6460 */
6461#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6462
6463enum ec_pd_power_role_caps {
6464 EC_PD_POWER_ROLE_SOURCE = 0,
6465 EC_PD_POWER_ROLE_SINK = 1,
6466 EC_PD_POWER_ROLE_DUAL = 2,
6467};
6468
6469enum ec_pd_try_power_role_caps {
6470 EC_PD_TRY_POWER_ROLE_NONE = 0,
6471 EC_PD_TRY_POWER_ROLE_SINK = 1,
6472 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6473};
6474
6475enum ec_pd_data_role_caps {
6476 EC_PD_DATA_ROLE_DFP = 0,
6477 EC_PD_DATA_ROLE_UFP = 1,
6478 EC_PD_DATA_ROLE_DUAL = 2,
6479};
6480
6481/* From: power_manager/power_supply_properties.proto */
6482enum ec_pd_port_location {
6483 /* The location of the port is unknown, or there's only one port. */
6484 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6485
6486 /*
6487 * Various positions on the device. The first word describes the side of
6488 * the device where the port is located while the second clarifies the
6489 * position. For example, LEFT_BACK means the farthest-back port on the
6490 * left side, while BACK_LEFT means the leftmost port on the back of the
6491 * device.
6492 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006493 EC_PD_PORT_LOCATION_LEFT = 1,
6494 EC_PD_PORT_LOCATION_RIGHT = 2,
6495 EC_PD_PORT_LOCATION_BACK = 3,
6496 EC_PD_PORT_LOCATION_FRONT = 4,
6497 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6498 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006499 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006500 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6501 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6502 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006503};
6504
6505struct ec_params_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006506 uint8_t port; /* Which port to interrogate */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006507} __ec_align1;
6508
6509struct ec_response_get_pd_port_caps {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006510 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6511 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6512 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6513 uint8_t pd_port_location; /* enum ec_pd_port_location */
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006514} __ec_align1;
6515
6516/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006517/*
6518 * Button press simulation
6519 *
6520 * This command is used to simulate a button press.
6521 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6522 * Time duration for which button needs to be pressed is an optional parameter.
6523 *
6524 * NOTE: This is only available on unlocked devices for testing purposes only.
6525 */
6526#define EC_CMD_BUTTON 0x0129
6527
6528struct ec_params_button {
6529 /* Button mask aligned to enum keyboard_button_type */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006530 uint32_t btn_mask;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006531
6532 /* Duration in milliseconds button needs to be pressed */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006533 uint32_t press_ms;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006534} __ec_align1;
6535
6536enum keyboard_button_type {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006537 KEYBOARD_BUTTON_POWER = 0,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006538 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
Caveh Jalali024ffe32023-01-30 14:35:19 -08006539 KEYBOARD_BUTTON_VOLUME_UP = 2,
6540 KEYBOARD_BUTTON_RECOVERY = 3,
6541 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6542 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6543 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6544 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6545 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6546 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6547 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6548 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006549
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006550 KEYBOARD_BUTTON_COUNT,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006551};
Yidi Lin42f79592020-09-21 18:04:10 +08006552
Rajat Jainc0495722020-04-02 23:58:35 -07006553/*****************************************************************************/
6554/*
6555 * "Get the Keyboard Config". An EC implementing this command is expected to be
6556 * vivaldi capable, i.e. can send action codes for the top row keys.
6557 * Additionally, capability to send function codes for the same keys is
6558 * optional and acceptable.
6559 *
6560 * Note: If the top row can generate both function and action codes by
6561 * using a dedicated Fn key, it does not matter whether the key sends
6562 * "function" or "action" codes by default. In both cases, the response
6563 * for this command will look the same.
6564 */
6565#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6566
6567/* Possible values for the top row keys */
6568enum action_key {
6569 TK_ABSENT = 0,
6570 TK_BACK = 1,
6571 TK_FORWARD = 2,
6572 TK_REFRESH = 3,
6573 TK_FULLSCREEN = 4,
6574 TK_OVERVIEW = 5,
6575 TK_BRIGHTNESS_DOWN = 6,
6576 TK_BRIGHTNESS_UP = 7,
6577 TK_VOL_MUTE = 8,
6578 TK_VOL_DOWN = 9,
6579 TK_VOL_UP = 10,
6580 TK_SNAPSHOT = 11,
6581 TK_PRIVACY_SCRN_TOGGLE = 12,
6582 TK_KBD_BKLIGHT_DOWN = 13,
6583 TK_KBD_BKLIGHT_UP = 14,
6584 TK_PLAY_PAUSE = 15,
6585 TK_NEXT_TRACK = 16,
6586 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006587 TK_KBD_BKLIGHT_TOGGLE = 18,
6588 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006589 TK_MENU = 20,
Rajat Jainc0495722020-04-02 23:58:35 -07006590};
6591
6592/*
6593 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6594 * If this needs to change, please create a new version of the command.
6595 */
6596#define MAX_TOP_ROW_KEYS 15
6597#define MIN_TOP_ROW_KEYS 10
6598
6599/*
6600 * Is the keyboard capable of sending function keys *in addition to*
6601 * action keys. This is possible for e.g. if the keyboard has a
6602 * dedicated Fn key.
6603 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006604#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
Rajat Jainc0495722020-04-02 23:58:35 -07006605/*
6606 * Whether the keyboard has a dedicated numeric keyboard.
6607 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006608#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
Rajat Jainc0495722020-04-02 23:58:35 -07006609/*
6610 * Whether the keyboard has a screenlock key.
6611 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006612#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
Rajat Jainc0495722020-04-02 23:58:35 -07006613
6614struct ec_response_keybd_config {
6615 /*
6616 * Number of top row keys, excluding Esc and Screenlock.
6617 * If this is 0, all Vivaldi keyboard code is disabled.
6618 * (i.e. does not expose any tables to the kernel).
6619 */
6620 uint8_t num_top_row_keys;
6621
6622 /*
6623 * The action keys in the top row, in order from left to right.
6624 * The values are filled from enum action_key. Esc and Screenlock
6625 * keys are not considered part of top row keys.
6626 */
6627 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6628
6629 /* Capability flags */
6630 uint8_t capabilities;
6631
6632} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006633
Yidi Lin42f79592020-09-21 18:04:10 +08006634/*
6635 * Configure smart discharge
6636 */
6637#define EC_CMD_SMART_DISCHARGE 0x012B
6638
Caveh Jalali024ffe32023-01-30 14:35:19 -08006639#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
Yidi Lin42f79592020-09-21 18:04:10 +08006640
6641/* Discharge rates when the system is in cutoff or hibernation. */
6642struct discharge_rate {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006643 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6644 uint16_t hibern; /* Discharge rate (uA) in hibernation */
Yidi Lin42f79592020-09-21 18:04:10 +08006645};
6646
6647struct smart_discharge_zone {
6648 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6649 int cutoff;
6650 /* When the capacity (mAh) is below this, EC stays up. */
6651 int stayup;
6652};
6653
6654struct ec_params_smart_discharge {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006655 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
Yidi Lin42f79592020-09-21 18:04:10 +08006656 /*
6657 * Desired hours for the battery to survive before reaching 0%. Set to
6658 * zero to disable smart discharging. That is, the system hibernates as
6659 * soon as the G3 idle timer expires.
6660 */
6661 uint16_t hours_to_zero;
6662 /* Set both to zero to keep the current rates. */
6663 struct discharge_rate drate;
6664};
6665
6666struct ec_response_smart_discharge {
6667 uint16_t hours_to_zero;
6668 struct discharge_rate drate;
6669 struct smart_discharge_zone dzone;
6670};
6671
6672/*****************************************************************************/
6673/* Voltage regulator controls */
6674
6675/*
6676 * Get basic info of voltage regulator for given index.
6677 *
6678 * Returns the regulator name and supported voltage list in mV.
6679 */
6680#define EC_CMD_REGULATOR_GET_INFO 0x012C
6681
6682/* Maximum length of regulator name */
6683#define EC_REGULATOR_NAME_MAX_LEN 16
6684
6685/* Maximum length of the supported voltage list. */
6686#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6687
6688struct ec_params_regulator_get_info {
6689 uint32_t index;
6690} __ec_align4;
6691
6692struct ec_response_regulator_get_info {
6693 char name[EC_REGULATOR_NAME_MAX_LEN];
6694 uint16_t num_voltages;
6695 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6696} __ec_align2;
6697
6698/*
6699 * Configure the regulator as enabled / disabled.
6700 */
6701#define EC_CMD_REGULATOR_ENABLE 0x012D
6702
6703struct ec_params_regulator_enable {
6704 uint32_t index;
6705 uint8_t enable;
6706} __ec_align4;
6707
6708/*
6709 * Query if the regulator is enabled.
6710 *
6711 * Returns 1 if the regulator is enabled, 0 if not.
6712 */
6713#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6714
6715struct ec_params_regulator_is_enabled {
6716 uint32_t index;
6717} __ec_align4;
6718
6719struct ec_response_regulator_is_enabled {
6720 uint8_t enabled;
6721} __ec_align1;
6722
6723/*
6724 * Set voltage for the voltage regulator within the range specified.
6725 *
6726 * The driver should select the voltage in range closest to min_mv.
6727 *
6728 * Also note that this might be called before the regulator is enabled, and the
6729 * setting should be in effect after the regulator is enabled.
6730 */
6731#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6732
6733struct ec_params_regulator_set_voltage {
6734 uint32_t index;
6735 uint32_t min_mv;
6736 uint32_t max_mv;
6737} __ec_align4;
6738
6739/*
6740 * Get the currently configured voltage for the voltage regulator.
6741 *
6742 * Note that this might be called before the regulator is enabled, and this
6743 * should return the configured output voltage if the regulator is enabled.
6744 */
6745#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6746
6747struct ec_params_regulator_get_voltage {
6748 uint32_t index;
6749} __ec_align4;
6750
6751struct ec_response_regulator_get_voltage {
6752 uint32_t voltage_mv;
6753} __ec_align4;
6754
6755/*
6756 * Gather all discovery information for the given port and partner type.
6757 *
6758 * Note that if discovery has not yet completed, only the currently completed
6759 * responses will be filled in. If the discovery data structures are changed
6760 * in the process of the command running, BUSY will be returned.
6761 *
6762 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6763 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6764 * maximum parameter size.
6765 */
6766#define EC_CMD_TYPEC_DISCOVERY 0x0131
6767
6768enum typec_partner_type {
6769 TYPEC_PARTNER_SOP = 0,
6770 TYPEC_PARTNER_SOP_PRIME = 1,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006771 TYPEC_PARTNER_SOP_PRIME_PRIME = 2,
Yidi Lin42f79592020-09-21 18:04:10 +08006772};
6773
6774struct ec_params_typec_discovery {
6775 uint8_t port;
6776 uint8_t partner_type; /* enum typec_partner_type */
6777} __ec_align1;
6778
6779struct svid_mode_info {
6780 uint16_t svid;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006781 uint16_t mode_count; /* Number of modes partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08006782 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6783};
6784
6785struct ec_response_typec_discovery {
Caveh Jalali024ffe32023-01-30 14:35:19 -08006786 uint8_t identity_count; /* Number of identity VDOs partner sent */
6787 uint8_t svid_count; /* Number of SVIDs partner sent */
Yidi Lin42f79592020-09-21 18:04:10 +08006788 uint16_t reserved;
6789 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6790 struct svid_mode_info svids[0];
6791} __ec_align1;
6792
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006793/* USB Type-C commands for AP-controlled device policy. */
6794#define EC_CMD_TYPEC_CONTROL 0x0132
6795
6796enum typec_control_command {
6797 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6798 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006799 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006800 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006801 TYPEC_CONTROL_COMMAND_USB_MUX_SET,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006802 TYPEC_CONTROL_COMMAND_BIST_SHARE_MODE,
6803 TYPEC_CONTROL_COMMAND_SEND_VDM_REQ,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006804};
6805
6806/* Modes (USB or alternate) that a type-C port may enter. */
6807enum typec_mode {
6808 TYPEC_MODE_DP,
6809 TYPEC_MODE_TBT,
6810 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006811};
6812
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006813/* Replies the AP may specify to the TBT EnterMode command as a UFP */
6814enum typec_tbt_ufp_reply {
6815 TYPEC_TBT_UFP_REPLY_NAK,
6816 TYPEC_TBT_UFP_REPLY_ACK,
6817};
6818
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006819#define TYPEC_USB_MUX_SET_ALL_CHIPS 0xFF
6820
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006821struct typec_usb_mux_set {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006822 /* Index of the mux to set in the chain */
6823 uint8_t mux_index;
6824
6825 /* USB_PD_MUX_*-encoded USB mux state to set */
6826 uint8_t mux_flags;
6827} __ec_align1;
6828
6829#define VDO_MAX_SIZE 7
6830
6831struct typec_vdm_req {
6832 /* VDM data, including VDM header */
6833 uint32_t vdm_data[VDO_MAX_SIZE];
6834 /* Number of 32-bit fields filled in */
6835 uint8_t vdm_data_objects;
6836 /* Partner to address - see enum typec_partner_type */
6837 uint8_t partner_type;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006838} __ec_align1;
6839
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006840struct ec_params_typec_control {
6841 uint8_t port;
Caveh Jalali024ffe32023-01-30 14:35:19 -08006842 uint8_t command; /* enum typec_control_command */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006843 uint16_t reserved;
6844
6845 /*
6846 * This section will be interpreted based on |command|. Define a
6847 * placeholder structure to avoid having to increase the size and bump
6848 * the command version when adding new sub-commands.
6849 */
6850 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006851 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006852 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006853 /* Used for ENTER_MODE - enum typec_mode */
6854 uint8_t mode_to_enter;
6855 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
6856 uint8_t tbt_ufp_reply;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08006857 /* Used for USB_MUX_SET */
6858 struct typec_usb_mux_set mux_params;
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006859 /* Used for BIST_SHARE_MODE */
6860 uint8_t bist_share_mode;
6861 /* Used for VMD_REQ */
6862 struct typec_vdm_req vdm_req_params;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006863 uint8_t placeholder[128];
6864 };
6865} __ec_align1;
6866
6867/*
6868 * Gather all status information for a port.
6869 *
6870 * Note: this covers many of the return fields from the deprecated
6871 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6872 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6873 * EC_CMD_USB_PD_CONTROL command.
6874 *
6875 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006876 */
6877#define EC_CMD_TYPEC_STATUS 0x0133
6878
6879/*
6880 * Power role.
6881 *
6882 * Note this is also used for PD header creation, and values align to those in
6883 * the Power Delivery Specification Revision 3.0 (See
6884 * 6.2.1.1.4 Port Power Role).
6885 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006886enum pd_power_role {
6887 PD_ROLE_SINK = 0,
6888 PD_ROLE_SOURCE = 1,
6889};
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006890
6891/*
6892 * Data role.
6893 *
6894 * Note this is also used for PD header creation, and the first two values
6895 * align to those in the Power Delivery Specification Revision 3.0 (See
6896 * 6.2.1.1.6 Port Data Role).
6897 */
6898enum pd_data_role {
6899 PD_ROLE_UFP = 0,
6900 PD_ROLE_DFP = 1,
6901 PD_ROLE_DISCONNECTED = 2,
6902};
6903
6904enum pd_vconn_role {
6905 PD_ROLE_VCONN_OFF = 0,
6906 PD_ROLE_VCONN_SRC = 1,
6907};
6908
6909/*
6910 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6911 * regardless of whether a debug accessory is connected.
6912 */
6913enum tcpc_cc_polarity {
6914 /*
6915 * _CCx: is used to indicate the polarity while not connected to
6916 * a Debug Accessory. Only one CC line will assert a resistor and
6917 * the other will be open.
6918 */
6919 POLARITY_CC1 = 0,
6920 POLARITY_CC2 = 1,
6921
6922 /*
6923 * _CCx_DTS is used to indicate the polarity while connected to a
6924 * SRC Debug Accessory. Assert resistors on both lines.
6925 */
6926 POLARITY_CC1_DTS = 2,
6927 POLARITY_CC2_DTS = 3,
6928
6929 /*
6930 * The current TCPC code relies on these specific POLARITY values.
6931 * Adding in a check to verify if the list grows for any reason
6932 * that this will give a hint that other places need to be
6933 * adjusted.
6934 */
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006935 POLARITY_COUNT,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006936};
6937
Caveh Jalali024ffe32023-01-30 14:35:19 -08006938#define MODE_DP_PIN_A BIT(0)
6939#define MODE_DP_PIN_B BIT(1)
6940#define MODE_DP_PIN_C BIT(2)
6941#define MODE_DP_PIN_D BIT(3)
6942#define MODE_DP_PIN_E BIT(4)
6943#define MODE_DP_PIN_F BIT(5)
6944#define MODE_DP_PIN_ALL GENMASK(5, 0)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006945
Caveh Jalali024ffe32023-01-30 14:35:19 -08006946#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6947#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
6948#define PD_STATUS_EVENT_HARD_RESET BIT(2)
6949#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
6950#define PD_STATUS_EVENT_MUX_0_SET_DONE BIT(4)
6951#define PD_STATUS_EVENT_MUX_1_SET_DONE BIT(5)
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006952#define PD_STATUS_EVENT_VDM_REQ_REPLY BIT(6)
6953#define PD_STATUS_EVENT_VDM_REQ_FAILED BIT(7)
6954#define PD_STATUS_EVENT_VDM_ATTENTION BIT(8)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006955
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006956/*
6957 * Encode and decode for BCD revision response
6958 *
6959 * Note: the major revision set is written assuming that the value given is the
6960 * Specification Revision from the PD header, which currently only maps to PD
6961 * 1.0-3.0 with the major revision being one greater than the binary value.
6962 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006963#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6964#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6965#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006966
6967/*
Caveh Jalali6bd733b2023-01-30 17:06:31 -08006968 * Encode revision from partner RMDO
6969 *
6970 * Unlike the specification revision given in the PD header, specification and
6971 * version information returned in the revision message data object (RMDO) is
6972 * not offset.
6973 */
6974#define PD_STATUS_RMDO_REV_SET_MAJOR(r) (r << 12)
6975#define PD_STATUS_RMDO_REV_SET_MINOR(r) (r << 8)
6976#define PD_STATUS_RMDO_VER_SET_MAJOR(r) (r << 4)
6977#define PD_STATUS_RMDO_VER_SET_MINOR(r) (r)
6978
6979/*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006980 * Decode helpers for Source and Sink Capability PDOs
6981 *
6982 * Note: The Power Delivery Specification should be considered the ultimate
6983 * source of truth on the decoding of these PDOs
6984 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08006985#define PDO_TYPE_FIXED (0 << 30)
6986#define PDO_TYPE_BATTERY (1 << 30)
6987#define PDO_TYPE_VARIABLE (2 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006988#define PDO_TYPE_AUGMENTED (3 << 30)
Caveh Jalali024ffe32023-01-30 14:35:19 -08006989#define PDO_TYPE_MASK (3 << 30)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006990
6991/*
6992 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6993 *
6994 * <31:30> : Fixed Supply
6995 * <29> : Dual-Role Power
6996 * <28> : SNK/SRC dependent
6997 * <27> : Unconstrained Power
6998 * <26> : USB Communications Capable
6999 * <25> : Dual-Role Data
7000 * <24:20> : SNK/SRC dependent
7001 * <19:10> : Voltage in 50mV Units
7002 * <9:0> : Maximum Current in 10mA units
7003 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007004#define PDO_FIXED_DUAL_ROLE BIT(29)
7005#define PDO_FIXED_UNCONSTRAINED BIT(27)
7006#define PDO_FIXED_COMM_CAP BIT(26)
7007#define PDO_FIXED_DATA_SWAP BIT(25)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007008#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007009#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7010#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007011
7012/*
7013 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
7014 *
7015 * <31:30> : Battery
7016 * <29:20> : Maximum Voltage in 50mV units
7017 * <19:10> : Minimum Voltage in 50mV units
7018 * <9:0> : Maximum Allowable Power in 250mW units
7019 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007020#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7021#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7022#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007023
7024/*
7025 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
7026 *
7027 * <31:30> : Variable Supply (non-Battery)
7028 * <29:20> : Maximum Voltage in 50mV units
7029 * <19:10> : Minimum Voltage in 50mV units
7030 * <9:0> : Operational Current in 10mA units
7031 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007032#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
7033#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
7034#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007035
7036/*
7037 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
7038 *
7039 * Note this type is reserved in PD 2.0, and only one type of APDO is
7040 * supported as of the cited version.
7041 *
7042 * <31:30> : Augmented Power Data Object
7043 * <29:28> : Programmable Power Supply
7044 * <27> : PPS Power Limited
7045 * <26:25> : Reserved
7046 * <24:17> : Maximum Voltage in 100mV increments
7047 * <16> : Reserved
7048 * <15:8> : Minimum Voltage in 100mV increments
7049 * <7> : Reserved
7050 * <6:0> : Maximum Current in 50mA increments
7051 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007052#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
7053#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
7054#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007055
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007056struct ec_params_typec_status {
7057 uint8_t port;
7058} __ec_align1;
7059
7060struct ec_response_typec_status {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007061 uint8_t pd_enabled; /* PD communication enabled - bool */
7062 uint8_t dev_connected; /* Device connected - bool */
7063 uint8_t sop_connected; /* Device is SOP PD capable - bool */
7064 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007065
Caveh Jalali024ffe32023-01-30 14:35:19 -08007066 uint8_t power_role; /* enum pd_power_role */
7067 uint8_t data_role; /* enum pd_data_role */
7068 uint8_t vconn_role; /* enum pd_vconn_role */
7069 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007070
Caveh Jalali024ffe32023-01-30 14:35:19 -08007071 uint8_t polarity; /* enum tcpc_cc_polarity */
7072 uint8_t cc_state; /* enum pd_cc_states */
7073 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
7074 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007075
Caveh Jalali024ffe32023-01-30 14:35:19 -08007076 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007077
Caveh Jalali024ffe32023-01-30 14:35:19 -08007078 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007079
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007080 /*
7081 * BCD PD revisions for partners
7082 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007083 * The format has the PD major revision in the upper nibble, and the PD
7084 * minor revision in the next nibble. The following two nibbles hold the
7085 * major and minor specification version. If a partner does not support
7086 * the Revision message, only the major revision will be given.
7087 * ex. PD Revision 3.2 Version 1.9 would map to 0x3219
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007088 *
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007089 * PD revision/version will be 0 if no PD device is connected.
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007090 */
7091 uint16_t sop_revision;
7092 uint16_t sop_prime_revision;
7093
Caveh Jalali024ffe32023-01-30 14:35:19 -08007094 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007095
Caveh Jalali024ffe32023-01-30 14:35:19 -08007096 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06007097} __ec_align1;
7098
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007099/**
7100 * Get the number of peripheral charge ports
7101 */
7102#define EC_CMD_PCHG_COUNT 0x0134
7103
7104#define EC_PCHG_MAX_PORTS 8
7105
7106struct ec_response_pchg_count {
7107 uint8_t port_count;
7108} __ec_align1;
7109
7110/**
7111 * Get the status of a peripheral charge port
7112 */
7113#define EC_CMD_PCHG 0x0135
7114
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007115/* For v1 and v2 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007116struct ec_params_pchg {
7117 uint8_t port;
7118} __ec_align1;
7119
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007120struct ec_params_pchg_v3 {
7121 uint8_t port;
7122 /* Below are new in v3. */
7123 uint8_t reserved1;
7124 uint8_t reserved2;
7125 uint8_t reserved3;
7126 /* Errors acked by the host (thus to be cleared) */
7127 uint32_t error;
7128} __ec_align1;
7129
7130/* For v1 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007131struct ec_response_pchg {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007132 uint32_t error; /* enum pchg_error */
7133 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007134 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007135 uint8_t unused0;
7136 uint8_t unused1;
7137 /* Fields added in version 1 */
7138 uint32_t fw_version;
7139 uint32_t dropped_event_count;
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007140} __ec_align4;
7141
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007142/* For v2 and v3 */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007143struct ec_response_pchg_v2 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007144 uint32_t error; /* enum pchg_error */
7145 uint8_t state; /* enum pchg_state state */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007146 uint8_t battery_percentage;
7147 uint8_t unused0;
7148 uint8_t unused1;
7149 /* Fields added in version 1 */
7150 uint32_t fw_version;
7151 uint32_t dropped_event_count;
7152 /* Fields added in version 2 */
7153 uint32_t dropped_host_event_count;
7154} __ec_align4;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007155
7156enum pchg_state {
7157 /* Charger is reset and not initialized. */
7158 PCHG_STATE_RESET = 0,
7159 /* Charger is initialized or disabled. */
7160 PCHG_STATE_INITIALIZED,
7161 /* Charger is enabled and ready to detect a device. */
7162 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007163 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007164 PCHG_STATE_DETECTED,
7165 /* Device is being charged. */
7166 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007167 /* Device is fully charged. It implies DETECTED (& not charging). */
7168 PCHG_STATE_FULL,
7169 /* In download (a.k.a. firmware update) mode */
7170 PCHG_STATE_DOWNLOAD,
7171 /* In download mode. Ready for receiving data. */
7172 PCHG_STATE_DOWNLOADING,
7173 /* Device is ready for data communication. */
7174 PCHG_STATE_CONNECTED,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007175 /* Charger is in Built-In Self Test mode. */
7176 PCHG_STATE_BIST,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007177 /* Put no more entry below */
7178 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007179};
7180
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007181/* clang-format off */
7182#define EC_PCHG_STATE_TEXT \
7183 { \
7184 [PCHG_STATE_RESET] = "RESET", \
7185 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
7186 [PCHG_STATE_ENABLED] = "ENABLED", \
7187 [PCHG_STATE_DETECTED] = "DETECTED", \
7188 [PCHG_STATE_CHARGING] = "CHARGING", \
7189 [PCHG_STATE_FULL] = "FULL", \
7190 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
7191 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
7192 [PCHG_STATE_CONNECTED] = "CONNECTED", \
7193 [PCHG_STATE_BIST] = "BIST", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007194 }
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007195/* clang-format on */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007196
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007197/**
7198 * Update firmware of peripheral chip
7199 */
7200#define EC_CMD_PCHG_UPDATE 0x0136
7201
7202/* Port number is encoded in bit[28:31]. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007203#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007204/* Utility macros for converting MKBP event <-> port number. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007205#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
7206#define EC_MKBP_PCHG_PORT_TO_EVENT(p) ((p) << EC_MKBP_PCHG_PORT_SHIFT)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007207/* Utility macro for extracting event bits. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007208#define EC_MKBP_PCHG_EVENT_MASK(e) ((e)&GENMASK(EC_MKBP_PCHG_PORT_SHIFT - 1, 0))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007209
Caveh Jalali024ffe32023-01-30 14:35:19 -08007210#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
7211#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
7212#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
7213#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
7214#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007215
7216enum ec_pchg_update_cmd {
7217 /* Reset chip to normal mode. */
7218 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
7219 /* Reset and put a chip in update (a.k.a. download) mode. */
7220 EC_PCHG_UPDATE_CMD_OPEN,
7221 /* Write a block of data containing FW image. */
7222 EC_PCHG_UPDATE_CMD_WRITE,
7223 /* Close update session. */
7224 EC_PCHG_UPDATE_CMD_CLOSE,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007225 /* Reset chip (without mode change). */
7226 EC_PCHG_UPDATE_CMD_RESET,
7227 /* Enable pass-through mode. */
7228 EC_PCHG_UPDATE_CMD_ENABLE_PASSTHRU,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007229 /* End of commands */
7230 EC_PCHG_UPDATE_CMD_COUNT,
7231};
7232
7233struct ec_params_pchg_update {
7234 /* PCHG port number */
7235 uint8_t port;
7236 /* enum ec_pchg_update_cmd */
7237 uint8_t cmd;
7238 /* Padding */
7239 uint8_t reserved0;
7240 uint8_t reserved1;
7241 /* Version of new firmware */
7242 uint32_t version;
7243 /* CRC32 of new firmware */
7244 uint32_t crc32;
7245 /* Address in chip memory where <data> is written to */
7246 uint32_t addr;
7247 /* Size of <data> */
7248 uint32_t size;
7249 /* Partial data of new firmware */
7250 uint8_t data[];
7251} __ec_align4;
7252
Caveh Jalali024ffe32023-01-30 14:35:19 -08007253BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT <
7254 BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd) * 8));
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007255
7256struct ec_response_pchg_update {
7257 /* Block size */
7258 uint32_t block_size;
7259} __ec_align4;
7260
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007261#define EC_CMD_DISPLAY_SOC 0x0137
7262
7263struct ec_response_display_soc {
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007264 /* Display charge in 10ths of a % (1000=100.0%) */
7265 int16_t display_soc;
7266 /* Full factor in 10ths of a % (1000=100.0%) */
7267 int16_t full_factor;
7268 /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7269 int16_t shutdown_soc;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007270} __ec_align2;
7271
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007272#define EC_CMD_SET_BASE_STATE 0x0138
7273
7274struct ec_params_set_base_state {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007275 uint8_t cmd; /* enum ec_set_base_state_cmd */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007276} __ec_align1;
7277
7278enum ec_set_base_state_cmd {
7279 EC_SET_BASE_STATE_DETACH = 0,
7280 EC_SET_BASE_STATE_ATTACH,
7281 EC_SET_BASE_STATE_RESET,
7282};
7283
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007284#define EC_CMD_I2C_CONTROL 0x0139
7285
7286/* Subcommands for I2C control */
7287
7288enum ec_i2c_control_command {
7289 EC_I2C_CONTROL_GET_SPEED,
7290 EC_I2C_CONTROL_SET_SPEED,
7291};
7292
7293#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7294
7295struct ec_params_i2c_control {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007296 uint8_t port; /* I2C port number */
7297 uint8_t cmd; /* enum ec_i2c_control_command */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007298 union {
7299 uint16_t speed_khz;
7300 } cmd_params;
7301} __ec_align_size1;
7302
7303struct ec_response_i2c_control {
7304 union {
7305 uint16_t speed_khz;
7306 } cmd_response;
7307} __ec_align_size1;
7308
Caveh Jalali024ffe32023-01-30 14:35:19 -08007309#define EC_CMD_RGBKBD_SET_COLOR 0x013A
7310#define EC_CMD_RGBKBD 0x013B
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007311
Caveh Jalali024ffe32023-01-30 14:35:19 -08007312#define EC_RGBKBD_MAX_KEY_COUNT 128
7313#define EC_RGBKBD_MAX_RGB_COLOR 0xFFFFFF
7314#define EC_RGBKBD_MAX_SCALE 0xFF
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007315
7316enum rgbkbd_state {
7317 /* RGB keyboard is reset and not initialized. */
7318 RGBKBD_STATE_RESET = 0,
7319 /* RGB keyboard is initialized but not enabled. */
7320 RGBKBD_STATE_INITIALIZED,
7321 /* RGB keyboard is disabled. */
7322 RGBKBD_STATE_DISABLED,
7323 /* RGB keyboard is enabled and ready to receive a command. */
7324 RGBKBD_STATE_ENABLED,
7325
7326 /* Put no more entry below */
7327 RGBKBD_STATE_COUNT,
7328};
7329
7330enum ec_rgbkbd_subcmd {
7331 EC_RGBKBD_SUBCMD_CLEAR = 1,
7332 EC_RGBKBD_SUBCMD_DEMO = 2,
7333 EC_RGBKBD_SUBCMD_SET_SCALE = 3,
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007334 EC_RGBKBD_SUBCMD_GET_CONFIG = 4,
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007335 EC_RGBKBD_SUBCMD_COUNT
7336};
7337
7338enum ec_rgbkbd_demo {
7339 EC_RGBKBD_DEMO_OFF = 0,
7340 EC_RGBKBD_DEMO_FLOW = 1,
7341 EC_RGBKBD_DEMO_DOT = 2,
7342 EC_RGBKBD_DEMO_COUNT,
7343};
7344
7345BUILD_ASSERT(EC_RGBKBD_DEMO_COUNT <= 255);
7346
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007347enum ec_rgbkbd_type {
7348 EC_RGBKBD_TYPE_UNKNOWN = 0,
7349 EC_RGBKBD_TYPE_PER_KEY = 1, /* e.g. Vell */
7350 EC_RGBKBD_TYPE_FOUR_ZONES_40_LEDS = 2, /* e.g. Taniks */
7351 EC_RGBKBD_TYPE_FOUR_ZONES_12_LEDS = 3, /* e.g. Osiris */
7352 EC_RGBKBD_TYPE_FOUR_ZONES_4_LEDS = 4, /* e.g. Mithrax */
7353 EC_RGBKBD_TYPE_COUNT,
7354};
7355
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007356struct ec_rgbkbd_set_scale {
7357 uint8_t key;
7358 struct rgb_s scale;
7359};
7360
7361struct ec_params_rgbkbd {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007362 uint8_t subcmd; /* Sub-command (enum ec_rgbkbd_subcmd) */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007363 union {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007364 struct rgb_s color; /* EC_RGBKBD_SUBCMD_CLEAR */
7365 uint8_t demo; /* EC_RGBKBD_SUBCMD_DEMO */
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007366 struct ec_rgbkbd_set_scale set_scale;
7367 };
7368} __ec_align1;
7369
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007370struct ec_response_rgbkbd {
7371 /*
7372 * RGBKBD type supported by the device.
7373 */
7374
7375 uint8_t rgbkbd_type; /* enum ec_rgbkbd_type */
7376} __ec_align1;
7377
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007378struct ec_params_rgbkbd_set_color {
7379 /* Specifies the starting key ID whose color is being changed. */
7380 uint8_t start_key;
7381 /* Specifies # of elements in <color>. */
7382 uint8_t length;
7383 /* RGB color data array of length up to MAX_KEY_COUNT. */
7384 struct rgb_s color[];
7385} __ec_align1;
7386
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007387/*
7388 * Gather the response to the most recent VDM REQ from the AP, as well
7389 * as popping the oldest VDM:Attention from the DPM queue
7390 */
7391#define EC_CMD_TYPEC_VDM_RESPONSE 0x013C
7392
7393struct ec_params_typec_vdm_response {
7394 uint8_t port;
7395} __ec_align1;
7396
7397struct ec_response_typec_vdm_response {
7398 /* Number of 32-bit fields filled in */
7399 uint8_t vdm_data_objects;
7400 /* Partner to address - see enum typec_partner_type */
7401 uint8_t partner_type;
7402 /* enum ec_status describing VDM response */
7403 uint16_t vdm_response_err;
7404 /* VDM data, including VDM header */
7405 uint32_t vdm_response[VDO_MAX_SIZE];
7406 /* Number of 32-bit Attention fields filled in */
7407 uint8_t vdm_attention_objects;
7408 /* Number of remaining messages to consume */
7409 uint8_t vdm_attention_left;
7410 /* Reserved */
7411 uint16_t reserved1;
7412 /* VDM:Attention contents */
7413 uint32_t vdm_attention[2];
7414} __ec_align1;
7415
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007416/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007417/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007418
7419/*****************************************************************************/
7420/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007421 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007422 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007423#define EC_CMD_CR51_BASE 0x0300
7424#define EC_CMD_CR51_LAST 0x03FF
7425
7426/*****************************************************************************/
7427/* Fingerprint MCU commands: range 0x0400-0x040x */
7428
7429/* Fingerprint SPI sensor passthru command: prototyping ONLY */
7430#define EC_CMD_FP_PASSTHRU 0x0400
7431
7432#define EC_FP_FLAG_NOT_COMPLETE 0x1
7433
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007434struct ec_params_fp_passthru {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007435 uint16_t len; /* Number of bytes to write then read */
7436 uint16_t flags; /* EC_FP_FLAG_xxx */
7437 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007438} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007439
7440/* Configure the Fingerprint MCU behavior */
7441#define EC_CMD_FP_MODE 0x0402
7442
7443/* Put the sensor in its lowest power mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007444#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007445/* Wait to see a finger on the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007446#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007447/* Poll until the finger has left the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007448#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007449/* Capture the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007450#define FP_MODE_CAPTURE BIT(3)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007451/* Finger enrollment session on-going */
7452#define FP_MODE_ENROLL_SESSION BIT(4)
7453/* Enroll the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007454#define FP_MODE_ENROLL_IMAGE BIT(5)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007455/* Try to match the current finger image */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007456#define FP_MODE_MATCH BIT(6)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007457/* Reset and re-initialize the sensor. */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007458#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007459/* Sensor maintenance for dead pixels. */
7460#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007461/* special value: don't change anything just read back current mode */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007462#define FP_MODE_DONT_CHANGE BIT(31)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007463
Caveh Jalali024ffe32023-01-30 14:35:19 -08007464#define FP_VALID_MODES \
7465 (FP_MODE_DEEPSLEEP | FP_MODE_FINGER_DOWN | FP_MODE_FINGER_UP | \
7466 FP_MODE_CAPTURE | FP_MODE_ENROLL_SESSION | FP_MODE_ENROLL_IMAGE | \
7467 FP_MODE_MATCH | FP_MODE_RESET_SENSOR | FP_MODE_SENSOR_MAINTENANCE | \
7468 FP_MODE_DONT_CHANGE)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007469
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007470/* Capture types defined in bits [30..28] */
7471#define FP_MODE_CAPTURE_TYPE_SHIFT 28
Caveh Jalali024ffe32023-01-30 14:35:19 -08007472#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
Yu-Ping Wu3fa36f62022-06-28 16:12:41 +08007473/**
7474 * enum fp_capture_type - Specifies the "mode" when capturing images.
7475 *
7476 * @FP_CAPTURE_VENDOR_FORMAT: Capture 1-3 images and choose the best quality
7477 * image (produces 'frame_size' bytes)
7478 * @FP_CAPTURE_SIMPLE_IMAGE: Simple raw image capture (produces width x height x
7479 * bpp bits)
7480 * @FP_CAPTURE_PATTERN0: Self test pattern (e.g. checkerboard)
7481 * @FP_CAPTURE_PATTERN1: Self test pattern (e.g. inverted checkerboard)
7482 * @FP_CAPTURE_QUALITY_TEST: Capture for Quality test with fixed contrast
7483 * @FP_CAPTURE_RESET_TEST: Capture for pixel reset value test
7484 * @FP_CAPTURE_TYPE_MAX: End of enum
7485 *
7486 * @note This enum must remain ordered, if you add new values you must ensure
7487 * that FP_CAPTURE_TYPE_MAX is still the last one.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007488 */
7489enum fp_capture_type {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007490 FP_CAPTURE_VENDOR_FORMAT = 0,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007491 FP_CAPTURE_SIMPLE_IMAGE = 1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007492 FP_CAPTURE_PATTERN0 = 2,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007493 FP_CAPTURE_PATTERN1 = 3,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007494 FP_CAPTURE_QUALITY_TEST = 4,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007495 FP_CAPTURE_RESET_TEST = 5,
7496 FP_CAPTURE_TYPE_MAX,
7497};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007498/* Extracts the capture type from the sensor 'mode' word */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007499#define FP_CAPTURE_TYPE(mode) \
7500 (((mode)&FP_MODE_CAPTURE_TYPE_MASK) >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007502struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007503 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007504} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007505
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007506struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007507 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007508} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007509
7510/* Retrieve Fingerprint sensor information */
7511#define EC_CMD_FP_INFO 0x0403
7512
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007513/* Number of dead pixels detected on the last maintenance */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007514#define FP_ERROR_DEAD_PIXELS(errors) ((errors)&0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007515/* Unknown number of dead pixels detected on the last maintenance */
7516#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007517/* No interrupt from the sensor */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007518#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007519/* SPI communication error */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007520#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007521/* Invalid sensor Hardware ID */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007522#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007523/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007524#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007525
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007526struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007527 /* Sensor identification */
7528 uint32_t vendor_id;
7529 uint32_t product_id;
7530 uint32_t model_id;
7531 uint32_t version;
7532 /* Image frame characteristics */
7533 uint32_t frame_size;
7534 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7535 uint16_t width;
7536 uint16_t height;
7537 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007538 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007539} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007541struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007542 /* Sensor identification */
7543 uint32_t vendor_id;
7544 uint32_t product_id;
7545 uint32_t model_id;
7546 uint32_t version;
7547 /* Image frame characteristics */
7548 uint32_t frame_size;
7549 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7550 uint16_t width;
7551 uint16_t height;
7552 uint16_t bpp;
7553 uint16_t errors; /* see FP_ERROR_ flags above */
7554 /* Template/finger current information */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007555 uint32_t template_size; /* max template size in bytes */
7556 uint16_t template_max; /* maximum number of fingers/templates */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007557 uint16_t template_valid; /* number of valid fingers/templates */
7558 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007559 uint32_t template_version; /* version of the template format */
7560} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007561
7562/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007563#define EC_CMD_FP_FRAME 0x0404
7564
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007565/* constants defining the 'offset' field which also contains the frame index */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007566#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007567/* Frame buffer where the captured image is stored */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007568#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007569/* First frame buffer holding a template */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007570#define FP_FRAME_INDEX_TEMPLATE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007571#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Caveh Jalali024ffe32023-01-30 14:35:19 -08007572#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007573
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007574/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007575#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007576
7577/* Constants for encryption parameters */
7578#define FP_CONTEXT_NONCE_BYTES 12
7579#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7580#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007581#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007582#define FP_CONTEXT_TPM_BYTES 32
7583
Jett Rinkba2edaf2020-01-14 11:49:06 -07007584/* Constants for positive match parameters. */
7585#define FP_POSITIVE_MATCH_SALT_BYTES 16
7586
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007587struct ec_fp_template_encryption_metadata {
7588 /*
7589 * Version of the structure format (N=3).
7590 */
7591 uint16_t struct_version;
7592 /* Reserved bytes, set to 0. */
7593 uint16_t reserved;
7594 /*
7595 * The salt is *only* ever used for key derivation. The nonce is unique,
7596 * a different one is used for every message.
7597 */
7598 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007599 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007600 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7601};
7602
7603struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007604 /*
7605 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7606 * in the high nibble, and the real offset within the frame in
7607 * FP_FRAME_OFFSET_MASK.
7608 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007609 uint32_t offset;
7610 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007611} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007612
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007613/* Load a template into the MCU */
7614#define EC_CMD_FP_TEMPLATE 0x0405
7615
7616/* Flag in the 'size' field indicating that the full template has been sent */
7617#define FP_TEMPLATE_COMMIT 0x80000000
7618
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007619struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007620 uint32_t offset;
7621 uint32_t size;
7622 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007623} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007624
7625/* Clear the current fingerprint user context and set a new one */
7626#define EC_CMD_FP_CONTEXT 0x0406
7627
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007628struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007629 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007630} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007631
Jett Rinkba2edaf2020-01-14 11:49:06 -07007632enum fp_context_action {
7633 FP_CONTEXT_ASYNC = 0,
7634 FP_CONTEXT_GET_RESULT = 1,
7635};
7636
7637/* Version 1 of the command is "asynchronous". */
7638struct ec_params_fp_context_v1 {
Caveh Jalali024ffe32023-01-30 14:35:19 -08007639 uint8_t action; /**< enum fp_context_action */
7640 uint8_t reserved[3]; /**< padding for alignment */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007641 uint32_t userid[FP_CONTEXT_USERID_WORDS];
7642} __ec_align4;
7643
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007644#define EC_CMD_FP_STATS 0x0407
7645
Caveh Jalali024ffe32023-01-30 14:35:19 -08007646#define FPSTATS_CAPTURE_INV BIT(0)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007647#define FPSTATS_MATCHING_INV BIT(1)
7648
7649struct ec_response_fp_stats {
7650 uint32_t capture_time_us;
7651 uint32_t matching_time_us;
7652 uint32_t overall_time_us;
7653 struct {
7654 uint32_t lo;
7655 uint32_t hi;
7656 } overall_t0;
7657 uint8_t timestamps_invalid;
7658 int8_t template_matched;
7659} __ec_align2;
7660
7661#define EC_CMD_FP_SEED 0x0408
7662struct ec_params_fp_seed {
7663 /*
7664 * Version of the structure format (N=3).
7665 */
7666 uint16_t struct_version;
7667 /* Reserved bytes, set to 0. */
7668 uint16_t reserved;
7669 /* Seed from the TPM. */
7670 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7671} __ec_align4;
7672
7673#define EC_CMD_FP_ENC_STATUS 0x0409
7674
7675/* FP TPM seed has been set or not */
7676#define FP_ENC_STATUS_SEED_SET BIT(0)
7677
7678struct ec_response_fp_encryption_status {
7679 /* Used bits in encryption engine status */
7680 uint32_t valid_flags;
7681 /* Encryption engine status */
7682 uint32_t status;
7683} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007684
Jett Rinkba2edaf2020-01-14 11:49:06 -07007685#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7686struct ec_params_fp_read_match_secret {
7687 uint16_t fgr;
7688} __ec_align4;
7689
7690/* The positive match secret has the length of the SHA256 digest. */
7691#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7692struct ec_response_fp_read_match_secret {
7693 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7694} __ec_align4;
7695
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007696/*****************************************************************************/
7697/* Touchpad MCU commands: range 0x0500-0x05FF */
7698
7699/* Perform touchpad self test */
7700#define EC_CMD_TP_SELF_TEST 0x0500
7701
7702/* Get number of frame types, and the size of each type */
7703#define EC_CMD_TP_FRAME_INFO 0x0501
7704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007705struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007706 uint32_t n_frames;
7707 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007708} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007709
7710/* Create a snapshot of current frame readings */
7711#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7712
7713/* Read the frame */
7714#define EC_CMD_TP_FRAME_GET 0x0503
7715
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007716struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007717 uint32_t frame_index;
7718 uint32_t offset;
7719 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007720} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007721
7722/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007723/* EC-EC communication commands: range 0x0600-0x06FF */
7724
7725#define EC_COMM_TEXT_MAX 8
7726
7727/*
7728 * Get battery static information, i.e. information that never changes, or
7729 * very infrequently.
7730 */
7731#define EC_CMD_BATTERY_GET_STATIC 0x0600
7732
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007733/**
7734 * struct ec_params_battery_static_info - Battery static info parameters
7735 * @index: Battery index.
7736 */
7737struct ec_params_battery_static_info {
7738 uint8_t index;
7739} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007740
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007741/**
7742 * struct ec_response_battery_static_info - Battery static info response
7743 * @design_capacity: Battery Design Capacity (mAh)
7744 * @design_voltage: Battery Design Voltage (mV)
7745 * @manufacturer: Battery Manufacturer String
7746 * @model: Battery Model Number String
7747 * @serial: Battery Serial Number String
7748 * @type: Battery Type String
7749 * @cycle_count: Battery Cycle Count
7750 */
7751struct ec_response_battery_static_info {
7752 uint16_t design_capacity;
7753 uint16_t design_voltage;
7754 char manufacturer[EC_COMM_TEXT_MAX];
7755 char model[EC_COMM_TEXT_MAX];
7756 char serial[EC_COMM_TEXT_MAX];
7757 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007758 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007759 uint32_t cycle_count;
7760} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007761
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007762/**
7763 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7764 * Equivalent to struct ec_response_battery_static_info, but with longer
7765 * strings.
7766 * @design_capacity: battery design capacity (in mAh)
7767 * @design_voltage: battery design voltage (in mV)
7768 * @cycle_count: battery cycle count
7769 * @manufacturer_ext: battery manufacturer string
7770 * @model_ext: battery model string
7771 * @serial_ext: battery serial number string
7772 * @type_ext: battery type string
7773 */
7774struct ec_response_battery_static_info_v1 {
7775 uint16_t design_capacity;
7776 uint16_t design_voltage;
7777 uint32_t cycle_count;
7778 char manufacturer_ext[12];
7779 char model_ext[12];
7780 char serial_ext[12];
7781 char type_ext[12];
7782} __ec_align4;
7783
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007784/**
7785 * struct ec_response_battery_static_info_v2 - hostcmd v2 battery static info
7786 *
7787 * Equivalent to struct ec_response_battery_static_info, but with strings
7788 * further lengthened (relative to v1) to accommodate the maximum string length
7789 * permitted by the Smart Battery Data Specification revision 1.1 and fields
7790 * renamed to better match that specification.
7791 *
7792 * @design_capacity: battery design capacity (in mAh)
7793 * @design_voltage: battery design voltage (in mV)
7794 * @cycle_count: battery cycle count
7795 * @manufacturer: battery manufacturer string
7796 * @device_name: battery model string
7797 * @serial: battery serial number string
7798 * @chemistry: battery type string
7799 */
7800struct ec_response_battery_static_info_v2 {
7801 uint16_t design_capacity;
7802 uint16_t design_voltage;
7803 uint32_t cycle_count;
7804 char manufacturer[32];
7805 char device_name[32];
7806 char serial[32];
7807 char chemistry[32];
7808} __ec_align4;
7809
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007810/*
7811 * Get battery dynamic information, i.e. information that is likely to change
7812 * every time it is read.
7813 */
7814#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007816/**
7817 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7818 * @index: Battery index.
7819 */
7820struct ec_params_battery_dynamic_info {
7821 uint8_t index;
7822} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007823
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007824/**
7825 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7826 * @actual_voltage: Battery voltage (mV)
7827 * @actual_current: Battery current (mA); negative=discharging
7828 * @remaining_capacity: Remaining capacity (mAh)
7829 * @full_capacity: Capacity (mAh, might change occasionally)
7830 * @flags: Flags, see EC_BATT_FLAG_*
7831 * @desired_voltage: Charging voltage desired by battery (mV)
7832 * @desired_current: Charging current desired by battery (mA)
7833 */
7834struct ec_response_battery_dynamic_info {
7835 int16_t actual_voltage;
7836 int16_t actual_current;
7837 int16_t remaining_capacity;
7838 int16_t full_capacity;
7839 int16_t flags;
7840 int16_t desired_voltage;
7841 int16_t desired_current;
7842} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007843
7844/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007845 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007846 */
7847#define EC_CMD_CHARGER_CONTROL 0x0602
7848
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007849/**
7850 * struct ec_params_charger_control - Charger control parameters
7851 * @max_current: Charger current (mA). Positive to allow base to draw up to
7852 * max_current and (possibly) charge battery, negative to request current
7853 * from base (OTG).
7854 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7855 * >= 0.
7856 * @allow_charging: Allow base battery charging (only makes sense if
7857 * max_current > 0).
7858 */
7859struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007860 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007861 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007862 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007863} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007864
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007865/* Get ACK from the USB-C SS muxes */
7866#define EC_CMD_USB_PD_MUX_ACK 0x0603
7867
7868struct ec_params_usb_pd_mux_ack {
7869 uint8_t port; /* USB-C port number */
7870} __ec_align1;
7871
Caveh Jalali6bd733b2023-01-30 17:06:31 -08007872/* Get boot time */
7873#define EC_CMD_GET_BOOT_TIME 0x0604
7874
7875enum boot_time_param {
7876 ARAIL = 0,
7877 RSMRST,
7878 ESPIRST,
7879 PLTRST_LOW,
7880 PLTRST_HIGH,
7881 EC_CUR_TIME,
7882 RESET_CNT,
7883};
7884
7885struct ec_response_get_boot_time {
7886 uint64_t timestamp[RESET_CNT];
7887 uint16_t cnt;
7888} __ec_align4;
7889
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007890/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007891/*
7892 * Reserve a range of host commands for board-specific, experimental, or
7893 * special purpose features. These can be (re)used without updating this file.
7894 *
7895 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7896 * their EC commands for easier development, testing, debugging, and support.
7897 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007898 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7899 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7900 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007901 * In your experimental code, you may want to do something like this:
7902 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007903 * #define EC_CMD_MAGIC_FOO 0x0000
7904 * #define EC_CMD_MAGIC_BAR 0x0001
7905 * #define EC_CMD_MAGIC_HEY 0x0002
7906 *
7907 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7908 * EC_VER_MASK(0);
7909 *
7910 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7911 * EC_VER_MASK(0);
7912 *
7913 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7914 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007915 */
7916#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7917#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7918
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007919/*
7920 * Given the private host command offset, calculate the true private host
7921 * command value.
7922 */
7923#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7924 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7925
Duncan Laurie93e24442014-01-06 12:30:52 -08007926/*****************************************************************************/
7927/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007928 * Passthru commands
7929 *
7930 * Some platforms have sub-processors chained to each other. For example.
7931 *
7932 * AP <--> EC <--> PD MCU
7933 *
7934 * The top 2 bits of the command number are used to indicate which device the
7935 * command is intended for. Device 0 is always the device receiving the
7936 * command; other device mapping is board-specific.
7937 *
7938 * When a device receives a command to be passed to a sub-processor, it passes
7939 * it on with the device number set back to 0. This allows the sub-processor
7940 * to remain blissfully unaware of whether the command originated on the next
7941 * device up the chain, or was passed through from the AP.
7942 *
7943 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7944 * AP sends command 0x4002 to the EC
7945 * EC sends command 0x0002 to the PD MCU
7946 * EC forwards PD MCU response back to the AP
7947 */
7948
7949/* Offset and max command number for sub-device n */
7950#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7951#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7952
7953/*****************************************************************************/
7954/*
Duncan Laurie93e24442014-01-06 12:30:52 -08007955 * Deprecated constants. These constants have been renamed for clarity. The
7956 * meaning and size has not changed. Programs that use the old names should
7957 * switch to the new names soon, as the old names may not be carried forward
7958 * forever.
7959 */
Caveh Jalali024ffe32023-01-30 14:35:19 -08007960#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
7961#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
7962#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
Duncan Laurie93e24442014-01-06 12:30:52 -08007963
Caveh Jalali024ffe32023-01-30 14:35:19 -08007964#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007965
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007966#ifdef __cplusplus
7967}
7968#endif
7969
Caveh Jalali024ffe32023-01-30 14:35:19 -08007970#endif /* __CROS_EC_EC_COMMANDS_H */