blob: e8b028f8226e0f59a505e3bfe80e8dcdbb6733c1 [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 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070032#endif /* CHROMIUM_EC */
33
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
45#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
49#define BIT_ULL(nr) (1ULL << (nr))
50#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
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070067#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
Stefan Reinauerd6682e82013-02-21 15:39:35 -080073/*
Duncan Laurie93e24442014-01-06 12:30:52 -080074 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080075 *
Duncan Laurie93e24442014-01-06 12:30:52 -080076 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
77 * determined in other ways. Remove this once the kernel code no longer
78 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080079 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080080#define EC_PROTO_VERSION 0x00000002
81
82/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080083#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -080084
85/* I/O addresses for ACPI commands */
86#define EC_LPC_ADDR_ACPI_DATA 0x62
87#define EC_LPC_ADDR_ACPI_CMD 0x66
88
89/* I/O addresses for host command */
90#define EC_LPC_ADDR_HOST_DATA 0x200
91#define EC_LPC_ADDR_HOST_CMD 0x204
92
93/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080094/* Protocol version 2 */
95#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
96#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080097 * EC_PROTO2_MAX_PARAM_SIZE
98 */
Duncan Laurie93e24442014-01-06 12:30:52 -080099/* Protocol version 3 */
100#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
101#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800102
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800103/*
104 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
105 * and they tell the kernel that so we have to think of it as two parts.
106 */
Bill Richardsone221aad2013-06-12 10:50:41 -0700107#define EC_HOST_CMD_REGION0 0x800
108#define EC_HOST_CMD_REGION1 0x880
109#define EC_HOST_CMD_REGION_SIZE 0x80
110
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800111/* EC command register bit functions */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800112#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
113#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
114#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
115#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
116#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
117#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
118#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800119
120#define EC_LPC_ADDR_MEMMAP 0x900
121#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
122#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
123
124/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700125#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
126#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
127#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
128#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800129#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
130#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
131#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
132#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
133#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700134#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
135/* Unused 0x28 - 0x2f */
136#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
137/* Unused 0x31 - 0x33 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600138#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
139/* Battery values are all 32 bits, unless otherwise noted. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800140#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
141#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
142#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600143#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
144#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
145#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
146/* Unused 0x4f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800147#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
148#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
149#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
150#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700151/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800152#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
153#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
154#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
155#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700156#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
157/* Unused 0x84 - 0x8f */
158#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
159/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800160#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
161/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
162/* 0x94 - 0x99: 1st Accelerometer */
163/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700164#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700165/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700166
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700167/*
168 * ACPI is unable to access memory mapped data at or above this offset due to
169 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
170 * which might be needed by ACPI.
171 */
172#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700173
174/* Define the format of the accelerometer mapped memory status byte. */
175#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800176#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
177#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800178
179/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
180#define EC_TEMP_SENSOR_ENTRIES 16
181/*
182 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
183 *
184 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
185 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700186#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800187
188/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700189#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
190#define EC_TEMP_SENSOR_ERROR 0xfe
191#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
192#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800193/*
194 * The offset of temperature value stored in mapped memory. This allows
195 * reporting a temperature range of 200K to 454K = -73C to 181C.
196 */
197#define EC_TEMP_SENSOR_OFFSET 200
198
Duncan Laurie93e24442014-01-06 12:30:52 -0800199/*
200 * Number of ALS readings at EC_MEMMAP_ALS
201 */
202#define EC_ALS_ENTRIES 2
203
204/*
205 * The default value a temperature sensor will return when it is present but
206 * has not been read this boot. This is a reasonable number to avoid
207 * triggering alarms on the host.
208 */
209#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
210
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800211#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
212#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
213#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
214
215/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
216#define EC_BATT_FLAG_AC_PRESENT 0x01
217#define EC_BATT_FLAG_BATT_PRESENT 0x02
218#define EC_BATT_FLAG_DISCHARGING 0x04
219#define EC_BATT_FLAG_CHARGING 0x08
220#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600221/* Set if some of the static/dynamic data is invalid (or outdated). */
222#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800223
224/* Switch flags at EC_MEMMAP_SWITCHES */
225#define EC_SWITCH_LID_OPEN 0x01
226#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
227#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700228/* Was recovery requested via keyboard; now unused. */
229#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800230/* Recovery requested via dedicated signal (from servo board) */
231#define EC_SWITCH_DEDICATED_RECOVERY 0x10
232/* Was fake developer mode switch; now unused. Remove in next refactor. */
233#define EC_SWITCH_IGNORE0 0x20
234
235/* Host command interface flags */
236/* Host command interface supports LPC args (LPC interface only) */
237#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800238/* Host command interface supports version 3 protocol */
239#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800240
241/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800242#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
243#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
244#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
245#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
246#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800247
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700248/*****************************************************************************/
249/*
250 * ACPI commands
251 *
252 * These are valid ONLY on the ACPI command/data port.
253 */
254
255/*
256 * ACPI Read Embedded Controller
257 *
258 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
259 *
260 * Use the following sequence:
261 *
262 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
263 * - Wait for EC_LPC_CMDR_PENDING bit to clear
264 * - Write address to EC_LPC_ADDR_ACPI_DATA
265 * - Wait for EC_LPC_CMDR_DATA bit to set
266 * - Read value from EC_LPC_ADDR_ACPI_DATA
267 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700268#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700269
270/*
271 * ACPI Write Embedded Controller
272 *
273 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
274 *
275 * Use the following sequence:
276 *
277 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
278 * - Wait for EC_LPC_CMDR_PENDING bit to clear
279 * - Write address to EC_LPC_ADDR_ACPI_DATA
280 * - Wait for EC_LPC_CMDR_PENDING bit to clear
281 * - Write value to EC_LPC_ADDR_ACPI_DATA
282 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700283#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700284
285/*
286 * ACPI Burst Enable Embedded Controller
287 *
288 * This enables burst mode on the EC to allow the host to issue several
289 * commands back-to-back. While in this mode, writes to mapped multi-byte
290 * data are locked out to ensure data consistency.
291 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700292#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700293
294/*
295 * ACPI Burst Disable Embedded Controller
296 *
297 * This disables burst mode on the EC and stops preventing EC writes to mapped
298 * multi-byte data.
299 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700300#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700301
302/*
303 * ACPI Query Embedded Controller
304 *
305 * This clears the lowest-order bit in the currently pending host events, and
306 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
307 * event 0x80000000 = 32), or 0 if no event was pending.
308 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700309#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700310
311/* Valid addresses in ACPI memory space, for read/write commands */
312
313/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
314#define EC_ACPI_MEM_VERSION 0x00
315/*
316 * Test location; writing value here updates test compliment byte to (0xff -
317 * value).
318 */
319#define EC_ACPI_MEM_TEST 0x01
320/* Test compliment; writes here are ignored. */
321#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
322
323/* Keyboard backlight brightness percent (0 - 100) */
324#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
325/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
326#define EC_ACPI_MEM_FAN_DUTY 0x04
327
328/*
329 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
330 * independent thresholds attached to them. The current value of the ID
331 * register determines which sensor is affected by the THRESHOLD and COMMIT
332 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
333 * as the memory-mapped sensors. The COMMIT register applies those settings.
334 *
335 * The spec does not mandate any way to read back the threshold settings
336 * themselves, but when a threshold is crossed the AP needs a way to determine
337 * which sensor(s) are responsible. Each reading of the ID register clears and
338 * returns one sensor ID that has crossed one of its threshold (in either
339 * direction) since the last read. A value of 0xFF means "no new thresholds
340 * have tripped". Setting or enabling the thresholds for a sensor will clear
341 * the unread event count for that sensor.
342 */
343#define EC_ACPI_MEM_TEMP_ID 0x05
344#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
345#define EC_ACPI_MEM_TEMP_COMMIT 0x07
346/*
347 * Here are the bits for the COMMIT register:
348 * bit 0 selects the threshold index for the chosen sensor (0/1)
349 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
350 * Each write to the commit register affects one threshold.
351 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800352#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
353#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700354/*
355 * Example:
356 *
357 * Set the thresholds for sensor 2 to 50 C and 60 C:
358 * write 2 to [0x05] -- select temp sensor 2
359 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
360 * write 0x2 to [0x07] -- enable threshold 0 with this value
361 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
362 * write 0x3 to [0x07] -- enable threshold 1 with this value
363 *
364 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
365 * write 2 to [0x05] -- select temp sensor 2
366 * write 0x1 to [0x07] -- disable threshold 1
367 */
368
369/* DPTF battery charging current limit */
370#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
371
372/* Charging limit is specified in 64 mA steps */
373#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
374/* Value to disable DPTF battery charging limit */
375#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700376
jiazi Yang51fc93f2016-07-28 05:15:01 -0400377/*
378 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800379 * Bits Definition
380 * 3:1 Device DPTF Profile Number (DDPN)
381 * 0 = Reserved for backward compatibility (indicates no valid
382 * profile number. Host should fall back to using TBMD).
383 * 1..7 = DPTF Profile number to indicate to host which table needs
384 * to be loaded.
385 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400386 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700387#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800388#define EC_ACPI_MEM_TBMD_SHIFT 0
389#define EC_ACPI_MEM_TBMD_MASK 0x1
390#define EC_ACPI_MEM_DDPN_SHIFT 1
391#define EC_ACPI_MEM_DDPN_MASK 0x7
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700392
393/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600394 * Report device features. Uses the same format as the host command, except:
395 *
396 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
397 * of features", which is of limited interest when the system is already
398 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
399 * these are supported, it defaults to 0.
400 * This allows detecting the presence of this field since older versions of
401 * the EC codebase would simply return 0xff to that unknown address. Check
402 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
403 * are valid.
404 */
405#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
406#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
407#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
408#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
409#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
410#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
411#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
412#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
413
414#define EC_ACPI_MEM_BATTERY_INDEX 0x12
415
416/*
417 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
418 * is enabled (1) or disabled (0).
419 * bit 0 USB port ID 0
420 * ...
421 * bit 7 USB port ID 7
422 */
423#define EC_ACPI_MEM_USB_PORT_POWER 0x13
424
425/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600426 * USB Retimer firmware update.
427 * Read:
428 * Result of last operation AP requested
429 * Write:
430 * bits[3:0]: USB-C port number
431 * bits[7:4]: Operation requested by AP
432 *
433 * NDA (no device attached) case:
434 * To update retimer firmware, AP needs set up TBT Alt mode.
435 * AP requests operations in this sequence:
436 * 1. Get port information about which ports support retimer firmware update.
437 * In the query result, each bit represents one port.
438 * 2. Get current MUX mode, it's NDA.
439 * 3. Suspend specified PD port's task.
440 * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode ->
441 * update firmware -> disconnect MUX -> resume PD task.
442 *
443 * DA (device attached) cases:
444 * Retimer firmware update is not supported in DA cases.
445 * 1. Get port information about which ports support retimer firmware update
446 * 2. Get current MUX mode, it's DA.
447 * 3. AP continues. No more retimer firmware update activities.
448 *
449 */
450#define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14
451
452#define USB_RETIMER_FW_UPDATE_OP_SHIFT 4
453#define USB_RETIMER_FW_UPDATE_ERR 0xfe
454#define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff
Scott Chao18141d8c2021-07-30 10:40:57 +0800455/* Mask to clear unused MUX bits in retimer firmware update */
456#define USB_RETIMER_FW_UPDATE_MUX_MASK (USB_PD_MUX_USB_ENABLED | \
457 USB_PD_MUX_DP_ENABLED | \
458 USB_PD_MUX_SAFE_MODE | \
459 USB_PD_MUX_TBT_COMPAT_ENABLED | \
460 USB_PD_MUX_USB4_ENABLED)
461
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600462/* Retimer firmware update operations */
463#define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
464#define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
465#define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
466#define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
467#define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
468#define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
469#define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
470#define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
471
472#define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x) & 0x0f)
473#define EC_ACPI_MEM_USB_RETIMER_OP(x) \
474 (((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
475
476/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700477 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
478 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
479 */
480#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
481#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
482
483/* Current version of ACPI memory address space */
484#define EC_ACPI_MEM_VERSION_CURRENT 2
485
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -0600486
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800487/*
488 * This header file is used in coreboot both in C and ACPI code. The ACPI code
489 * is pre-processed to handle constants but the ASL compiler is unable to
490 * handle actual C code so keep it separate.
491 */
492#ifndef __ACPI__
493
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800494#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800495/*
496 * Define __packed if someone hasn't beat us to it. Linux kernel style
497 * checking prefers __packed over __attribute__((packed)).
498 */
499#ifndef __packed
500#define __packed __attribute__((packed))
501#endif
502
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700503#ifndef __aligned
504#define __aligned(x) __attribute__((aligned(x)))
505#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800506#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700507
508/*
509 * Attributes for EC request and response packets. Just defining __packed
510 * results in inefficient assembly code on ARM, if the structure is actually
511 * 32-bit aligned, as it should be for all buffers.
512 *
513 * Be very careful when adding these to existing structures. They will round
514 * up the structure size to the specified boundary.
515 *
516 * Also be very careful to make that if a structure is included in some other
517 * parent structure that the alignment will still be true given the packing of
518 * the parent structure. This is particularly important if the sub-structure
519 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200520 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700521 *
522 * Also be very careful using __packed - particularly when nesting non-packed
523 * structures inside packed ones. In fact, DO NOT use __packed directly;
524 * always use one of these attributes.
525 *
526 * Once everything is annotated properly, the following search strings should
527 * not return ANY matches in this file other than right here:
528 *
529 * "__packed" - generates inefficient code; all sub-structs must also be packed
530 *
531 * "struct [^_]" - all structs should be annotated, except for structs that are
532 * members of other structs/unions (and their original declarations should be
533 * annotated).
534 */
535#ifdef CONFIG_HOSTCMD_ALIGNED
536
537/*
538 * Packed structures where offset and size are always aligned to 1, 2, or 4
539 * byte boundary.
540 */
541#define __ec_align1 __packed
542#define __ec_align2 __packed __aligned(2)
543#define __ec_align4 __packed __aligned(4)
544
545/*
546 * Packed structure which must be under-aligned, because its size is not a
547 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
548 * of all multi-byte fields in it, even though they are themselves aligned.
549 *
550 * In theory, we could duplicate the structure with __aligned(4) for accessing
551 * its members, but use the __packed version for sizeof().
552 */
553#define __ec_align_size1 __packed
554
555/*
556 * Packed structure which must be under-aligned, because its offset inside a
557 * parent structure is not a 4-byte multiple.
558 */
559#define __ec_align_offset1 __packed
560#define __ec_align_offset2 __packed __aligned(2)
561
562/*
563 * Structures which are complicated enough that I'm skipping them on the first
564 * pass. They are effectively unchanged from their previous definitions.
565 *
566 * TODO(rspangler): Figure out what to do with these. It's likely necessary
567 * to work out the size and offset of each member and add explicit padding to
568 * maintain those.
569 */
570#define __ec_todo_packed __packed
571#define __ec_todo_unpacked
572
573#else /* !CONFIG_HOSTCMD_ALIGNED */
574
575/*
576 * Packed structures make no assumption about alignment, so they do inefficient
577 * byte-wise reads.
578 */
579#define __ec_align1 __packed
580#define __ec_align2 __packed
581#define __ec_align4 __packed
582#define __ec_align_size1 __packed
583#define __ec_align_offset1 __packed
584#define __ec_align_offset2 __packed
585#define __ec_todo_packed __packed
586#define __ec_todo_unpacked
587
588#endif /* !CONFIG_HOSTCMD_ALIGNED */
589
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800590/* LPC command status byte masks */
591/* EC has written a byte in the data register and host hasn't read it yet */
592#define EC_LPC_STATUS_TO_HOST 0x01
593/* Host has written a command/data byte and the EC hasn't read it yet */
594#define EC_LPC_STATUS_FROM_HOST 0x02
595/* EC is processing a command */
596#define EC_LPC_STATUS_PROCESSING 0x04
597/* Last write to EC was a command, not data */
598#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700599/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800600#define EC_LPC_STATUS_BURST_MODE 0x10
601/* SCI event is pending (requesting SCI query) */
602#define EC_LPC_STATUS_SCI_PENDING 0x20
603/* SMI event is pending (requesting SMI query) */
604#define EC_LPC_STATUS_SMI_PENDING 0x40
605/* (reserved) */
606#define EC_LPC_STATUS_RESERVED 0x80
607
608/*
609 * EC is busy. This covers both the EC processing a command, and the host has
610 * written a new command but the EC hasn't picked it up yet.
611 */
612#define EC_LPC_STATUS_BUSY_MASK \
613 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
614
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800615/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700616 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700617 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800618enum ec_status {
619 EC_RES_SUCCESS = 0,
620 EC_RES_INVALID_COMMAND = 1,
621 EC_RES_ERROR = 2,
622 EC_RES_INVALID_PARAM = 3,
623 EC_RES_ACCESS_DENIED = 4,
624 EC_RES_INVALID_RESPONSE = 5,
625 EC_RES_INVALID_VERSION = 6,
626 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700627 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
628 EC_RES_UNAVAILABLE = 9, /* No response available */
629 EC_RES_TIMEOUT = 10, /* We got a timeout */
630 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800631 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
632 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700633 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700634 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600635 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
636 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
637 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
638 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
639 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700640
641 EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */
642} __packed;
643BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800644
645/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600646 * Host event codes. ACPI query EC command uses code 0 to mean "no event
647 * pending". We explicitly specify each value in the enum listing so they won't
648 * change if we delete/insert an item or rearrange the list (it needs to be
649 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800650 */
651enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600652 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800653 EC_HOST_EVENT_LID_CLOSED = 1,
654 EC_HOST_EVENT_LID_OPEN = 2,
655 EC_HOST_EVENT_POWER_BUTTON = 3,
656 EC_HOST_EVENT_AC_CONNECTED = 4,
657 EC_HOST_EVENT_AC_DISCONNECTED = 5,
658 EC_HOST_EVENT_BATTERY_LOW = 6,
659 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
660 EC_HOST_EVENT_BATTERY = 8,
661 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700662 /* Event generated by a device attached to the EC */
663 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800664 EC_HOST_EVENT_THERMAL = 11,
665 EC_HOST_EVENT_USB_CHARGER = 12,
666 EC_HOST_EVENT_KEY_PRESSED = 13,
667 /*
668 * EC has finished initializing the host interface. The host can check
669 * for this event following sending a EC_CMD_REBOOT_EC command to
670 * determine when the EC is ready to accept subsequent commands.
671 */
672 EC_HOST_EVENT_INTERFACE_READY = 14,
673 /* Keyboard recovery combo has been pressed */
674 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
675
676 /* Shutdown due to thermal overload */
677 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
678 /* Shutdown due to battery level too low */
679 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
680
Duncan Laurie93e24442014-01-06 12:30:52 -0800681 /* Suggest that the AP throttle itself */
682 EC_HOST_EVENT_THROTTLE_START = 18,
683 /* Suggest that the AP resume normal speed */
684 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700685
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800686 /* Hang detect logic detected a hang and host event timeout expired */
687 EC_HOST_EVENT_HANG_DETECT = 20,
688 /* Hang detect logic detected a hang and warm rebooted the AP */
689 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700690
691 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700692 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800693
Duncan Lauried8401182014-09-29 08:32:19 -0700694 /* Battery Status flags have changed */
695 EC_HOST_EVENT_BATTERY_STATUS = 23,
696
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700697 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800698 EC_HOST_EVENT_PANIC = 24,
699
Furquan Shaikh066cc852015-06-20 15:53:03 -0700700 /* Keyboard fastboot combo has been pressed */
701 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
702
Gwendal Grignou880b4582016-06-20 08:49:25 -0700703 /* EC RTC event occurred */
704 EC_HOST_EVENT_RTC = 26,
705
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700706 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700707 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700708
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700709 /* EC desires to change state of host-controlled USB mux */
710 EC_HOST_EVENT_USB_MUX = 28,
711
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800712 /*
713 * The device has changed "modes". This can be one of the following:
714 *
715 * - TABLET/LAPTOP mode
716 * - detachable base attach/detach event
717 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400718 EC_HOST_EVENT_MODE_CHANGE = 29,
719
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700720 /* Keyboard recovery combo with hardware reinitialization */
721 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
722
Jett Rinkba2edaf2020-01-14 11:49:06 -0700723 /* WoV */
724 EC_HOST_EVENT_WOV = 31,
725
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700726 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800727 * The high bit of the event mask is not used as a host event code. If
728 * it reads back as set, then the entire event mask should be
729 * considered invalid by the host. This can happen when reading the
730 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
731 * not initialized on the EC, or improperly configured on the host.
732 */
733 EC_HOST_EVENT_INVALID = 32
734};
735/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800736#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800737
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800738/**
739 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
740 * @flags: The host argument flags.
741 * @command_version: Command version.
742 * @data_size: The length of data.
743 * @checksum: Checksum; sum of command + flags + command_version + data_size +
744 * all params/response data bytes.
745 */
746struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800747 uint8_t flags;
748 uint8_t command_version;
749 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800750 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800751} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800752
753/* Flags for ec_lpc_host_args.flags */
754/*
755 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
756 * params.
757 *
758 * If EC gets a command and this flag is not set, this is an old-style command.
759 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
760 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700761 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800762 */
763#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
764/*
765 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
766 *
767 * If EC responds to a command and this flag is not set, this is an old-style
768 * response. Command version is 0 and response data from EC is at
769 * EC_LPC_ADDR_OLD_PARAM with unknown length.
770 */
771#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
772
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800773/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800774/*
775 * Byte codes returned by EC over SPI interface.
776 *
777 * These can be used by the AP to debug the EC interface, and to determine
778 * when the EC is not in a state where it will ever get around to responding
779 * to the AP.
780 *
781 * Example of sequence of bytes read from EC for a current good transfer:
782 * 1. - - AP asserts chip select (CS#)
783 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
784 * 3. - - EC starts handling CS# interrupt
785 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
786 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
787 * bytes looking for EC_SPI_FRAME_START
788 * 6. - - EC finishes processing and sets up response
789 * 7. EC_SPI_FRAME_START - AP reads frame byte
790 * 8. (response packet) - AP reads response packet
791 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
792 * 10 - - AP deasserts chip select
793 * 11 - - EC processes CS# interrupt and sets up DMA for
794 * next request
795 *
796 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
797 * the following byte values:
798 * EC_SPI_OLD_READY
799 * EC_SPI_RX_READY
800 * EC_SPI_RECEIVING
801 * EC_SPI_PROCESSING
802 *
803 * Then the EC found an error in the request, or was not ready for the request
804 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
805 * because the EC is unable to tell when the AP is done sending its request.
806 */
807
808/*
809 * Framing byte which precedes a response packet from the EC. After sending a
810 * request, the AP will clock in bytes until it sees the framing byte, then
811 * clock in the response packet.
812 */
813#define EC_SPI_FRAME_START 0xec
814
815/*
816 * Padding bytes which are clocked out after the end of a response packet.
817 */
818#define EC_SPI_PAST_END 0xed
819
820/*
821 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
822 * that the AP will send a valid packet header (starting with
823 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
824 */
825#define EC_SPI_RX_READY 0xf8
826
827/*
828 * EC has started receiving the request from the AP, but hasn't started
829 * processing it yet.
830 */
831#define EC_SPI_RECEIVING 0xf9
832
833/* EC has received the entire request from the AP and is processing it. */
834#define EC_SPI_PROCESSING 0xfa
835
836/*
837 * EC received bad data from the AP, such as a packet header with an invalid
838 * length. EC will ignore all data until chip select deasserts.
839 */
840#define EC_SPI_RX_BAD_DATA 0xfb
841
842/*
843 * EC received data from the AP before it was ready. That is, the AP asserted
844 * chip select and started clocking data before the EC was ready to receive it.
845 * EC will ignore all data until chip select deasserts.
846 */
847#define EC_SPI_NOT_READY 0xfc
848
849/*
850 * EC was ready to receive a request from the AP. EC has treated the byte sent
851 * by the AP as part of a request packet, or (for old-style ECs) is processing
852 * a fully received packet but is not ready to respond yet.
853 */
854#define EC_SPI_OLD_READY 0xfd
855
856/*****************************************************************************/
857
858/*
859 * Protocol version 2 for I2C and SPI send a request this way:
860 *
861 * 0 EC_CMD_VERSION0 + (command version)
862 * 1 Command number
863 * 2 Length of params = N
864 * 3..N+2 Params, if any
865 * N+3 8-bit checksum of bytes 0..N+2
866 *
867 * The corresponding response is:
868 *
869 * 0 Result code (EC_RES_*)
870 * 1 Length of params = M
871 * 2..M+1 Params, if any
872 * M+2 8-bit checksum of bytes 0..M+1
873 */
874#define EC_PROTO2_REQUEST_HEADER_BYTES 3
875#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
876#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
877 EC_PROTO2_REQUEST_TRAILER_BYTES)
878
879#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
880#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
881#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
882 EC_PROTO2_RESPONSE_TRAILER_BYTES)
883
884/* Parameter length was limited by the LPC interface */
885#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
886
887/* Maximum request and response packet sizes for protocol version 2 */
888#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
889 EC_PROTO2_MAX_PARAM_SIZE)
890#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
891 EC_PROTO2_MAX_PARAM_SIZE)
892
893/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800894
895/*
896 * Value written to legacy command port / prefix byte to indicate protocol
897 * 3+ structs are being used. Usage is bus-dependent.
898 */
899#define EC_COMMAND_PROTOCOL_3 0xda
900
901#define EC_HOST_REQUEST_VERSION 3
902
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800903/**
904 * struct ec_host_request - Version 3 request from host.
905 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
906 * receives a header with a version it doesn't know how to
907 * parse.
908 * @checksum: Checksum of request and data; sum of all bytes including checksum
909 * should total to 0.
910 * @command: Command to send (EC_CMD_...)
911 * @command_version: Command version.
912 * @reserved: Unused byte in current protocol version; set to 0.
913 * @data_len: Length of data which follows this header.
914 */
915struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800916 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800917 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800918 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800919 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800920 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800921 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800922} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800923
924#define EC_HOST_RESPONSE_VERSION 3
925
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800926/**
927 * struct ec_host_response - Version 3 response from EC.
928 * @struct_version: Struct version (=3).
929 * @checksum: Checksum of response and data; sum of all bytes including
930 * checksum should total to 0.
931 * @result: EC's response to the command (separate from communication failure)
932 * @data_len: Length of data which follows this header.
933 * @reserved: Unused bytes in current protocol version; set to 0.
934 */
935struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800936 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800937 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800938 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800939 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800940 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800941} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800942
943/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600944
945/*
946 * Host command protocol V4.
947 *
948 * Packets always start with a request or response header. They are followed
949 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +0100950 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600951 * polynomial.
952 *
953 * Host algorithm when sending a request q:
954 *
955 * 101) tries_left=(some value, e.g. 3);
956 * 102) q.seq_num++
957 * 103) q.seq_dup=0
958 * 104) Calculate q.header_crc.
959 * 105) Send request q to EC.
960 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
961 *
962 * 201) If r.struct_version != 4, go to 301.
963 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
964 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
965 * 204) If r.seq_num != q.seq_num, go to 301.
966 * 205) If r.seq_dup == q.seq_dup, return success.
967 * 207) If r.seq_dup == 1, go to 301.
968 * 208) Return error.
969 *
970 * 301) If --tries_left <= 0, return error.
971 * 302) If q.seq_dup == 1, go to 105.
972 * 303) q.seq_dup = 1
973 * 304) Go to 104.
974 *
975 * EC algorithm when receiving a request q.
976 * EC has response buffer r, error buffer e.
977 *
978 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
979 * and go to 301
980 * 102) If q.header_crc mismatches calculated CRC, set e.result =
981 * EC_RES_INVALID_HEADER_CRC and go to 301
982 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
983 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
984 * and go to 301.
985 * 104) If q.seq_dup == 0, go to 201.
986 * 105) If q.seq_num != r.seq_num, go to 201.
987 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
988 *
989 * 201) Process request q into response r.
990 * 202) r.seq_num = q.seq_num
991 * 203) r.seq_dup = q.seq_dup
992 * 204) Calculate r.header_crc
993 * 205) If r.data_len > 0 and data is no longer available, set e.result =
994 * EC_RES_DUP_UNAVAILABLE and go to 301.
995 * 206) Send response r.
996 *
997 * 301) e.seq_num = q.seq_num
998 * 302) e.seq_dup = q.seq_dup
999 * 303) Calculate e.header_crc.
1000 * 304) Send error response e.
1001 */
1002
1003/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001004struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001005 /*
1006 * bits 0-3: struct_version: Structure version (=4)
1007 * bit 4: is_response: Is response (=0)
1008 * bits 5-6: seq_num: Sequence number
1009 * bit 7: seq_dup: Sequence duplicate flag
1010 */
1011 uint8_t fields0;
1012
1013 /*
1014 * bits 0-4: command_version: Command version
1015 * bits 5-6: Reserved (set 0, ignore on read)
1016 * bit 7: data_crc_present: Is data CRC present after data
1017 */
1018 uint8_t fields1;
1019
1020 /* Command code (EC_CMD_*) */
1021 uint16_t command;
1022
1023 /* Length of data which follows this header (not including data CRC) */
1024 uint16_t data_len;
1025
1026 /* Reserved (set 0, ignore on read) */
1027 uint8_t reserved;
1028
1029 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1030 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001031} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001032
1033/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001034struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001035 /*
1036 * bits 0-3: struct_version: Structure version (=4)
1037 * bit 4: is_response: Is response (=1)
1038 * bits 5-6: seq_num: Sequence number
1039 * bit 7: seq_dup: Sequence duplicate flag
1040 */
1041 uint8_t fields0;
1042
1043 /*
1044 * bits 0-6: Reserved (set 0, ignore on read)
1045 * bit 7: data_crc_present: Is data CRC present after data
1046 */
1047 uint8_t fields1;
1048
1049 /* Result code (EC_RES_*) */
1050 uint16_t result;
1051
1052 /* Length of data which follows this header (not including data CRC) */
1053 uint16_t data_len;
1054
1055 /* Reserved (set 0, ignore on read) */
1056 uint8_t reserved;
1057
1058 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1059 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001060} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001061
1062/* Fields in fields0 byte */
1063#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1064#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1065#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1066#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1067#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1068
1069/* Fields in fields1 byte */
1070#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1071#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1072
1073/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001074/*
1075 * Notes on commands:
1076 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001077 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001078 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001079 * specified, the command does not input or output data, respectively.
1080 * Parameter/response length is implicit in the structs. Some underlying
1081 * communication protocols (I2C, SPI) may add length or checksum headers, but
1082 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001083 *
1084 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1085 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001086 */
1087
1088/*****************************************************************************/
1089/* General / test commands */
1090
1091/*
1092 * Get protocol version, used to deal with non-backward compatible protocol
1093 * changes.
1094 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001095#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001097/**
1098 * struct ec_response_proto_version - Response to the proto version command.
1099 * @version: The protocol version.
1100 */
1101struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001102 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001103} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001104
1105/*
1106 * Hello. This is a simple command to test the EC is responsive to
1107 * commands.
1108 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001109#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001110
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001111/**
1112 * struct ec_params_hello - Parameters to the hello command.
1113 * @in_data: Pass anything here.
1114 */
1115struct ec_params_hello {
1116 uint32_t in_data;
1117} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001118
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001119/**
1120 * struct ec_response_hello - Response to the hello command.
1121 * @out_data: Output will be in_data + 0x01020304.
1122 */
1123struct ec_response_hello {
1124 uint32_t out_data;
1125} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001126
1127/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001128#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001129
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001130#if !defined(CHROMIUM_EC) && !defined(__KERNEL__)
1131/*
1132 * enum ec_current_image is deprecated and replaced by enum ec_image. This
1133 * macro exists for backwards compatibility of external projects until they
1134 * have been updated: b/149987779.
1135 */
1136#define ec_current_image ec_image
1137#endif
1138
1139enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001140 EC_IMAGE_UNKNOWN = 0,
1141 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001142 EC_IMAGE_RW,
1143 EC_IMAGE_RW_A = EC_IMAGE_RW,
1144 EC_IMAGE_RO_B,
1145 EC_IMAGE_RW_B
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001146};
1147
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001148/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001149 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001150 * @version_string_ro: Null-terminated RO firmware version string.
1151 * @version_string_rw: Null-terminated RW firmware version string.
1152 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001153 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001154 */
1155struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001156 char version_string_ro[32];
1157 char version_string_rw[32];
Rob Barnes5ab14662021-09-17 10:24:45 -06001158 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001159 uint32_t current_image;
1160} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001161
Rob Barnes5ab14662021-09-17 10:24:45 -06001162/**
1163 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1164 *
1165 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1166 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1167 * and adds one additional field (cros_fwid_rw).
1168 *
1169 * @version_string_ro: Null-terminated RO firmware version string.
1170 * @version_string_rw: Null-terminated RW firmware version string.
1171 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1172 * @current_image: One of ec_image.
1173 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1174 */
1175struct ec_response_get_version_v1 {
1176 char version_string_ro[32];
1177 char version_string_rw[32];
1178 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
1179 uint32_t current_image;
1180 char cros_fwid_rw[32]; /* Added in version 1 */
1181} __ec_align4;
1182
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001183/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001184#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001185
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001186/**
1187 * struct ec_params_read_test - Parameters for the read test command.
1188 * @offset: Starting value for read buffer.
1189 * @size: Size to read in bytes.
1190 */
1191struct ec_params_read_test {
1192 uint32_t offset;
1193 uint32_t size;
1194} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001195
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001196/**
1197 * struct ec_response_read_test - Response to the read test command.
1198 * @data: Data returned by the read test command.
1199 */
1200struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001201 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001202} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001203
1204/*
1205 * Get build information
1206 *
1207 * Response is null-terminated string.
1208 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001209#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001210
1211/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001212#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001213
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001214/**
1215 * struct ec_response_get_chip_info - Response to the get chip info command.
1216 * @vendor: Null-terminated string for chip vendor.
1217 * @name: Null-terminated string for chip name.
1218 * @revision: Null-terminated string for chip mask version.
1219 */
1220struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001221 char vendor[32];
1222 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001223 char revision[32];
1224} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001225
1226/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001227#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001228
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001229/**
1230 * struct ec_response_board_version - Response to the board version command.
1231 * @board_version: A monotonously incrementing number.
1232 */
1233struct ec_response_board_version {
1234 uint16_t board_version;
1235} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001236
1237/*
1238 * Read memory-mapped data.
1239 *
1240 * This is an alternate interface to memory-mapped data for bus protocols
1241 * which don't support direct-mapped memory - I2C, SPI, etc.
1242 *
1243 * Response is params.size bytes of data.
1244 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001245#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001246
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001247/**
1248 * struct ec_params_read_memmap - Parameters for the read memory map command.
1249 * @offset: Offset in memmap (EC_MEMMAP_*).
1250 * @size: Size to read in bytes.
1251 */
1252struct ec_params_read_memmap {
1253 uint8_t offset;
1254 uint8_t size;
1255} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001256
1257/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001258#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001259
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001260/**
1261 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1262 * @cmd: Command to check.
1263 */
1264struct ec_params_get_cmd_versions {
1265 uint8_t cmd;
1266} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001267
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001268/**
1269 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1270 * versions (v1)
1271 * @cmd: Command to check.
1272 */
1273struct ec_params_get_cmd_versions_v1 {
1274 uint16_t cmd;
1275} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001276
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001277/**
1278 * struct ec_response_get_cmd_version - Response to the get command versions.
1279 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1280 * a desired version.
1281 */
1282struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001283 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001284} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001285
Duncan Laurie433432b2013-06-03 10:38:22 -07001286/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001287 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001288 * on lpc since it has its own out-of-band busy indicator.
1289 *
1290 * lpc must read the status from the command register. Attempting this on
1291 * lpc will overwrite the args/parameter space and corrupt its data.
1292 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001293#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001294
1295/* Avoid using ec_status which is for return values */
1296enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001297 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001298};
1299
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001300/**
1301 * struct ec_response_get_comms_status - Response to the get comms status
1302 * command.
1303 * @flags: Mask of enum ec_comms_status.
1304 */
1305struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001306 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001307} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001308
Duncan Laurie93e24442014-01-06 12:30:52 -08001309/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001310#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001311
1312/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001313struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001314 uint32_t ec_result;
1315 uint32_t ret_len;
1316 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001317} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001318
1319/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001320struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001321 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001322} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001323
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001324/* Get protocol information */
1325#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001326
1327/* Flags for ec_response_get_protocol_info.flags */
1328/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001329#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001330
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001331/**
1332 * struct ec_response_get_protocol_info - Response to the get protocol info.
1333 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1334 * version n).
1335 * @max_request_packet_size: Maximum request packet size in bytes.
1336 * @max_response_packet_size: Maximum response packet size in bytes.
1337 * @flags: see EC_PROTOCOL_INFO_*
1338 */
1339struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001340 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001341 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001342 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001343 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001344 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001345} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001346
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001347
Duncan Laurie93e24442014-01-06 12:30:52 -08001348/*****************************************************************************/
1349/* Get/Set miscellaneous values */
1350
1351/* The upper byte of .flags tells what to do (nothing means "get") */
1352#define EC_GSV_SET 0x80000000
1353
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001354/*
1355 * The lower three bytes of .flags identifies the parameter, if that has
1356 * meaning for an individual command.
1357 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001358#define EC_GSV_PARAM_MASK 0x00ffffff
1359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001360struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001361 uint32_t flags;
1362 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001363} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001364
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001365struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001366 uint32_t flags;
1367 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001368} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001369
Duncan Laurieeb316852015-12-01 18:51:18 -08001370/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001371#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001372
Duncan Laurieeb316852015-12-01 18:51:18 -08001373/*****************************************************************************/
1374/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001375#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001376
1377/* Supported features */
1378enum ec_feature_code {
1379 /*
1380 * This image contains a limited set of features. Another image
1381 * in RW partition may support more features.
1382 */
1383 EC_FEATURE_LIMITED = 0,
1384 /*
1385 * Commands for probing/reading/writing/erasing the flash in the
1386 * EC are present.
1387 */
1388 EC_FEATURE_FLASH = 1,
1389 /*
1390 * Can control the fan speed directly.
1391 */
1392 EC_FEATURE_PWM_FAN = 2,
1393 /*
1394 * Can control the intensity of the keyboard backlight.
1395 */
1396 EC_FEATURE_PWM_KEYB = 3,
1397 /*
1398 * Support Google lightbar, introduced on Pixel.
1399 */
1400 EC_FEATURE_LIGHTBAR = 4,
1401 /* Control of LEDs */
1402 EC_FEATURE_LED = 5,
1403 /* Exposes an interface to control gyro and sensors.
1404 * The host goes through the EC to access these sensors.
1405 * In addition, the EC may provide composite sensors, like lid angle.
1406 */
1407 EC_FEATURE_MOTION_SENSE = 6,
1408 /* The keyboard is controlled by the EC */
1409 EC_FEATURE_KEYB = 7,
1410 /* The AP can use part of the EC flash as persistent storage. */
1411 EC_FEATURE_PSTORE = 8,
1412 /* The EC monitors BIOS port 80h, and can return POST codes. */
1413 EC_FEATURE_PORT80 = 9,
1414 /*
1415 * Thermal management: include TMP specific commands.
1416 * Higher level than direct fan control.
1417 */
1418 EC_FEATURE_THERMAL = 10,
1419 /* Can switch the screen backlight on/off */
1420 EC_FEATURE_BKLIGHT_SWITCH = 11,
1421 /* Can switch the wifi module on/off */
1422 EC_FEATURE_WIFI_SWITCH = 12,
1423 /* Monitor host events, through for example SMI or SCI */
1424 EC_FEATURE_HOST_EVENTS = 13,
1425 /* The EC exposes GPIO commands to control/monitor connected devices. */
1426 EC_FEATURE_GPIO = 14,
1427 /* The EC can send i2c messages to downstream devices. */
1428 EC_FEATURE_I2C = 15,
1429 /* Command to control charger are included */
1430 EC_FEATURE_CHARGER = 16,
1431 /* Simple battery support. */
1432 EC_FEATURE_BATTERY = 17,
1433 /*
1434 * Support Smart battery protocol
1435 * (Common Smart Battery System Interface Specification)
1436 */
1437 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001438 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001439 EC_FEATURE_HANG_DETECT = 19,
1440 /* Report power information, for pit only */
1441 EC_FEATURE_PMU = 20,
1442 /* Another Cros EC device is present downstream of this one */
1443 EC_FEATURE_SUB_MCU = 21,
1444 /* Support USB Power delivery (PD) commands */
1445 EC_FEATURE_USB_PD = 22,
1446 /* Control USB multiplexer, for audio through USB port for instance. */
1447 EC_FEATURE_USB_MUX = 23,
1448 /* Motion Sensor code has an internal software FIFO */
1449 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1450 /* Support temporary secure vstore */
1451 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001452 /* EC decides on USB-C SS mux state, muxes configured by host */
1453 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1454 /* EC has RTC feature that can be controlled by host commands */
1455 EC_FEATURE_RTC = 27,
1456 /* The MCU exposes a Fingerprint sensor */
1457 EC_FEATURE_FINGERPRINT = 28,
1458 /* The MCU exposes a Touchpad */
1459 EC_FEATURE_TOUCHPAD = 29,
1460 /* The MCU has RWSIG task enabled */
1461 EC_FEATURE_RWSIG = 30,
1462 /* EC has device events support */
1463 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001464 /* EC supports the unified wake masks for LPC/eSPI systems */
1465 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001466 /* EC supports 64-bit host events */
1467 EC_FEATURE_HOST_EVENT64 = 33,
1468 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1469 EC_FEATURE_EXEC_IN_RAM = 34,
1470 /* EC supports CEC commands */
1471 EC_FEATURE_CEC = 35,
1472 /* EC supports tight sensor timestamping. */
1473 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001474 /*
1475 * EC supports tablet mode detection aligned to Chrome and allows
1476 * setting of threshold by host command using
1477 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1478 */
1479 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001480 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001481 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001482 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1483 * be sent to RO to be precise.
1484 */
1485 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001486 /* The MCU is a System Companion Processor (SCP). */
1487 EC_FEATURE_SCP = 39,
1488 /* The MCU is an Integrated Sensor Hub */
1489 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001490 /* New TCPMv2 TYPEC_ prefaced commands supported */
1491 EC_FEATURE_TYPEC_CMD = 41,
1492 /*
1493 * The EC will wait for direction from the AP to enter Type-C alternate
1494 * modes or USB4.
1495 */
1496 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1497 /*
1498 * The EC will wait for an acknowledge from the AP after setting the
1499 * mux.
1500 */
1501 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Duncan Laurieeb316852015-12-01 18:51:18 -08001502};
1503
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001504#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1505#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1506
1507struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001508 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001509} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001510
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001511/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001512/* Get the board's SKU ID from EC */
1513#define EC_CMD_GET_SKU_ID 0x000E
1514
Kevin Chiue2bb0592017-09-12 09:13:41 +08001515/* Set SKU ID from AP */
1516#define EC_CMD_SET_SKU_ID 0x000F
1517
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001518struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001519 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001520} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001521
1522/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001523/* Flash commands */
1524
1525/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001526#define EC_CMD_FLASH_INFO 0x0010
1527#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001528
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001529/**
1530 * struct ec_response_flash_info - Response to the flash info command.
1531 * @flash_size: Usable flash size in bytes.
1532 * @write_block_size: Write block size. Write offset and size must be a
1533 * multiple of this.
1534 * @erase_block_size: Erase block size. Erase offset and size must be a
1535 * multiple of this.
1536 * @protect_block_size: Protection block size. Protection offset and size
1537 * must be a multiple of this.
1538 *
1539 * Version 0 returns these fields.
1540 */
1541struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001542 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001543 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001544 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001545 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001546} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001547
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001548/*
1549 * Flags for version 1+ flash info command
1550 * EC flash erases bits to 0 instead of 1.
1551 */
1552#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001553
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001554/*
1555 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001556 * be necessary on a chip where write/erase can be corrupted by other board
1557 * activity, or where the chip needs to enable some sort of programming voltage,
1558 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001559 * chip functionality.
1560 */
1561#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001562
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001563/**
1564 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1565 * @flash_size: Usable flash size in bytes.
1566 * @write_block_size: Write block size. Write offset and size must be a
1567 * multiple of this.
1568 * @erase_block_size: Erase block size. Erase offset and size must be a
1569 * multiple of this.
1570 * @protect_block_size: Protection block size. Protection offset and size
1571 * must be a multiple of this.
1572 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1573 * size is exactly this and offset is a multiple of this.
1574 * For example, an EC may have a write buffer which can do
1575 * half-page operations if data is aligned, and a slower
1576 * word-at-a-time write mode.
1577 * @flags: Flags; see EC_FLASH_INFO_*
1578 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001579 * Version 1 returns the same initial fields as version 0, with additional
1580 * fields following.
1581 *
1582 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001583 * if they did we'd define the version 0 structure as a sub-structure of this
1584 * one.
1585 *
1586 * Version 2 supports flash banks of different sizes:
1587 * The caller specified the number of banks it has preallocated
1588 * (num_banks_desc)
1589 * The EC returns the number of banks describing the flash memory.
1590 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001591 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001592struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001593 /* Version 0 fields; see above for description */
1594 uint32_t flash_size;
1595 uint32_t write_block_size;
1596 uint32_t erase_block_size;
1597 uint32_t protect_block_size;
1598
1599 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001600 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001601 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001602} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001603
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001604struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001605 /* Number of banks to describe */
1606 uint16_t num_banks_desc;
1607 /* Reserved; set 0; ignore on read */
1608 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001609} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001610
1611struct ec_flash_bank {
1612 /* Number of sector is in this bank. */
1613 uint16_t count;
1614 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1615 uint8_t size_exp;
1616 /* Minimal write size for the sectors in this bank */
1617 uint8_t write_size_exp;
1618 /* Erase size for the sectors in this bank */
1619 uint8_t erase_size_exp;
1620 /* Size for write protection, usually identical to erase size. */
1621 uint8_t protect_size_exp;
1622 /* Reserved; set 0; ignore on read */
1623 uint8_t reserved[2];
1624};
1625
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001626struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001627 /* Total flash in the EC. */
1628 uint32_t flash_size;
1629 /* Flags; see EC_FLASH_INFO_* */
1630 uint32_t flags;
1631 /* Maximum size to use to send data to write to the EC. */
1632 uint32_t write_ideal_size;
1633 /* Number of banks present in the EC. */
1634 uint16_t num_banks_total;
1635 /* Number of banks described in banks array. */
1636 uint16_t num_banks_desc;
1637 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001638} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001639
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001640/*
1641 * Read flash
1642 *
1643 * Response is params.size bytes of data.
1644 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001645#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001646
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001647/**
1648 * struct ec_params_flash_read - Parameters for the flash read command.
1649 * @offset: Byte offset to read.
1650 * @size: Size to read in bytes.
1651 */
1652struct ec_params_flash_read {
1653 uint32_t offset;
1654 uint32_t size;
1655} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001656
1657/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001658#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001659#define EC_VER_FLASH_WRITE 1
1660
1661/* Version 0 of the flash command supported only 64 bytes of data */
1662#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001663
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001664/**
1665 * struct ec_params_flash_write - Parameters for the flash write command.
1666 * @offset: Byte offset to write.
1667 * @size: Size to write in bytes.
1668 */
1669struct ec_params_flash_write {
1670 uint32_t offset;
1671 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001672 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001673} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001674
1675/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001676#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001677
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001678/**
1679 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1680 * @offset: Byte offset to erase.
1681 * @size: Size to erase in bytes.
1682 */
1683struct ec_params_flash_erase {
1684 uint32_t offset;
1685 uint32_t size;
1686} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001687
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001688/*
1689 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001690 * subcommands can returns:
1691 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1692 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1693 * EC_RES_ERROR : other errors.
1694 * EC_RES_BUSY : an existing erase operation is in progress.
1695 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1696 *
1697 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1698 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1699 * the proper result.
1700 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1701 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1702 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1703 * permitted while erasing. (For instance, STM32F4).
1704 */
1705enum ec_flash_erase_cmd {
1706 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1707 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1708 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1709};
1710
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001711/**
1712 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1713 * @cmd: One of ec_flash_erase_cmd.
1714 * @reserved: Pad byte; currently always contains 0.
1715 * @flag: No flags defined yet; set to 0.
1716 * @params: Same as v0 parameters.
1717 */
1718struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001719 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001720 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001721 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001722 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001723} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001724
1725/*
1726 * Get/set flash protection.
1727 *
1728 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1729 * firmware write protect GPIO, not all flags will take effect immediately;
1730 * some flags require a subsequent hard reset to take effect. Check the
1731 * returned flags bits to see what actually happened.
1732 *
1733 * If mask=0, simply returns the current flags state.
1734 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001735#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001736#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1737
1738/* Flags for flash protection */
1739/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001740#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001741/*
1742 * RO flash code protected now. If this bit is set, at-boot status cannot
1743 * be changed.
1744 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001745#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001746/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001747#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001748/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001749#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001750/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001751#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001752/*
1753 * Error - flash protection is in inconsistent state. At least one bank of
1754 * flash which should be protected is not protected. Usually fixed by
1755 * re-requesting the desired flags, or by a hard reset if that fails.
1756 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001757#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001758/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001759#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001760/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001761#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001762/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001763#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001764/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001765#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001766/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001767#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001768
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001769
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001770/**
1771 * struct ec_params_flash_protect - Parameters for the flash protect command.
1772 * @mask: Bits in flags to apply.
1773 * @flags: New flags to apply.
1774 */
1775struct ec_params_flash_protect {
1776 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001777 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001778} __ec_align4;
1779
1780/**
1781 * struct ec_response_flash_protect - Response to the flash protect command.
1782 * @flags: Current value of flash protect flags.
1783 * @valid_flags: Flags which are valid on this platform. This allows the
1784 * caller to distinguish between flags which aren't set vs. flags
1785 * which can't be set on this platform.
1786 * @writable_flags: Flags which can be changed given the current protection
1787 * state.
1788 */
1789struct ec_response_flash_protect {
1790 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001791 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001792 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001793} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001794
1795/*
1796 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1797 * write protect. These commands may be reused with version > 0.
1798 */
1799
1800/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001801#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001802#define EC_VER_FLASH_REGION_INFO 1
1803
1804enum ec_flash_region {
1805 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001806 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001807 /*
1808 * Region which holds active RW image. 'Active' is different from
1809 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1810 * scheduled to run, active/non-active applies only to RW images (for
1811 * the same reason 'update' applies only to RW images. It's a state of
1812 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1813 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1814 * doesn't enter 'running' state but it's still active on a flash.
1815 */
1816 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001817 /*
1818 * Region which should be write-protected in the factory (a superset of
1819 * EC_FLASH_REGION_RO)
1820 */
1821 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001822 /* Region which holds updatable (non-active) RW image */
1823 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001824 /* Number of regions */
1825 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001826};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001827/*
1828 * 'RW' is vague if there are multiple RW images; we mean the active one,
1829 * so the old constant is deprecated.
1830 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001831#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001832
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001833/**
1834 * struct ec_params_flash_region_info - Parameters for the flash region info
1835 * command.
1836 * @region: Flash region; see EC_FLASH_REGION_*
1837 */
1838struct ec_params_flash_region_info {
1839 uint32_t region;
1840} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001841
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001842struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001843 uint32_t offset;
1844 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001845} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001846
Rob Barnes8bc5fa92021-06-28 09:32:28 -06001847/*
1848 * Read/write VbNvContext
1849 *
1850 * Deprecated as of February 2021. No current devices use VBNV in EC
1851 * BBRAM anymore, so this is guaranteed to fail.
1852 *
1853 * TODO(b/178689388): remove from this header once no external
1854 * dependencies reference these constants.
1855 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001856#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001857#define EC_VER_VBNV_CONTEXT 1
1858#define EC_VBNV_BLOCK_SIZE 16
1859
1860enum ec_vbnvcontext_op {
1861 EC_VBNV_CONTEXT_OP_READ,
1862 EC_VBNV_CONTEXT_OP_WRITE,
1863};
1864
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001865struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001866 uint32_t op;
1867 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001868} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001869
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001870struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001871 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001872} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001873
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001874
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001875/* Get SPI flash information */
1876#define EC_CMD_FLASH_SPI_INFO 0x0018
1877
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001878struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001879 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1880 uint8_t jedec[3];
1881
1882 /* Pad byte; currently always contains 0 */
1883 uint8_t reserved0;
1884
1885 /* Manufacturer / device ID from command 0x90 */
1886 uint8_t mfr_dev_id[2];
1887
1888 /* Status registers from command 0x05 and 0x35 */
1889 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001890} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001891
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001892
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001893/* Select flash during flash operations */
1894#define EC_CMD_FLASH_SELECT 0x0019
1895
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001896/**
1897 * struct ec_params_flash_select - Parameters for the flash select command.
1898 * @select: 1 to select flash, 0 to deselect flash
1899 */
1900struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001901 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001902} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001903
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001904
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001905/**
1906 * Request random numbers to be generated and returned.
1907 * Can be used to test the random number generator is truly random.
1908 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1909 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1910 */
1911#define EC_CMD_RAND_NUM 0x001A
1912#define EC_VER_RAND_NUM 0
1913
1914struct ec_params_rand_num {
1915 uint16_t num_rand_bytes; /**< num random bytes to generate */
1916} __ec_align4;
1917
1918struct ec_response_rand_num {
1919 uint8_t rand[0]; /**< generated random numbers */
1920} __ec_align4;
1921
1922BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1923
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001924/**
1925 * Get information about the key used to sign the RW firmware.
1926 * For more details on the fields, see "struct vb21_packed_key".
1927 */
1928#define EC_CMD_RWSIG_INFO 0x001B
1929#define EC_VER_RWSIG_INFO 0
1930
1931#define VBOOT2_KEY_ID_BYTES 20
1932
1933#ifdef CHROMIUM_EC
1934/* Don't force external projects to depend on the vboot headers. */
1935#include "vb21_struct.h"
1936BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1937#endif
1938
1939struct ec_response_rwsig_info {
1940 /**
1941 * Signature algorithm used by the key
1942 * (enum vb2_signature_algorithm).
1943 */
1944 uint16_t sig_alg;
1945
1946 /**
1947 * Hash digest algorithm used with the key
1948 * (enum vb2_hash_algorithm).
1949 */
1950 uint16_t hash_alg;
1951
1952 /** Key version. */
1953 uint32_t key_version;
1954
1955 /** Key ID (struct vb2_id). */
1956 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
1957
1958 uint8_t key_is_valid;
1959
1960 /** Alignment padding. */
1961 uint8_t reserved[3];
1962} __ec_align4;
1963
1964BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
1965
1966/**
1967 * Get information about the system, such as reset flags, locked state, etc.
1968 */
1969#define EC_CMD_SYSINFO 0x001C
1970#define EC_VER_SYSINFO 0
1971
1972enum sysinfo_flags {
1973 SYSTEM_IS_LOCKED = BIT(0),
1974 SYSTEM_IS_FORCE_LOCKED = BIT(1),
1975 SYSTEM_JUMP_ENABLED = BIT(2),
1976 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08001977 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
1978 /*
1979 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
1980 * set and cleared when the system shuts down (not when the host event
1981 * flag is cleared).
1982 */
1983 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001984};
1985
1986struct ec_response_sysinfo {
1987 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
1988 uint32_t current_image; /**< enum ec_current_image */
1989 uint32_t flags; /**< enum sysinfo_flags */
1990} __ec_align4;
1991
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001992/*****************************************************************************/
1993/* PWM commands */
1994
1995/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001996#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001997
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001998struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001999 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002000} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002001
2002/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002003#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002004
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002005/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002006struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002007 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002008} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002009
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002010/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002011struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002012 uint32_t rpm;
2013 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002014} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002016/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002017/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002018#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002019
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002020struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002021 uint8_t percent;
2022 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002023} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002024
2025/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002026/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002027#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002028
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002029struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002030 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002031} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002032
2033/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002034#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002035
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002036/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002037struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002038 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002039} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002040
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002041/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002042struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002043 uint32_t percent;
2044 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002045} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002046
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002047#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002048/* 16 bit duty cycle, 0xffff = 100% */
2049#define EC_PWM_MAX_DUTY 0xffff
2050
2051enum ec_pwm_type {
2052 /* All types, indexed by board-specific enum pwm_channel */
2053 EC_PWM_TYPE_GENERIC = 0,
2054 /* Keyboard backlight */
2055 EC_PWM_TYPE_KB_LIGHT,
2056 /* Display backlight */
2057 EC_PWM_TYPE_DISPLAY_LIGHT,
2058 EC_PWM_TYPE_COUNT,
2059};
2060
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002061struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002062 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2063 uint8_t pwm_type; /* ec_pwm_type */
2064 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002065} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002066
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002067#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002068
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002069struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002070 uint8_t pwm_type; /* ec_pwm_type */
2071 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002072} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002073
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002074struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002075 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002076} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002077
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002078/*****************************************************************************/
2079/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002080 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002081 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2082 * into a subcommand. We'll make separate structs for subcommands with
2083 * different input args, so that we know how much to expect.
2084 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002085#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002086
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002087struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002088 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002089} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002090
Duncan Laurie433432b2013-06-03 10:38:22 -07002091#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002092
2093/*
2094 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002095 * host command, but the alignment is the same regardless. Keep it that way.
2096 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002097struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002098 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002099 int32_t google_ramp_up;
2100 int32_t google_ramp_down;
2101 int32_t s3s0_ramp_up;
2102 int32_t s0_tick_delay[2]; /* AC=0/1 */
2103 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2104 int32_t s0s3_ramp_down;
2105 int32_t s3_sleep_for;
2106 int32_t s3_ramp_up;
2107 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002108
2109 /* Oscillation */
2110 uint8_t new_s0;
2111 uint8_t osc_min[2]; /* AC=0/1 */
2112 uint8_t osc_max[2]; /* AC=0/1 */
2113 uint8_t w_ofs[2]; /* AC=0/1 */
2114
2115 /* Brightness limits based on the backlight and AC. */
2116 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2117 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2118 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2119
2120 /* Battery level thresholds */
2121 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2122
2123 /* Map [AC][battery_level] to color index */
2124 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2125 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2126
2127 /* Color palette */
2128 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002129} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002130
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002131struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002132 /* Timing */
2133 int32_t google_ramp_up;
2134 int32_t google_ramp_down;
2135 int32_t s3s0_ramp_up;
2136 int32_t s0_tick_delay[2]; /* AC=0/1 */
2137 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2138 int32_t s0s3_ramp_down;
2139 int32_t s3_sleep_for;
2140 int32_t s3_ramp_up;
2141 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002142 int32_t s5_ramp_up;
2143 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002144 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002145 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002146 int32_t tap_display_time;
2147
2148 /* Tap-for-battery params */
2149 uint8_t tap_pct_red;
2150 uint8_t tap_pct_green;
2151 uint8_t tap_seg_min_on;
2152 uint8_t tap_seg_max_on;
2153 uint8_t tap_seg_osc;
2154 uint8_t tap_idx[3];
2155
2156 /* Oscillation */
2157 uint8_t osc_min[2]; /* AC=0/1 */
2158 uint8_t osc_max[2]; /* AC=0/1 */
2159 uint8_t w_ofs[2]; /* AC=0/1 */
2160
2161 /* Brightness limits based on the backlight and AC. */
2162 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2163 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2164 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2165
2166 /* Battery level thresholds */
2167 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2168
2169 /* Map [AC][battery_level] to color index */
2170 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2171 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2172
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002173 /* s5: single color pulse on inhibited power-up */
2174 uint8_t s5_idx;
2175
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002176 /* Color palette */
2177 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002178} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002179
Duncan Laurieeb316852015-12-01 18:51:18 -08002180/* Lightbar command params v2
2181 * crbug.com/467716
2182 *
2183 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2184 * logical groups to make it more manageable ( < 120 bytes).
2185 *
2186 * NOTE: Each of these groups must be less than 120 bytes.
2187 */
2188
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002189struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002190 /* Timing */
2191 int32_t google_ramp_up;
2192 int32_t google_ramp_down;
2193 int32_t s3s0_ramp_up;
2194 int32_t s0_tick_delay[2]; /* AC=0/1 */
2195 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2196 int32_t s0s3_ramp_down;
2197 int32_t s3_sleep_for;
2198 int32_t s3_ramp_up;
2199 int32_t s3_ramp_down;
2200 int32_t s5_ramp_up;
2201 int32_t s5_ramp_down;
2202 int32_t tap_tick_delay;
2203 int32_t tap_gate_delay;
2204 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002205} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002206
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002207struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002208 /* Tap-for-battery params */
2209 uint8_t tap_pct_red;
2210 uint8_t tap_pct_green;
2211 uint8_t tap_seg_min_on;
2212 uint8_t tap_seg_max_on;
2213 uint8_t tap_seg_osc;
2214 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002215} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002217struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002218 /* Oscillation */
2219 uint8_t osc_min[2]; /* AC=0/1 */
2220 uint8_t osc_max[2]; /* AC=0/1 */
2221 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002222} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002223
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002224struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002225 /* Brightness limits based on the backlight and AC. */
2226 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2227 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2228 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002229} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002230
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002231struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002232 /* Battery level thresholds */
2233 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002234} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002235
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002236struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002237 /* Map [AC][battery_level] to color index */
2238 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2239 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2240
2241 /* s5: single color pulse on inhibited power-up */
2242 uint8_t s5_idx;
2243
2244 /* Color palette */
2245 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002246} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002247
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002248/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002249#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002250struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002251 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002252 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002253} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002254
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002255struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002256 uint8_t cmd; /* Command (see enum lightbar_command) */
2257 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002258 /*
2259 * The following commands have no args:
2260 *
2261 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2262 * version, get_brightness, get_demo, suspend, resume,
2263 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2264 * get_params_v2_bright, get_params_v2_thlds,
2265 * get_params_v2_colors
2266 *
2267 * Don't use an empty struct, because C++ hates that.
2268 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002269
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002270 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002271 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002272 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002273
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002274 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002275 uint8_t ctrl, reg, value;
2276 } reg;
2277
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002278 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002279 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002280 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002281
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002282 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002283 uint8_t led;
2284 } get_rgb;
2285
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002286 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002287 uint8_t enable;
2288 } manual_suspend_ctrl;
2289
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002290 struct lightbar_params_v0 set_params_v0;
2291 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002292
2293 struct lightbar_params_v2_timing set_v2par_timing;
2294 struct lightbar_params_v2_tap set_v2par_tap;
2295 struct lightbar_params_v2_oscillation set_v2par_osc;
2296 struct lightbar_params_v2_brightness set_v2par_bright;
2297 struct lightbar_params_v2_thresholds set_v2par_thlds;
2298 struct lightbar_params_v2_colors set_v2par_colors;
2299
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002300 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002301 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002302} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002303
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002304struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002305 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002306 struct __ec_todo_unpacked {
2307 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002308 uint8_t reg;
2309 uint8_t ic0;
2310 uint8_t ic1;
2311 } vals[23];
2312 } dump;
2313
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002314 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002315 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002316 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002317
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002318 struct lightbar_params_v0 get_params_v0;
2319 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002320
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002321
Duncan Laurieeb316852015-12-01 18:51:18 -08002322 struct lightbar_params_v2_timing get_params_v2_timing;
2323 struct lightbar_params_v2_tap get_params_v2_tap;
2324 struct lightbar_params_v2_oscillation get_params_v2_osc;
2325 struct lightbar_params_v2_brightness get_params_v2_bright;
2326 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2327 struct lightbar_params_v2_colors get_params_v2_colors;
2328
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002329 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002330 uint32_t num;
2331 uint32_t flags;
2332 } version;
2333
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002334 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002335 uint8_t red, green, blue;
2336 } get_rgb;
2337
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002338 /*
2339 * The following commands have no response:
2340 *
2341 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2342 * set_params_v0, set_params_v1, set_program,
2343 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2344 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2345 * set_v2par_thlds, set_v2par_colors
2346 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002347 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002348} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002349
2350/* Lightbar commands */
2351enum lightbar_command {
2352 LIGHTBAR_CMD_DUMP = 0,
2353 LIGHTBAR_CMD_OFF = 1,
2354 LIGHTBAR_CMD_ON = 2,
2355 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002356 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002357 LIGHTBAR_CMD_SEQ = 5,
2358 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002359 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002360 LIGHTBAR_CMD_GET_SEQ = 8,
2361 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002362 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2363 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002364 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002365 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2366 LIGHTBAR_CMD_GET_RGB = 14,
2367 LIGHTBAR_CMD_GET_DEMO = 15,
2368 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2369 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002370 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002371 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2372 LIGHTBAR_CMD_SUSPEND = 20,
2373 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002374 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2375 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2376 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2377 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2378 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2379 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2380 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2381 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2382 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2383 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2384 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2385 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002386 LIGHTBAR_NUM_CMDS
2387};
2388
2389/*****************************************************************************/
2390/* LED control commands */
2391
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002392#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002393
Bill Richardsone221aad2013-06-12 10:50:41 -07002394enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002395 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002396 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002397 /*
2398 * LED to indicate system power state (on or in suspend).
2399 * May be on power button or on C-panel.
2400 */
2401 EC_LED_ID_POWER_LED,
2402 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002403 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002404 /* LED to indicate left side */
2405 EC_LED_ID_LEFT_LED,
2406 /* LED to indicate right side */
2407 EC_LED_ID_RIGHT_LED,
2408 /* LED to indicate recovery mode with HW_REINIT */
2409 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2410 /* LED to indicate sysrq debug mode. */
2411 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002412
2413 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002414};
Duncan Laurie433432b2013-06-03 10:38:22 -07002415
Bill Richardsone221aad2013-06-12 10:50:41 -07002416/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002417#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2418#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002419
2420enum ec_led_colors {
2421 EC_LED_COLOR_RED = 0,
2422 EC_LED_COLOR_GREEN,
2423 EC_LED_COLOR_BLUE,
2424 EC_LED_COLOR_YELLOW,
2425 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002426 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002427
2428 EC_LED_COLOR_COUNT
2429};
2430
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002431struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002432 uint8_t led_id; /* Which LED to control */
2433 uint8_t flags; /* Control flags */
2434
2435 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002436} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002437
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002438struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002439 /*
2440 * Available brightness value range.
2441 *
2442 * Range 0 means color channel not present.
2443 * Range 1 means on/off control.
2444 * Other values means the LED is control by PWM.
2445 */
2446 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002447} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002448
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002449/*****************************************************************************/
2450/* Verified boot commands */
2451
2452/*
2453 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2454 * reused for other purposes with version > 0.
2455 */
2456
2457/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002458#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002459
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002460struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002461 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2462 uint8_t hash_type; /* enum ec_vboot_hash_type */
2463 uint8_t nonce_size; /* Nonce size; may be 0 */
2464 uint8_t reserved0; /* Reserved; set 0 */
2465 uint32_t offset; /* Offset in flash to hash */
2466 uint32_t size; /* Number of bytes to hash */
2467 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002468} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002469
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002470struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002471 uint8_t status; /* enum ec_vboot_hash_status */
2472 uint8_t hash_type; /* enum ec_vboot_hash_type */
2473 uint8_t digest_size; /* Size of hash digest in bytes */
2474 uint8_t reserved0; /* Ignore; will be 0 */
2475 uint32_t offset; /* Offset in flash which was hashed */
2476 uint32_t size; /* Number of bytes hashed */
2477 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002478} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002479
2480enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002481 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2482 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2483 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2484 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002485};
2486
2487enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002488 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002489};
2490
2491enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002492 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2493 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2494 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002495};
2496
Duncan Laurie433432b2013-06-03 10:38:22 -07002497/*
2498 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2499 * If one of these is specified, the EC will automatically update offset and
2500 * size to the correct values for the specified image (RO or RW).
2501 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002502#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2503#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2504#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2505
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002506/*
2507 * 'RW' is vague if there are multiple RW images; we mean the active one,
2508 * so the old constant is deprecated.
2509 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002510#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002511
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002512/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002513/*
2514 * Motion sense commands. We'll make separate structs for sub-commands with
2515 * different input args, so that we know how much to expect.
2516 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002517#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002518
2519/* Motion sense commands */
2520enum motionsense_command {
2521 /*
2522 * Dump command returns all motion sensor data including motion sense
2523 * module flags and individual sensor flags.
2524 */
2525 MOTIONSENSE_CMD_DUMP = 0,
2526
2527 /*
2528 * Info command returns data describing the details of a given sensor,
2529 * including enum motionsensor_type, enum motionsensor_location, and
2530 * enum motionsensor_chip.
2531 */
2532 MOTIONSENSE_CMD_INFO = 1,
2533
2534 /*
2535 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002536 * in milliseconds.
2537 * It is per sensor, the EC run sample task at the minimum of all
2538 * sensors EC_RATE.
2539 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2540 * to collect all the sensor samples.
2541 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2542 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002543 */
2544 MOTIONSENSE_CMD_EC_RATE = 2,
2545
2546 /*
2547 * Sensor ODR command is a setter/getter command for the output data
2548 * rate of a specific motion sensor in millihertz.
2549 */
2550 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2551
2552 /*
2553 * Sensor range command is a setter/getter command for the range of
2554 * a specified motion sensor in +/-G's or +/- deg/s.
2555 */
2556 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2557
2558 /*
2559 * Setter/getter command for the keyboard wake angle. When the lid
2560 * angle is greater than this value, keyboard wake is disabled in S3,
2561 * and when the lid angle goes less than this value, keyboard wake is
2562 * enabled. Note, the lid angle measurement is an approximate,
2563 * un-calibrated value, hence the wake angle isn't exact.
2564 */
2565 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2566
Duncan Laurieeb316852015-12-01 18:51:18 -08002567 /*
2568 * Returns a single sensor data.
2569 */
2570 MOTIONSENSE_CMD_DATA = 6,
2571
2572 /*
2573 * Return sensor fifo info.
2574 */
2575 MOTIONSENSE_CMD_FIFO_INFO = 7,
2576
2577 /*
2578 * Insert a flush element in the fifo and return sensor fifo info.
2579 * The host can use that element to synchronize its operation.
2580 */
2581 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2582
2583 /*
2584 * Return a portion of the fifo.
2585 */
2586 MOTIONSENSE_CMD_FIFO_READ = 9,
2587
2588 /*
2589 * Perform low level calibration.
2590 * On sensors that support it, ask to do offset calibration.
2591 */
2592 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2593
2594 /*
2595 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002596 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002597 * The offsets can be calculated by the host, or via
2598 * PERFORM_CALIB command.
2599 */
2600 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2601
2602 /*
2603 * List available activities for a MOTION sensor.
2604 * Indicates if they are enabled or disabled.
2605 */
2606 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2607
2608 /*
2609 * Activity management
2610 * Enable/Disable activity recognition.
2611 */
2612 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2613
2614 /*
2615 * Lid Angle
2616 */
2617 MOTIONSENSE_CMD_LID_ANGLE = 14,
2618
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002619 /*
2620 * Allow the FIFO to trigger interrupt via MKBP events.
2621 * By default the FIFO does not send interrupt to process the FIFO
2622 * until the AP is ready or it is coming from a wakeup sensor.
2623 */
2624 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2625
2626 /*
2627 * Spoof the readings of the sensors. The spoofed readings can be set
2628 * to arbitrary values, or will lock to the last read actual values.
2629 */
2630 MOTIONSENSE_CMD_SPOOF = 16,
2631
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002632 /* Set lid angle for tablet mode detection. */
2633 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2634
2635 /*
2636 * Sensor Scale command is a setter/getter command for the calibration
2637 * scale.
2638 */
2639 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2640
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002641 /*
2642 * Read the current online calibration values (if available).
2643 */
2644 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2645
Yidi Lin42f79592020-09-21 18:04:10 +08002646 /*
2647 * Activity management
2648 * Retrieve current status of given activity.
2649 */
2650 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2651
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002652 /* Number of motionsense sub-commands. */
2653 MOTIONSENSE_NUM_CMDS
2654};
2655
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002656/* List of motion sensor types. */
2657enum motionsensor_type {
2658 MOTIONSENSE_TYPE_ACCEL = 0,
2659 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002660 MOTIONSENSE_TYPE_MAG = 2,
2661 MOTIONSENSE_TYPE_PROX = 3,
2662 MOTIONSENSE_TYPE_LIGHT = 4,
2663 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002664 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002665 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002666 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002667 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002668};
2669
2670/* List of motion sensor locations. */
2671enum motionsensor_location {
2672 MOTIONSENSE_LOC_BASE = 0,
2673 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002674 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002675 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002676};
2677
2678/* List of motion sensor chips. */
2679enum motionsensor_chip {
2680 MOTIONSENSE_CHIP_KXCJ9 = 0,
2681 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002682 MOTIONSENSE_CHIP_BMI160 = 2,
2683 MOTIONSENSE_CHIP_SI1141 = 3,
2684 MOTIONSENSE_CHIP_SI1142 = 4,
2685 MOTIONSENSE_CHIP_SI1143 = 5,
2686 MOTIONSENSE_CHIP_KX022 = 6,
2687 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002688 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002689 MOTIONSENSE_CHIP_BMP280 = 9,
2690 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002691 MOTIONSENSE_CHIP_BH1730 = 11,
2692 MOTIONSENSE_CHIP_GPIO = 12,
2693 MOTIONSENSE_CHIP_LIS2DH = 13,
2694 MOTIONSENSE_CHIP_LSM6DSM = 14,
2695 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002696 MOTIONSENSE_CHIP_LIS2MDL = 16,
2697 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2698 MOTIONSENSE_CHIP_LSM6DSO = 18,
2699 MOTIONSENSE_CHIP_LNG2DM = 19,
2700 MOTIONSENSE_CHIP_TCS3400 = 20,
2701 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2702 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002703 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002704 MOTIONSENSE_CHIP_BMI260 = 24,
2705 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002706 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002707 MOTIONSENSE_CHIP_BMA422 = 27,
2708 MOTIONSENSE_CHIP_BMI323 = 28,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002709 MOTIONSENSE_CHIP_MAX,
2710};
2711
2712/* List of orientation positions */
2713enum motionsensor_orientation {
2714 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2715 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2716 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2717 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2718 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002719};
2720
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002721struct ec_response_activity_data {
2722 uint8_t activity; /* motionsensor_activity */
2723 uint8_t state;
2724} __ec_todo_packed;
2725
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002726struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002727 /* Flags for each sensor. */
2728 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002729 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002730 uint8_t sensor_num;
2731 /* Each sensor is up to 3-axis. */
2732 union {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002733 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002734 /* for sensors using unsigned data */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002735 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002736 struct __ec_todo_packed {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002737 uint16_t reserved;
2738 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002739 };
2740 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002741 struct ec_response_activity_data activity_data;
2742 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002743 };
2744 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002745} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002746
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002747/* Response to AP reporting calibration data for a given sensor. */
2748struct ec_response_online_calibration_data {
2749 /** The calibration values. */
2750 int16_t data[3];
2751};
2752
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002753/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002754struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002755 /* Size of the fifo */
2756 uint16_t size;
2757 /* Amount of space used in the fifo */
2758 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002759 /* Timestamp recorded in us.
2760 * aka accurate timestamp when host event was triggered.
2761 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002762 uint32_t timestamp;
2763 /* Total amount of vector lost */
2764 uint16_t total_lost;
2765 /* Lost events since the last fifo_info, per sensors */
2766 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002767} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002768
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002769struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002770 uint32_t number_data;
2771 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002772} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002773
2774/* List supported activity recognition */
2775enum motionsensor_activity {
2776 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2777 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2778 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002779 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002780 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002781};
2782
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002783struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002784 uint8_t sensor_num;
2785 uint8_t activity; /* one of enum motionsensor_activity */
2786 uint8_t enable; /* 1: enable, 0: disable */
2787 uint8_t reserved;
2788 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002789} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002790
2791/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002792#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002793
2794/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002795#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002796
2797/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002798 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002799 * data contains time stamp
2800 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002801#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2802#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2803#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2804#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2805#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002806
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002807#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2808
Duncan Laurieeb316852015-12-01 18:51:18 -08002809/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002810 * Send this value for the data element to only perform a read. If you
2811 * send any other value, the EC will interpret it as data to set and will
2812 * return the actual value set.
2813 */
2814#define EC_MOTION_SENSE_NO_VALUE -1
2815
Duncan Laurieeb316852015-12-01 18:51:18 -08002816#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2817
2818/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2819/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002820#define MOTION_SENSE_SET_OFFSET BIT(0)
2821
2822/* Default Scale value, factor 1. */
2823#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002824
2825#define LID_ANGLE_UNRELIABLE 500
2826
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002827enum motionsense_spoof_mode {
2828 /* Disable spoof mode. */
2829 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2830
2831 /* Enable spoof mode, but use provided component values. */
2832 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2833
2834 /* Enable spoof mode, but use the current sensor values. */
2835 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2836
2837 /* Query the current spoof mode status for the sensor. */
2838 MOTIONSENSE_SPOOF_MODE_QUERY,
2839};
2840
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002841struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002842 uint8_t cmd;
2843 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002844 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002845 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002846 /*
2847 * Maximal number of sensor the host is expecting.
2848 * 0 means the host is only interested in the number
2849 * of sensors controlled by the EC.
2850 */
2851 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002852 } dump;
2853
2854 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002855 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002856 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002857 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002858 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2859 * kb_wake_angle: angle to wakup AP.
2860 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002861 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002862 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002863
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002864 /*
2865 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2866 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002867 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002868 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002869 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002870
2871 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002872 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2873 * Allow entering/exiting the calibration mode.
2874 */
2875 struct __ec_todo_unpacked {
2876 uint8_t sensor_num;
2877 uint8_t enable;
2878 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002879
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002880 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002881 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2882 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002883 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002885 uint8_t sensor_num;
2886
2887 /* Rounding flag, true for round-up, false for down. */
2888 uint8_t roundup;
2889
2890 uint16_t reserved;
2891
2892 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2893 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002894 } ec_rate, sensor_odr, sensor_range;
2895
2896 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002897 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002898 uint8_t sensor_num;
2899
2900 /*
2901 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2902 * the calibration information in the EC.
2903 * If unset, just retrieve calibration information.
2904 */
2905 uint16_t flags;
2906
2907 /*
2908 * Temperature at calibration, in units of 0.01 C
2909 * 0x8000: invalid / unknown.
2910 * 0x0: 0C
2911 * 0x7fff: +327.67C
2912 */
2913 int16_t temp;
2914
2915 /*
2916 * Offset for calibration.
2917 * Unit:
2918 * Accelerometer: 1/1024 g
2919 * Gyro: 1/1024 deg/s
2920 * Compass: 1/16 uT
2921 */
2922 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002923 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002924
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002925 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2926 struct __ec_todo_packed {
2927 uint8_t sensor_num;
2928
2929 /*
2930 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2931 * the calibration information in the EC.
2932 * If unset, just retrieve calibration information.
2933 */
2934 uint16_t flags;
2935
2936 /*
2937 * Temperature at calibration, in units of 0.01 C
2938 * 0x8000: invalid / unknown.
2939 * 0x0: 0C
2940 * 0x7fff: +327.67C
2941 */
2942 int16_t temp;
2943
2944 /*
2945 * Scale for calibration:
2946 * By default scale is 1, it is encoded on 16bits:
2947 * 1 = BIT(15)
2948 * ~2 = 0xFFFF
2949 * ~0 = 0.
2950 */
2951 uint16_t scale[3];
2952 } sensor_scale;
2953
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002954
Duncan Laurieeb316852015-12-01 18:51:18 -08002955 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002956 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002957
2958 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002959 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002960 /*
2961 * Number of expected vector to return.
2962 * EC may return less or 0 if none available.
2963 */
2964 uint32_t max_data_vector;
2965 } fifo_read;
2966
Yidi Lin42f79592020-09-21 18:04:10 +08002967 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08002968 struct ec_motion_sense_activity set_activity;
2969
2970 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002971 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002972
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002973 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2974 struct __ec_todo_unpacked {
2975 /*
2976 * 1: enable, 0 disable fifo,
2977 * EC_MOTION_SENSE_NO_VALUE return value.
2978 */
2979 int8_t enable;
2980 } fifo_int_enable;
2981
2982 /* Used for MOTIONSENSE_CMD_SPOOF */
2983 struct __ec_todo_packed {
2984 uint8_t sensor_id;
2985
2986 /* See enum motionsense_spoof_mode. */
2987 uint8_t spoof_enable;
2988
2989 /* Ignored, used for alignment. */
2990 uint8_t reserved;
2991
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002992 union {
2993 /* Individual component values to spoof. */
2994 int16_t components[3];
2995
2996 /* Used when spoofing an activity */
2997 struct {
2998 /* enum motionsensor_activity */
2999 uint8_t activity_num;
3000
3001 /* spoof activity state */
3002 uint8_t activity_state;
3003 };
3004 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003005 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003006
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003007 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3008 struct __ec_todo_unpacked {
3009 /*
3010 * Lid angle threshold for switching between tablet and
3011 * clamshell mode.
3012 */
3013 int16_t lid_angle;
3014
3015 /*
3016 * Hysteresis degree to prevent fluctuations between
3017 * clamshell and tablet mode if lid angle keeps
3018 * changing around the threshold. Lid motion driver will
3019 * use lid_angle + hys_degree to trigger tablet mode and
3020 * lid_angle - hys_degree to trigger clamshell mode.
3021 */
3022 int16_t hys_degree;
3023 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003024
3025 /*
3026 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3027 * Allow reading a single sensor's online calibration value.
3028 */
3029 struct __ec_todo_unpacked {
3030 uint8_t sensor_num;
3031 } online_calib_read;
3032
Yidi Lin42f79592020-09-21 18:04:10 +08003033 /*
3034 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3035 */
3036 struct __ec_todo_unpacked {
3037 uint8_t sensor_num;
3038 uint8_t activity; /* enum motionsensor_activity */
3039 } get_activity;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003040 };
3041} __ec_todo_packed;
3042
Jett Rinkba2edaf2020-01-14 11:49:06 -07003043enum motion_sense_cmd_info_flags {
3044 /* The sensor supports online calibration */
3045 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3046};
3047
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003048struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003049 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003050 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003051 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003052 /* Flags representing the motion sensor module. */
3053 uint8_t module_flags;
3054
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003055 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003056 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003057
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003058 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003059 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003060 * for holding all the data.
3061 */
3062 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003063 } dump;
3064
3065 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003066 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003067 /* Should be element of enum motionsensor_type. */
3068 uint8_t type;
3069
3070 /* Should be element of enum motionsensor_location. */
3071 uint8_t location;
3072
3073 /* Should be element of enum motionsensor_chip. */
3074 uint8_t chip;
3075 } info;
3076
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003077 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3078 struct __ec_todo_unpacked {
3079 /* Should be element of enum motionsensor_type. */
3080 uint8_t type;
3081
3082 /* Should be element of enum motionsensor_location. */
3083 uint8_t location;
3084
3085 /* Should be element of enum motionsensor_chip. */
3086 uint8_t chip;
3087
3088 /* Minimum sensor sampling frequency */
3089 uint32_t min_frequency;
3090
3091 /* Maximum sensor sampling frequency */
3092 uint32_t max_frequency;
3093
3094 /* Max number of sensor events that could be in fifo */
3095 uint32_t fifo_max_event_count;
3096 } info_3;
3097
Jett Rinkba2edaf2020-01-14 11:49:06 -07003098 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3099 struct __ec_align4 {
3100 /* Should be element of enum motionsensor_type. */
3101 uint8_t type;
3102
3103 /* Should be element of enum motionsensor_location. */
3104 uint8_t location;
3105
3106 /* Should be element of enum motionsensor_chip. */
3107 uint8_t chip;
3108
3109 /* Minimum sensor sampling frequency */
3110 uint32_t min_frequency;
3111
3112 /* Maximum sensor sampling frequency */
3113 uint32_t max_frequency;
3114
3115 /* Max number of sensor events that could be in fifo */
3116 uint32_t fifo_max_event_count;
3117
3118 /*
3119 * Should be elements of
3120 * enum motion_sense_cmd_info_flags
3121 */
3122 uint32_t flags;
3123 } info_4;
3124
Duncan Laurieeb316852015-12-01 18:51:18 -08003125 /* Used for MOTIONSENSE_CMD_DATA */
3126 struct ec_response_motion_sensor_data data;
3127
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003128 /*
3129 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003130 * MOTIONSENSE_CMD_SENSOR_RANGE,
3131 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3132 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3133 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003134 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003135 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003136 /* Current value of the parameter queried. */
3137 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003138 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
3139 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003140
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003141 /*
3142 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3143 * PERFORM_CALIB.
3144 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003145 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003146 int16_t temp;
3147 int16_t offset[3];
3148 } sensor_offset, perform_calib;
3149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003150 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3151 struct __ec_todo_unpacked {
3152 int16_t temp;
3153 uint16_t scale[3];
3154 } sensor_scale;
3155
Duncan Laurieeb316852015-12-01 18:51:18 -08003156 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3157
3158 struct ec_response_motion_sense_fifo_data fifo_read;
3159
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003160 struct ec_response_online_calibration_data online_calib_read;
3161
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003162 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003163 uint16_t reserved;
3164 uint32_t enabled;
3165 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003166 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003167
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003168 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003169
Duncan Laurieeb316852015-12-01 18:51:18 -08003170 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003171 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003172 /*
3173 * Angle between 0 and 360 degree if available,
3174 * LID_ANGLE_UNRELIABLE otherwise.
3175 */
3176 uint16_t value;
3177 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003178
3179 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3180 struct __ec_todo_unpacked {
3181 /*
3182 * Lid angle threshold for switching between tablet and
3183 * clamshell mode.
3184 */
3185 uint16_t lid_angle;
3186
3187 /* Hysteresis degree. */
3188 uint16_t hys_degree;
3189 } tablet_mode_threshold;
3190
Yidi Lin42f79592020-09-21 18:04:10 +08003191 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3192 struct __ec_todo_unpacked {
3193 uint8_t state;
3194 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003195 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003196} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003197
3198/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003199/* Force lid open command */
3200
3201/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003202#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003203
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003204struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003205 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003206} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003207
3208/*****************************************************************************/
3209/* Configure the behavior of the power button */
3210#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3211
3212enum ec_config_power_button_flags {
3213 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003214 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003215};
3216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003217struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003218 /* See enum ec_config_power_button_flags */
3219 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003220} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003221
3222/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003223/* USB charging control commands */
3224
3225/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003226#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003227
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003228enum usb_charge_mode {
3229 /* Disable USB port. */
3230 USB_CHARGE_MODE_DISABLED,
3231 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3232 USB_CHARGE_MODE_SDP2,
3233 /* Set USB port to Charging Downstream Port, BC 1.2. */
3234 USB_CHARGE_MODE_CDP,
3235 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3236 USB_CHARGE_MODE_DCP_SHORT,
3237 /* Enable USB port (for dumb ports). */
3238 USB_CHARGE_MODE_ENABLED,
3239 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3240 USB_CHARGE_MODE_DEFAULT,
3241
3242 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003243};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003244
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003245enum usb_suspend_charge {
3246 /* Enable charging in suspend */
3247 USB_ALLOW_SUSPEND_CHARGE,
3248 /* Disable charging in suspend */
3249 USB_DISALLOW_SUSPEND_CHARGE
3250};
3251
3252struct ec_params_usb_charge_set_mode {
3253 uint8_t usb_port_id;
3254 uint8_t mode:7; /* enum usb_charge_mode */
3255 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
3256} __ec_align1;
3257
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003258/*****************************************************************************/
3259/* Persistent storage for host */
3260
3261/* Maximum bytes that can be read/written in a single command */
3262#define EC_PSTORE_SIZE_MAX 64
3263
3264/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003265#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003266
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003267struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003268 /* Persistent storage size, in bytes */
3269 uint32_t pstore_size;
3270 /* Access size; read/write offset and size must be a multiple of this */
3271 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003272} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003273
3274/*
3275 * Read persistent storage
3276 *
3277 * Response is params.size bytes of data.
3278 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003279#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003280
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003281struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003282 uint32_t offset; /* Byte offset to read */
3283 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003284} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003285
3286/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003287#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003288
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003289struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003290 uint32_t offset; /* Byte offset to write */
3291 uint32_t size; /* Size to write in bytes */
3292 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003293} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003294
3295/*****************************************************************************/
3296/* Real-time clock */
3297
3298/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003299struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003300 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003301} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003302
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003303struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003304 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003305} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003306
3307/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003308#define EC_CMD_RTC_GET_VALUE 0x0044
3309#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003310
3311/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003312#define EC_CMD_RTC_SET_VALUE 0x0046
3313#define EC_CMD_RTC_SET_ALARM 0x0047
3314
3315/* Pass as time param to SET_ALARM to clear the current alarm */
3316#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003317
3318/*****************************************************************************/
3319/* Port80 log access */
3320
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003321/* Maximum entries that can be read/written in a single command */
3322#define EC_PORT80_SIZE_MAX 32
3323
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003324/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003325#define EC_CMD_PORT80_LAST_BOOT 0x0048
3326#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003327
3328enum ec_port80_subcmd {
3329 EC_PORT80_GET_INFO = 0,
3330 EC_PORT80_READ_BUFFER,
3331};
3332
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003333struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003334 uint16_t subcmd;
3335 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003336 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003337 uint32_t offset;
3338 uint32_t num_entries;
3339 } read_buffer;
3340 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003341} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003342
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003343struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003344 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003345 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003346 uint32_t writes;
3347 uint32_t history_size;
3348 uint32_t last_boot;
3349 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003350 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003351 uint16_t codes[EC_PORT80_SIZE_MAX];
3352 } data;
3353 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003354} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003355
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003356struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003357 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003358} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003359
3360/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003361/* Temporary secure storage for host verified boot use */
3362
3363/* Number of bytes in a vstore slot */
3364#define EC_VSTORE_SLOT_SIZE 64
3365
3366/* Maximum number of vstore slots */
3367#define EC_VSTORE_SLOT_MAX 32
3368
3369/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003370#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003371struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003372 /* Indicates which slots are locked */
3373 uint32_t slot_locked;
3374 /* Total number of slots available */
3375 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003376} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003377
3378/*
3379 * Read temporary secure storage
3380 *
3381 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3382 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003383#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003384
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003385struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003386 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003387} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003388
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003389struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003390 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003391} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003392
3393/*
3394 * Write temporary secure storage and lock it.
3395 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003396#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003397
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003398struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003399 uint8_t slot; /* Slot to write to */
3400 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003401} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003402
3403/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003404/* Thermal engine commands. Note that there are two implementations. We'll
3405 * reuse the command number, but the data and behavior is incompatible.
3406 * Version 0 is what originally shipped on Link.
3407 * Version 1 separates the CPU thermal limits from the fan control.
3408 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003409
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003410#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3411#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003412
Duncan Laurie93e24442014-01-06 12:30:52 -08003413/* The version 0 structs are opaque. You have to know what they are for
3414 * the get/set commands to make any sense.
3415 */
3416
3417/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003418struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003419 uint8_t sensor_type;
3420 uint8_t threshold_id;
3421 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003422} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003423
Duncan Laurie93e24442014-01-06 12:30:52 -08003424/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003425struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003426 uint8_t sensor_type;
3427 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003428} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003429
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003430struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003431 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003432} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003433
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003434
Duncan Laurie93e24442014-01-06 12:30:52 -08003435/* The version 1 structs are visible. */
3436enum ec_temp_thresholds {
3437 EC_TEMP_THRESH_WARN = 0,
3438 EC_TEMP_THRESH_HIGH,
3439 EC_TEMP_THRESH_HALT,
3440
3441 EC_TEMP_THRESH_COUNT
3442};
3443
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003444/*
3445 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003446 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003447 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003448 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3449 * hysteresis.
3450 * For example,
3451 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3452 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3453 * EC will throttle ap when temperature >= 301 K, and release throttling when
3454 * temperature <= 299 K.
3455 *
3456 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3457 * For example,
3458 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3459 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3460 * EC will throttle ap when temperature >= 301 K, and release throttling when
3461 * temperature <= 294 K.
3462 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003463 * Note that this structure is a sub-structure of
3464 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003465 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003466struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003467 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003468 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003469 uint32_t temp_fan_off; /* no active cooling needed */
3470 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003471} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003472
3473/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003474struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003475 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003476} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003477/* This returns a struct ec_thermal_config */
3478
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003479/*
3480 * Version 1 - set config for one sensor.
3481 * Use read-modify-write for best results!
3482 */
3483struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003484 uint32_t sensor_num;
3485 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003486} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003487/* This returns no data */
3488
3489/****************************************************************************/
3490
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003491/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003492#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003493
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003494/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003495struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003496 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003497} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003498
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003499/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003500#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3501#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003502
3503/*
3504 * The original TMP006 calibration only needed four params, but now we need
3505 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3506 * the params opaque. The v1 "get" response will include the algorithm number
3507 * and how many params it requires. That way we can change the EC code without
3508 * needing to update this file. We can also use a different algorithm on each
3509 * sensor.
3510 */
3511
3512/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003513struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003514 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003515} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003516
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003517/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003518struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003519 float s0;
3520 float b0;
3521 float b1;
3522 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003523} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003524
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003525struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003526 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003527 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003528 float s0;
3529 float b0;
3530 float b1;
3531 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003532} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003533
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003534/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003535struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003536 uint8_t algorithm;
3537 uint8_t num_params;
3538 uint8_t reserved[2];
3539 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003540} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003541
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003542struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003543 uint8_t index;
3544 uint8_t algorithm;
3545 uint8_t num_params;
3546 uint8_t reserved;
3547 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003548} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003549
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003550
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003551/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003552#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003553
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003554struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003555 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003556} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003557
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003558struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003559 int32_t t; /* In 1/100 K */
3560 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003561} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003562
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003563/*****************************************************************************/
3564/* MKBP - Matrix KeyBoard Protocol */
3565
3566/*
3567 * Read key state
3568 *
3569 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3570 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003571 *
3572 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3573 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3574 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003575 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003576#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003577
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003578/*
3579 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3580 */
3581#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003582
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003583struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003584 uint32_t rows;
3585 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003586 /* Formerly "switches", which was 0. */
3587 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003588} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003589
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003590struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003591 uint8_t info_type;
3592 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003593} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003594
3595enum ec_mkbp_info_type {
3596 /*
3597 * Info about the keyboard matrix: number of rows and columns.
3598 *
3599 * Returns struct ec_response_mkbp_info.
3600 */
3601 EC_MKBP_INFO_KBD = 0,
3602
3603 /*
3604 * For buttons and switches, info about which specifically are
3605 * supported. event_type must be set to one of the values in enum
3606 * ec_mkbp_event.
3607 *
3608 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3609 * bitmask indicating which buttons or switches are present. See the
3610 * bit inidices below.
3611 */
3612 EC_MKBP_INFO_SUPPORTED = 1,
3613
3614 /*
3615 * Instantaneous state of buttons and switches.
3616 *
3617 * event_type must be set to one of the values in enum ec_mkbp_event.
3618 *
3619 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3620 * indicating the current state of the keyboard matrix.
3621 *
3622 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3623 * event state.
3624 *
3625 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3626 * state of supported buttons.
3627 *
3628 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3629 * state of supported switches.
3630 */
3631 EC_MKBP_INFO_CURRENT = 2,
3632};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003633
3634/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003635#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003636
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003637struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003638 uint8_t col;
3639 uint8_t row;
3640 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003641} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003642
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003643#define EC_CMD_GET_KEYBOARD_ID 0x0063
3644
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003645struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003646 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003647} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003648
3649enum keyboard_id {
3650 KEYBOARD_ID_UNSUPPORTED = 0,
3651 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3652};
3653
Duncan Laurie433432b2013-06-03 10:38:22 -07003654/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003655#define EC_CMD_MKBP_SET_CONFIG 0x0064
3656#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003657
3658/* flags */
3659enum mkbp_config_flags {
3660 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3661};
3662
3663enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003664 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3665 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3666 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3667 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3668 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3669 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3670 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003671};
3672
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003673/*
3674 * Configuration for our key scanning algorithm.
3675 *
3676 * Note that this is used as a sub-structure of
3677 * ec_{params/response}_mkbp_get_config.
3678 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003679struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003680 uint32_t valid_mask; /* valid fields */
3681 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3682 uint8_t valid_flags; /* which flags are valid */
3683 uint16_t scan_period_us; /* period between start of scans */
3684 /* revert to interrupt mode after no activity for this long */
3685 uint32_t poll_timeout_us;
3686 /*
3687 * minimum post-scan relax time. Once we finish a scan we check
3688 * the time until we are due to start the next one. If this time is
3689 * shorter this field, we use this instead.
3690 */
3691 uint16_t min_post_scan_delay_us;
3692 /* delay between setting up output and waiting for it to settle */
3693 uint16_t output_settle_us;
3694 uint16_t debounce_down_us; /* time for debounce on key down */
3695 uint16_t debounce_up_us; /* time for debounce on key up */
3696 /* maximum depth to allow for fifo (0 = no keyscan output) */
3697 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003698} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003699
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003700struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003701 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003702} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003703
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003704struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003705 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003706} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003707
3708/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003709#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003710
3711enum ec_keyscan_seq_cmd {
3712 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3713 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3714 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3715 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3716 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3717};
3718
3719enum ec_collect_flags {
3720 /*
3721 * Indicates this scan was processed by the EC. Due to timing, some
3722 * scans may be skipped.
3723 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003724 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003725};
3726
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003727struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003728 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003729} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003731struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003732 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3733 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003734 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003735 uint8_t active; /* still active */
3736 uint8_t num_items; /* number of items */
3737 /* Current item being presented */
3738 uint8_t cur_item;
3739 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003740 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003741 /*
3742 * Absolute time for this scan, measured from the
3743 * start of the sequence.
3744 */
3745 uint32_t time_us;
3746 uint8_t scan[0]; /* keyscan data */
3747 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003748 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003749 uint8_t start_item; /* First item to return */
3750 uint8_t num_items; /* Number of items to return */
3751 } collect;
3752 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003753} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003754
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003755struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003756 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003757 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003758 uint8_t num_items; /* Number of items */
3759 /* Data for each item */
3760 struct ec_collect_item item[0];
3761 } collect;
3762 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003763} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003764
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003765/*
3766 * Get the next pending MKBP event.
3767 *
3768 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3769 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003770#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003771
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003772#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3773
3774/*
3775 * We use the most significant bit of the event type to indicate to the host
3776 * that the EC has more MKBP events available to provide.
3777 */
3778#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3779
3780/* The mask to apply to get the raw event type */
3781#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3782
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003783enum ec_mkbp_event {
3784 /* Keyboard matrix changed. The event data is the new matrix state. */
3785 EC_MKBP_EVENT_KEY_MATRIX = 0,
3786
3787 /* New host event. The event data is 4 bytes of host event flags. */
3788 EC_MKBP_EVENT_HOST_EVENT = 1,
3789
Duncan Laurieeb316852015-12-01 18:51:18 -08003790 /* New Sensor FIFO data. The event data is fifo_info structure. */
3791 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3792
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003793 /* The state of the non-matrixed buttons have changed. */
3794 EC_MKBP_EVENT_BUTTON = 3,
3795
3796 /* The state of the switches have changed. */
3797 EC_MKBP_EVENT_SWITCH = 4,
3798
3799 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3800 EC_MKBP_EVENT_FINGERPRINT = 5,
3801
3802 /*
3803 * Sysrq event: send emulated sysrq. The event data is sysrq,
3804 * corresponding to the key to be pressed.
3805 */
3806 EC_MKBP_EVENT_SYSRQ = 6,
3807
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003808 /*
3809 * New 64-bit host event.
3810 * The event data is 8 bytes of host event flags.
3811 */
3812 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3813
3814 /* Notify the AP that something happened on CEC */
3815 EC_MKBP_EVENT_CEC_EVENT = 8,
3816
3817 /* Send an incoming CEC message to the AP */
3818 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3819
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003820 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3821 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3822
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003823 /* New online calibration values are available. */
3824 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3825
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003826 /* Peripheral device charger event */
3827 EC_MKBP_EVENT_PCHG = 12,
3828
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003829 /* Number of MKBP events */
3830 EC_MKBP_EVENT_COUNT,
3831};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003832BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003833
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003834union __ec_align_offset1 ec_response_get_next_data {
3835 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003836
3837 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003838 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003839 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003840
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003841 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003842 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003843 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003844 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003845 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003846
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003847 uint32_t buttons;
3848
3849 uint32_t switches;
3850
3851 uint32_t fp_events;
3852
3853 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003854
3855 /* CEC events from enum mkbp_cec_event */
3856 uint32_t cec_events;
3857};
3858
3859union __ec_align_offset1 ec_response_get_next_data_v1 {
3860 uint8_t key_matrix[16];
3861
3862 /* Unaligned */
3863 uint32_t host_event;
3864 uint64_t host_event64;
3865
3866 struct __ec_todo_unpacked {
3867 /* For aligning the fifo_info */
3868 uint8_t reserved[3];
3869 struct ec_response_motion_sense_fifo_info info;
3870 } sensor_fifo;
3871
3872 uint32_t buttons;
3873
3874 uint32_t switches;
3875
3876 uint32_t fp_events;
3877
3878 uint32_t sysrq;
3879
3880 /* CEC events from enum mkbp_cec_event */
3881 uint32_t cec_events;
3882
3883 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003884};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003885BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003886
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003887struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003888 uint8_t event_type;
3889 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003890 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003891} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003892
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003893struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003894 uint8_t event_type;
3895 /* Followed by event data if any */
3896 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003897} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003898
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003899/* Bit indices for buttons and switches.*/
3900/* Buttons */
3901#define EC_MKBP_POWER_BUTTON 0
3902#define EC_MKBP_VOL_UP 1
3903#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003904#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003905
3906/* Switches */
3907#define EC_MKBP_LID_OPEN 0
3908#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003909#define EC_MKBP_BASE_ATTACHED 2
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003910#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003911
Gwendal Grignou880b4582016-06-20 08:49:25 -07003912/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003913#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003914
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003915struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003916 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003917} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003918
3919/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3920#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003921#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3922#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3923#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3924 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3925#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3926#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3927#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3928 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003929#define EC_MKBP_FP_ENROLL BIT(27)
3930#define EC_MKBP_FP_MATCH BIT(28)
3931#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3932#define EC_MKBP_FP_FINGER_UP BIT(30)
3933#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003934/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3935#define EC_MKBP_FP_ERR_ENROLL_OK 0
3936#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3937#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3938#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3939#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3940/* Can be used to detect if image was usable for enrollment or not. */
3941#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3942/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3943#define EC_MKBP_FP_ERR_MATCH_NO 0
3944#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003945#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003946#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3947#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3948#define EC_MKBP_FP_ERR_MATCH_YES 1
3949#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3950#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3951
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003952
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003953#define EC_CMD_MKBP_WAKE_MASK 0x0069
3954enum ec_mkbp_event_mask_action {
3955 /* Retrieve the value of a wake mask. */
3956 GET_WAKE_MASK = 0,
3957
3958 /* Set the value of a wake mask. */
3959 SET_WAKE_MASK,
3960};
3961
3962enum ec_mkbp_mask_type {
3963 /*
3964 * These are host events sent via MKBP.
3965 *
3966 * Some examples are:
3967 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3968 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3969 *
3970 * The only things that should be in this mask are:
3971 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3972 */
3973 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3974
3975 /*
3976 * These are MKBP events. Some examples are:
3977 *
3978 * EC_MKBP_EVENT_KEY_MATRIX
3979 * EC_MKBP_EVENT_SWITCH
3980 *
3981 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3982 */
3983 EC_MKBP_EVENT_WAKE_MASK,
3984};
3985
3986struct ec_params_mkbp_event_wake_mask {
3987 /* One of enum ec_mkbp_event_mask_action */
3988 uint8_t action;
3989
3990 /*
3991 * Which MKBP mask are you interested in acting upon? This is one of
3992 * ec_mkbp_mask_type.
3993 */
3994 uint8_t mask_type;
3995
3996 /* If setting a new wake mask, this contains the mask to set. */
3997 uint32_t new_wake_mask;
3998};
3999
4000struct ec_response_mkbp_event_wake_mask {
4001 uint32_t wake_mask;
4002};
4003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004004/*****************************************************************************/
4005/* Temperature sensor commands */
4006
4007/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004008#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004009
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004010struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004011 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004012} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004013
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004014struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004015 char sensor_name[32];
4016 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004017} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004018
4019/*****************************************************************************/
4020
4021/*
4022 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4023 * commands accidentally sent to the wrong interface. See the ACPI section
4024 * below.
4025 */
4026
4027/*****************************************************************************/
4028/* Host event commands */
4029
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004030
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004031/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004032/*
4033 * Host event mask params and response structures, shared by all of the host
4034 * event commands below.
4035 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004036struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004037 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004038} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004039
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004040struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004041 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004042} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004043
4044/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004045#define EC_CMD_HOST_EVENT_GET_B 0x0087
4046#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4047#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
4048#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004049
4050/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004051#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4052#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4053#define EC_CMD_HOST_EVENT_CLEAR 0x008C
4054#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
4055#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004056
Jenny TC1dfc2c32017-12-14 14:24:39 +05304057/*
4058 * Unified host event programming interface - Should be used by newer versions
4059 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004060 *
4061 * EC returns:
4062 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4063 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304064 */
4065
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004066struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304067
4068 /* Action requested by host - one of enum ec_host_event_action. */
4069 uint8_t action;
4070
4071 /*
4072 * Mask type that the host requested the action on - one of
4073 * enum ec_host_event_mask_type.
4074 */
4075 uint8_t mask_type;
4076
4077 /* Set to 0, ignore on read */
4078 uint16_t reserved;
4079
4080 /* Value to be used in case of set operations. */
4081 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004082} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304083
4084/*
4085 * Response structure returned by EC_CMD_HOST_EVENT.
4086 * Update the value on a GET request. Set to 0 on GET/CLEAR
4087 */
4088
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004089struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304090
4091 /* Mask value in case of get operation */
4092 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004093} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304094
4095enum ec_host_event_action {
4096 /*
4097 * params.value is ignored. Value of mask_type populated
4098 * in response.value
4099 */
4100 EC_HOST_EVENT_GET,
4101
4102 /* Bits in params.value are set */
4103 EC_HOST_EVENT_SET,
4104
4105 /* Bits in params.value are cleared */
4106 EC_HOST_EVENT_CLEAR,
4107};
4108
4109enum ec_host_event_mask_type {
4110
4111 /* Main host event copy */
4112 EC_HOST_EVENT_MAIN,
4113
4114 /* Copy B of host events */
4115 EC_HOST_EVENT_B,
4116
4117 /* SCI Mask */
4118 EC_HOST_EVENT_SCI_MASK,
4119
4120 /* SMI Mask */
4121 EC_HOST_EVENT_SMI_MASK,
4122
4123 /* Mask of events that should be always reported in hostevents */
4124 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4125
4126 /* Active wake mask */
4127 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4128
4129 /* Lazy wake mask for S0ix */
4130 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4131
4132 /* Lazy wake mask for S3 */
4133 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4134
4135 /* Lazy wake mask for S5 */
4136 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4137};
4138
4139#define EC_CMD_HOST_EVENT 0x00A4
4140
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004141/*****************************************************************************/
4142/* Switch commands */
4143
4144/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004145#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004146
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004147struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004148 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004149} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004150
4151/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004152#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004153#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004154
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004155/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004156struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004157 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004158} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004159
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004160/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004161struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004162 /* Flags to enable now */
4163 uint8_t now_flags;
4164
4165 /* Which flags to copy from now_flags */
4166 uint8_t now_mask;
4167
4168 /*
4169 * Flags to leave enabled in S3, if they're on at the S0->S3
4170 * transition. (Other flags will be disabled by the S0->S3
4171 * transition.)
4172 */
4173 uint8_t suspend_flags;
4174
4175 /* Which flags to copy from suspend_flags */
4176 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004177} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004178
4179/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004180struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004181 /* Flags to enable now */
4182 uint8_t now_flags;
4183
4184 /* Flags to leave enabled in S3 */
4185 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004186} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004187
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004188/*****************************************************************************/
4189/* GPIO commands. Only available on EC if write protect has been disabled. */
4190
4191/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004192#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004193
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004194struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004195 char name[32];
4196 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004197} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004198
4199/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004200#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004201
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004202/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004203struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004204 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004205} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004206
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004207struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004208 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004209} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004210
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004211/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004212struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004213 uint8_t subcmd;
4214 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004215 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004216 char name[32];
4217 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004218 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004219 uint8_t index;
4220 } get_info;
4221 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004222} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004223
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004224struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004225 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004226 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004227 uint8_t val;
4228 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004229 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004230 uint8_t val;
4231 char name[32];
4232 uint32_t flags;
4233 } get_info;
4234 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004235} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004236
4237enum gpio_get_subcmd {
4238 EC_GPIO_GET_BY_NAME = 0,
4239 EC_GPIO_GET_COUNT = 1,
4240 EC_GPIO_GET_INFO = 2,
4241};
4242
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004243/*****************************************************************************/
4244/* I2C commands. Only available when flash write protect is unlocked. */
4245
Duncan Laurie93e24442014-01-06 12:30:52 -08004246/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004247 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4248 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4249 *
4250 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004251 */
4252
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004253/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004254#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004255
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004256struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004257 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004258 uint8_t read_size; /* Either 8 or 16. */
4259 uint8_t port;
4260 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004261} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004262
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004263struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004264 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004265} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004266
4267/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004268#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004269
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004270struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004271 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004272 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004273 uint8_t write_size; /* Either 8 or 16. */
4274 uint8_t port;
4275 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004276} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004277
4278/*****************************************************************************/
4279/* Charge state commands. Only available when flash write protect unlocked. */
4280
Duncan Laurie93e24442014-01-06 12:30:52 -08004281/* Force charge state machine to stop charging the battery or force it to
4282 * discharge the battery.
4283 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004284#define EC_CMD_CHARGE_CONTROL 0x0096
Scott Chao18141d8c2021-07-30 10:40:57 +08004285#define EC_VER_CHARGE_CONTROL 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004286
Duncan Laurie93e24442014-01-06 12:30:52 -08004287enum ec_charge_control_mode {
4288 CHARGE_CONTROL_NORMAL = 0,
4289 CHARGE_CONTROL_IDLE,
4290 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004291 /* Add no more entry below. */
4292 CHARGE_CONTROL_COUNT,
4293};
4294
4295#define EC_CHARGE_MODE_TEXT { \
4296 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4297 [CHARGE_CONTROL_IDLE] = "IDLE", \
4298 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
4299 }
4300
4301enum ec_charge_control_cmd {
4302 EC_CHARGE_CONTROL_CMD_SET = 0,
4303 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004304};
4305
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004306struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004307 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004308
4309 /* Below are the fields added in V2. */
4310 uint8_t cmd; /* enum ec_charge_control_cmd. */
4311 uint8_t reserved;
4312 /*
4313 * Lower and upper thresholds for battery sustainer. This struct isn't
4314 * named to avoid tainting foreign projects' name spaces.
4315 *
4316 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4317 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4318 * lower=-1, upper=-1.
4319 */
4320 struct {
4321 int8_t lower; /* Display SoC in percentage. */
4322 int8_t upper; /* Display SoC in percentage. */
4323 } sustain_soc;
4324} __ec_align4;
4325
4326/* Added in v2 */
4327struct ec_response_charge_control {
4328 uint32_t mode; /* enum charge_control_mode */
4329 struct { /* Battery sustainer thresholds */
4330 int8_t lower;
4331 int8_t upper;
4332 } sustain_soc;
4333 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004334} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004335
4336/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004337
4338/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004339#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004340
4341/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004342 * Read data from the saved snapshot. If the subcmd parameter is
4343 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4344 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4345 * end of the previous snapshot.
4346 *
4347 * The params are only looked at in version >= 1 of this command. Prior
4348 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004349 *
4350 * Response is null-terminated string. Empty string, if there is no more
4351 * remaining output.
4352 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004353#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004354
Duncan Laurieeb316852015-12-01 18:51:18 -08004355enum ec_console_read_subcmd {
4356 CONSOLE_READ_NEXT = 0,
4357 CONSOLE_READ_RECENT
4358};
4359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004360struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004361 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004362} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004363
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004364/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004365
4366/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004367 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004368 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004369 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4370 * EC_RES_SUCCESS if the command was successful.
4371 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004372 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004373#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004374
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004375#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004376
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004377struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004378 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004379} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004380
Duncan Laurie433432b2013-06-03 10:38:22 -07004381/*****************************************************************************/
4382/* USB port mux control. */
4383
4384/*
4385 * Switch USB mux or return to automatic switching.
4386 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004387#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004388
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004389struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004390 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004391} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004392
4393/*****************************************************************************/
4394/* LDOs / FETs control. */
4395
4396enum ec_ldo_state {
4397 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4398 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4399};
4400
4401/*
4402 * Switch on/off a LDO.
4403 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004404#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004405
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004406struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004407 uint8_t index;
4408 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004409} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004410
4411/*
4412 * Get LDO state.
4413 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004414#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004415
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004416struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004417 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004418} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004419
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004420struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004421 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004422} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004423
4424/*****************************************************************************/
4425/* Power info. */
4426
4427/*
4428 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004429 *
4430 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004431 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004432#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004433
Jett Rinkba2edaf2020-01-14 11:49:06 -07004434/*
4435 * v1 of EC_CMD_POWER_INFO
4436 */
4437enum system_power_source {
4438 /*
4439 * Haven't established which power source is used yet,
4440 * or no presence signals are available
4441 */
4442 POWER_SOURCE_UNKNOWN = 0,
4443 /* System is running on battery alone */
4444 POWER_SOURCE_BATTERY = 1,
4445 /* System is running on A/C alone */
4446 POWER_SOURCE_AC = 2,
4447 /* System is running on A/C and battery */
4448 POWER_SOURCE_AC_BATTERY = 3,
4449};
4450
4451struct ec_response_power_info_v1 {
4452 /* enum system_power_source */
4453 uint8_t system_power_source;
4454 /* Battery state-of-charge, 0-100, 0 if not present */
4455 uint8_t battery_soc;
4456 /* AC Adapter 100% rating, Watts */
4457 uint8_t ac_adapter_100pct;
4458 /* AC Adapter 10ms rating, Watts */
4459 uint8_t ac_adapter_10ms;
4460 /* Battery 1C rating, derated */
4461 uint8_t battery_1cd;
4462 /* Rest of Platform average, Watts */
4463 uint8_t rop_avg;
4464 /* Rest of Platform peak, Watts */
4465 uint8_t rop_peak;
4466 /* Nominal charger efficiency, % */
4467 uint8_t nominal_charger_eff;
4468 /* Rest of Platform VR Average Efficiency, % */
4469 uint8_t rop_avg_eff;
4470 /* Rest of Platform VR Peak Efficiency, % */
4471 uint8_t rop_peak_eff;
4472 /* SoC VR Efficiency at Average level, % */
4473 uint8_t soc_avg_eff;
4474 /* SoC VR Efficiency at Peak level, % */
4475 uint8_t soc_peak_eff;
4476 /* Intel-specific items */
4477 struct {
4478 /* Battery's level of DBPT support: 0, 2 */
4479 uint8_t batt_dbpt_support_level;
4480 /*
4481 * Maximum peak power from battery (10ms), Watts
4482 * If DBPT is not supported, this is 0
4483 */
4484 uint8_t batt_dbpt_max_peak_power;
4485 /*
4486 * Sustained peak power from battery, Watts
4487 * If DBPT is not supported, this is 0
4488 */
4489 uint8_t batt_dbpt_sus_peak_power;
4490 } intel;
4491} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004492
4493/*****************************************************************************/
4494/* I2C passthru command */
4495
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004496#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004497
Duncan Laurie433432b2013-06-03 10:38:22 -07004498/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004499#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004500
4501/* Mask for address */
4502#define EC_I2C_ADDR_MASK 0x3ff
4503
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004504#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4505#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004506
4507/* Any error */
4508#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4509
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004510struct ec_params_i2c_passthru_msg {
Rob Barnes8bc5fa92021-06-28 09:32:28 -06004511 uint16_t addr_flags; /* I2C peripheral address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004512 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004513} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004514
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004515struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004516 uint8_t port; /* I2C port number */
4517 uint8_t num_msgs; /* Number of messages */
4518 struct ec_params_i2c_passthru_msg msg[];
4519 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004520} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004521
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004522struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004523 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4524 uint8_t num_msgs; /* Number of messages processed */
4525 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004526} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004527
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004528/*****************************************************************************/
4529/* Power button hang detect */
4530
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004531#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004532
4533/* Reasons to start hang detection timer */
4534/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004535#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004536
4537/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004538#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004539
4540 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004541#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004542
4543/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004544#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004545
4546/* Reasons to cancel hang detection */
4547
4548/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004549#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004550
4551/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004552#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004553
4554/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004555#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004556
4557/*
4558 * If this flag is set, all the other fields are ignored, and the hang detect
4559 * timer is started. This provides the AP a way to start the hang timer
4560 * without reconfiguring any of the other hang detect settings. Note that
4561 * you must previously have configured the timeouts.
4562 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004563#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004564
4565/*
4566 * If this flag is set, all the other fields are ignored (including
4567 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4568 * without reconfiguring any of the other hang detect settings.
4569 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004570#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004571
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004572struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004573 /* Flags; see EC_HANG_* */
4574 uint32_t flags;
4575
4576 /* Timeout in msec before generating host event, if enabled */
4577 uint16_t host_event_timeout_msec;
4578
4579 /* Timeout in msec before generating warm reboot, if enabled */
4580 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004581} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004582
4583/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004584/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004585
4586/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004587 * This is the single catch-all host command to exchange data regarding the
4588 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004589 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004590#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004591
4592/* Subcommands for this host command */
4593enum charge_state_command {
4594 CHARGE_STATE_CMD_GET_STATE,
4595 CHARGE_STATE_CMD_GET_PARAM,
4596 CHARGE_STATE_CMD_SET_PARAM,
4597 CHARGE_STATE_NUM_CMDS
4598};
4599
4600/*
4601 * Known param numbers are defined here. Ranges are reserved for board-specific
4602 * params, which are handled by the particular implementations.
4603 */
4604enum charge_state_params {
4605 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4606 CS_PARAM_CHG_CURRENT, /* charger current limit */
4607 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4608 CS_PARAM_CHG_STATUS, /* charger-specific status */
4609 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004610 CS_PARAM_LIMIT_POWER, /*
4611 * Check if power is limited due to
4612 * low battery and / or a weak external
4613 * charger. READ ONLY.
4614 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004615 /* How many so far? */
4616 CS_NUM_BASE_PARAMS,
4617
4618 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4619 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4620 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4621
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004622 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4623 CS_PARAM_DEBUG_MIN = 0x20000,
4624 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4625 CS_PARAM_DEBUG_MANUAL_MODE,
4626 CS_PARAM_DEBUG_SEEMS_DEAD,
4627 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4628 CS_PARAM_DEBUG_BATT_REMOVED,
4629 CS_PARAM_DEBUG_MANUAL_CURRENT,
4630 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4631 CS_PARAM_DEBUG_MAX = 0x2ffff,
4632
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004633 /* Other custom param ranges go here... */
4634};
4635
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004636struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004637 uint8_t cmd; /* enum charge_state_command */
4638 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004639 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004640
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004641 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004642 uint32_t param; /* enum charge_state_param */
4643 } get_param;
4644
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004645 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004646 uint32_t param; /* param to set */
4647 uint32_t value; /* value to set */
4648 } set_param;
4649 };
Yidi Lin42f79592020-09-21 18:04:10 +08004650 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004651} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004652
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004653struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004654 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004655 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004656 int ac;
4657 int chg_voltage;
4658 int chg_current;
4659 int chg_input_current;
4660 int batt_state_of_charge;
4661 } get_state;
4662
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004663 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004664 uint32_t value;
4665 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004666
4667 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004668 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004669} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004670
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004671
Duncan Laurie433432b2013-06-03 10:38:22 -07004672/*
4673 * Set maximum battery charging current.
4674 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004675#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004676
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004677struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004678 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004679} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004680
4681/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004682 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004683 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004684#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004685
Duncan Laurieeb316852015-12-01 18:51:18 -08004686/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004687struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004688 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4689 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004690} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004691
Duncan Laurieeb316852015-12-01 18:51:18 -08004692#define EC_POWER_LIMIT_NONE 0xffff
4693
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004694/*
4695 * Set maximum voltage & current of a dedicated charge port
4696 */
4697#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4698
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004699struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004700 uint16_t current_lim; /* in mA */
4701 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004702} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004703
Duncan Laurieeb316852015-12-01 18:51:18 -08004704/*****************************************************************************/
4705/* Hibernate/Deep Sleep Commands */
4706
4707/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004708#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004709
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004710struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004711 /*
4712 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4713 * current settings without changing them.
4714 */
4715 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004716} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004717
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004718struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004719 /*
4720 * The current time in seconds in which the system has been in the G3
4721 * state. This value is reset if the EC transitions out of G3.
4722 */
4723 uint32_t time_g3;
4724
4725 /*
4726 * The current time remaining in seconds until the EC should hibernate.
4727 * This value is also reset if the EC transitions out of G3.
4728 */
4729 uint32_t time_remaining;
4730
4731 /*
4732 * The current time in seconds that the EC should wait in G3 before
4733 * hibernating.
4734 */
4735 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004736} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004737
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004738/* Inform the EC when entering a sleep state */
4739#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4740
4741enum host_sleep_event {
4742 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4743 HOST_SLEEP_EVENT_S3_RESUME = 2,
4744 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004745 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4746 /* S3 suspend with additional enabled wake sources */
4747 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004748};
4749
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004750struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004751 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004752} __ec_align1;
4753
4754/*
4755 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4756 * transition failures
4757 */
4758#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4759
4760/* Disable timeout detection for this sleep transition */
4761#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4762
4763struct ec_params_host_sleep_event_v1 {
4764 /* The type of sleep being entered or exited. */
4765 uint8_t sleep_event;
4766
4767 /* Padding */
4768 uint8_t reserved;
4769 union {
4770 /* Parameters that apply for suspend messages. */
4771 struct {
4772 /*
4773 * The timeout in milliseconds between when this message
4774 * is received and when the EC will declare sleep
4775 * transition failure if the sleep signal is not
4776 * asserted.
4777 */
4778 uint16_t sleep_timeout_ms;
4779 } suspend_params;
4780
4781 /* No parameters for non-suspend messages. */
4782 };
4783} __ec_align2;
4784
4785/* A timeout occurred when this bit is set */
4786#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4787
4788/*
4789 * The mask defining which bits correspond to the number of sleep transitions,
4790 * as well as the maximum number of suspend line transitions that will be
4791 * reported back to the host.
4792 */
4793#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4794
4795struct ec_response_host_sleep_event_v1 {
4796 union {
4797 /* Response fields that apply for resume messages. */
4798 struct {
4799 /*
4800 * The number of sleep power signal transitions that
4801 * occurred since the suspend message. The high bit
4802 * indicates a timeout occurred.
4803 */
4804 uint32_t sleep_transitions;
4805 } resume_response;
4806
4807 /* No response fields for non-resume messages. */
4808 };
4809} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004810
4811/*****************************************************************************/
4812/* Device events */
4813#define EC_CMD_DEVICE_EVENT 0x00AA
4814
4815enum ec_device_event {
4816 EC_DEVICE_EVENT_TRACKPAD,
4817 EC_DEVICE_EVENT_DSP,
4818 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004819 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004820};
4821
4822enum ec_device_event_param {
4823 /* Get and clear pending device events */
4824 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4825 /* Get device event mask */
4826 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4827 /* Set device event mask */
4828 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4829};
4830
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004831#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004832
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004833struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004834 uint32_t event_mask;
4835 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004836} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004837
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004838struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004839 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004840} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004841
Duncan Laurie433432b2013-06-03 10:38:22 -07004842/*****************************************************************************/
4843/* Smart battery pass-through */
4844
4845/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004846#define EC_CMD_SB_READ_WORD 0x00B0
4847#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004848
4849/* Get / Set string smart battery parameters
4850 * formatted as SMBUS "block".
4851 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004852#define EC_CMD_SB_READ_BLOCK 0x00B2
4853#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004854
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004855struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004856 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004857} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004859struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004860 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004861} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004862
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004863struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004864 uint8_t reg;
4865 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004866} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004867
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004868struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004869 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004870} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004871
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004872struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004873 uint8_t reg;
4874 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004875} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004876
4877/*****************************************************************************/
4878/* Battery vendor parameters
4879 *
4880 * Get or set vendor-specific parameters in the battery. Implementations may
4881 * differ between boards or batteries. On a set operation, the response
4882 * contains the actual value set, which may be rounded or clipped from the
4883 * requested value.
4884 */
4885
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004886#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004887
4888enum ec_battery_vendor_param_mode {
4889 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4890 BATTERY_VENDOR_PARAM_MODE_SET,
4891};
4892
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004893struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004894 uint32_t param;
4895 uint32_t value;
4896 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004897} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004898
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004899struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004900 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004901} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004902
4903/*****************************************************************************/
4904/*
4905 * Smart Battery Firmware Update Commands
4906 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004907#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004908
4909enum ec_sb_fw_update_subcmd {
4910 EC_SB_FW_UPDATE_PREPARE = 0x0,
4911 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4912 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4913 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4914 EC_SB_FW_UPDATE_END = 0x4,
4915 EC_SB_FW_UPDATE_STATUS = 0x5,
4916 EC_SB_FW_UPDATE_PROTECT = 0x6,
4917 EC_SB_FW_UPDATE_MAX = 0x7,
4918};
4919
4920#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4921#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4922#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4923
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004924struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004925 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4926 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004927} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004928
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004929struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004930 struct ec_sb_fw_update_header hdr;
4931 union {
4932 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4933 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4934 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4935 /* EC_SB_FW_UPDATE_END = 0x4 */
4936 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4937 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004938 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004939
4940 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004941 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004942 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4943 } write;
4944 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004945} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004946
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004947struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004948 union {
4949 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004950 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004951 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4952 } info;
4953
4954 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004955 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004956 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4957 } status;
4958 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004959} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004960
4961/*
4962 * Entering Verified Boot Mode Command
4963 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4964 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004965 *
4966 * EC no longer needs to know what mode vboot has entered,
4967 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004968 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004969#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004970
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004971struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004972 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004973} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004974
4975#define VBOOT_MODE_NORMAL 0
4976#define VBOOT_MODE_DEVELOPER 1
4977#define VBOOT_MODE_RECOVERY 2
4978
Duncan Laurie433432b2013-06-03 10:38:22 -07004979/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004980/*
4981 * I2C passthru protection command: Protects I2C tunnels against access on
4982 * certain addresses (board-specific).
4983 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004984#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004985
4986enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004987 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
4988 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
4989 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07004990};
4991
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004992struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004993 uint8_t subcmd;
4994 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004995} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004996
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004997struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004998 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004999} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005000
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005001
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005002/*****************************************************************************/
5003/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005004 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005005 *
5006 * These commands are for sending and receiving message via HDMI CEC
5007 */
5008
5009#define MAX_CEC_MSG_LEN 16
5010
5011/* CEC message from the AP to be written on the CEC bus */
5012#define EC_CMD_CEC_WRITE_MSG 0x00B8
5013
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005014/**
5015 * struct ec_params_cec_write - Message to write to the CEC bus
5016 * @msg: message content to write to the CEC bus
5017 */
5018struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005019 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005020} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005021
5022/* Set various CEC parameters */
5023#define EC_CMD_CEC_SET 0x00BA
5024
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005025/**
5026 * struct ec_params_cec_set - CEC parameters set
5027 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5028 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5029 * or 1 to enable CEC functionality, in case cmd is
5030 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5031 * address between 0 and 15 or 0xff to unregister
5032 */
5033struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005034 uint8_t cmd; /* enum cec_command */
5035 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005036} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005037
5038/* Read various CEC parameters */
5039#define EC_CMD_CEC_GET 0x00BB
5040
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005041/**
5042 * struct ec_params_cec_get - CEC parameters get
5043 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5044 */
5045struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005046 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005047} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005048
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005049/**
5050 * struct ec_response_cec_get - CEC parameters get response
5051 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5052 * disabled or 1 if CEC functionality is enabled,
5053 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5054 * configured logical address between 0 and 15 or 0xff if unregistered
5055 */
5056struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005057 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005058} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005059
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005060/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005061enum cec_command {
5062 /* CEC reading, writing and events enable */
5063 CEC_CMD_ENABLE,
5064 /* CEC logical address */
5065 CEC_CMD_LOGICAL_ADDRESS,
5066};
5067
5068/* Events from CEC to AP */
5069enum mkbp_cec_event {
5070 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005071 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005072 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005073 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005074};
5075
Gwendal Grignou880b4582016-06-20 08:49:25 -07005076/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005077
Jett Rinkba2edaf2020-01-14 11:49:06 -07005078/* Commands for audio codec. */
5079#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005080
Jett Rinkba2edaf2020-01-14 11:49:06 -07005081enum ec_codec_subcmd {
5082 EC_CODEC_GET_CAPABILITIES = 0x0,
5083 EC_CODEC_GET_SHM_ADDR = 0x1,
5084 EC_CODEC_SET_SHM_ADDR = 0x2,
5085 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005086};
5087
Jett Rinkba2edaf2020-01-14 11:49:06 -07005088enum ec_codec_cap {
5089 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5090 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5091 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005092};
5093
Jett Rinkba2edaf2020-01-14 11:49:06 -07005094enum ec_codec_shm_id {
5095 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5096 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5097 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005098};
5099
Jett Rinkba2edaf2020-01-14 11:49:06 -07005100enum ec_codec_shm_type {
5101 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5102 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005103};
5104
Jett Rinkba2edaf2020-01-14 11:49:06 -07005105struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5106 uint8_t shm_id;
5107 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005108};
5109
Jett Rinkba2edaf2020-01-14 11:49:06 -07005110struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5111 uint64_t phys_addr;
5112 uint32_t len;
5113 uint8_t shm_id;
5114 uint8_t reserved[3];
5115};
5116
5117struct __ec_align4 ec_param_ec_codec {
5118 uint8_t cmd; /* enum ec_codec_subcmd */
5119 uint8_t reserved[3];
5120
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005121 union {
Jett Rinkba2edaf2020-01-14 11:49:06 -07005122 struct ec_param_ec_codec_get_shm_addr
5123 get_shm_addr_param;
5124 struct ec_param_ec_codec_set_shm_addr
5125 set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005126 };
5127};
5128
Jett Rinkba2edaf2020-01-14 11:49:06 -07005129struct __ec_align4 ec_response_ec_codec_get_capabilities {
5130 uint32_t capabilities;
5131};
5132
5133struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5134 uint64_t phys_addr;
5135 uint32_t len;
5136 uint8_t type;
5137 uint8_t reserved[3];
5138};
5139
5140/*****************************************************************************/
5141
5142/* Commands for DMIC on audio codec. */
5143#define EC_CMD_EC_CODEC_DMIC 0x00BD
5144
5145enum ec_codec_dmic_subcmd {
5146 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5147 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5148 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5149 EC_CODEC_DMIC_SUBCMD_COUNT,
5150};
5151
5152enum ec_codec_dmic_channel {
5153 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5154 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5155 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5156 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5157 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5158 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5159 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5160 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5161 EC_CODEC_DMIC_CHANNEL_COUNT,
5162};
5163
5164struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5165 uint8_t channel; /* enum ec_codec_dmic_channel */
5166 uint8_t gain;
5167 uint8_t reserved[2];
5168};
5169
5170struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5171 uint8_t channel; /* enum ec_codec_dmic_channel */
5172 uint8_t reserved[3];
5173};
5174
5175struct __ec_align4 ec_param_ec_codec_dmic {
5176 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5177 uint8_t reserved[3];
5178
5179 union {
5180 struct ec_param_ec_codec_dmic_set_gain_idx
5181 set_gain_idx_param;
5182 struct ec_param_ec_codec_dmic_get_gain_idx
5183 get_gain_idx_param;
5184 };
5185};
5186
5187struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5188 uint8_t max_gain;
5189};
5190
5191struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5192 uint8_t gain;
5193};
5194
5195/*****************************************************************************/
5196
5197/* Commands for I2S RX on audio codec. */
5198
5199#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5200
5201enum ec_codec_i2s_rx_subcmd {
5202 EC_CODEC_I2S_RX_ENABLE = 0x0,
5203 EC_CODEC_I2S_RX_DISABLE = 0x1,
5204 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5205 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5206 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005207 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005208 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5209};
5210
5211enum ec_codec_i2s_rx_sample_depth {
5212 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5213 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5214 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5215};
5216
5217enum ec_codec_i2s_rx_daifmt {
5218 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5219 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5220 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5221 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5222};
5223
5224struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5225 uint8_t depth;
5226 uint8_t reserved[3];
5227};
5228
5229struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5230 uint8_t left;
5231 uint8_t right;
5232 uint8_t reserved[2];
5233};
5234
5235struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5236 uint8_t daifmt;
5237 uint8_t reserved[3];
5238};
5239
5240struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5241 uint32_t bclk;
5242};
5243
5244struct __ec_align4 ec_param_ec_codec_i2s_rx {
5245 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5246 uint8_t reserved[3];
5247
5248 union {
5249 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5250 set_sample_depth_param;
5251 struct ec_param_ec_codec_i2s_rx_set_daifmt
5252 set_daifmt_param;
5253 struct ec_param_ec_codec_i2s_rx_set_bclk
5254 set_bclk_param;
5255 };
5256};
5257
5258/*****************************************************************************/
5259/* Commands for WoV on audio codec. */
5260
5261#define EC_CMD_EC_CODEC_WOV 0x00BF
5262
5263enum ec_codec_wov_subcmd {
5264 EC_CODEC_WOV_SET_LANG = 0x0,
5265 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5266 EC_CODEC_WOV_GET_LANG = 0x2,
5267 EC_CODEC_WOV_ENABLE = 0x3,
5268 EC_CODEC_WOV_DISABLE = 0x4,
5269 EC_CODEC_WOV_READ_AUDIO = 0x5,
5270 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5271 EC_CODEC_WOV_SUBCMD_COUNT,
5272};
5273
5274/*
5275 * @hash is SHA256 of the whole language model.
5276 * @total_len indicates the length of whole language model.
5277 * @offset is the cursor from the beginning of the model.
5278 * @buf is the packet buffer.
5279 * @len denotes how many bytes in the buf.
5280 */
5281struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5282 uint8_t hash[32];
5283 uint32_t total_len;
5284 uint32_t offset;
5285 uint8_t buf[128];
5286 uint32_t len;
5287};
5288
5289struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5290 uint8_t hash[32];
5291 uint32_t total_len;
5292};
5293
5294struct __ec_align4 ec_param_ec_codec_wov {
5295 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5296 uint8_t reserved[3];
5297
5298 union {
5299 struct ec_param_ec_codec_wov_set_lang
5300 set_lang_param;
5301 struct ec_param_ec_codec_wov_set_lang_shm
5302 set_lang_shm_param;
5303 };
5304};
5305
5306struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5307 uint8_t hash[32];
5308};
5309
5310struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5311 uint8_t buf[128];
5312 uint32_t len;
5313};
5314
5315struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5316 uint32_t offset;
5317 uint32_t len;
5318};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005319
5320/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005321/* Commands for PoE PSE controller */
5322
5323#define EC_CMD_PSE 0x00C0
5324
5325enum ec_pse_subcmd {
5326 EC_PSE_STATUS = 0x0,
5327 EC_PSE_ENABLE = 0x1,
5328 EC_PSE_DISABLE = 0x2,
5329 EC_PSE_SUBCMD_COUNT,
5330};
5331
5332struct __ec_align1 ec_params_pse {
5333 uint8_t cmd; /* enum ec_pse_subcmd */
5334 uint8_t port; /* PSE port */
5335};
5336
5337enum ec_pse_status {
5338 EC_PSE_STATUS_DISABLED = 0x0,
5339 EC_PSE_STATUS_ENABLED = 0x1,
5340 EC_PSE_STATUS_POWERED = 0x2,
5341};
5342
5343struct __ec_align1 ec_response_pse_status {
5344 uint8_t status; /* enum ec_pse_status */
5345};
5346
5347/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005348/* System commands */
5349
5350/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005351 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5352 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005353 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005354#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005355
5356/* Command */
5357enum ec_reboot_cmd {
5358 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005359 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005360 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005361 /* (command 3 was jump to RW-B) */
5362 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005363 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08005364 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Yidi Lin42f79592020-09-21 18:04:10 +08005365 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_IDLE flag */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005366 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005367};
5368
5369/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005370#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5371#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5372#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005373
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005374struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005375 uint8_t cmd; /* enum ec_reboot_cmd */
5376 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005377} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005378
Duncan Laurie433432b2013-06-03 10:38:22 -07005379/*
5380 * Get information on last EC panic.
5381 *
5382 * Returns variable-length platform-dependent panic information. See panic.h
5383 * for details.
5384 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005385#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005386
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005387/*****************************************************************************/
5388/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005389 * Special commands
5390 *
5391 * These do not follow the normal rules for commands. See each command for
5392 * details.
5393 */
5394
5395/*
5396 * Reboot NOW
5397 *
5398 * This command will work even when the EC LPC interface is busy, because the
5399 * reboot command is processed at interrupt level. Note that when the EC
5400 * reboots, the host will reboot too, so there is no response to this command.
5401 *
5402 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5403 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005404#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005405
5406/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005407 * Resend last response (not supported on LPC).
5408 *
5409 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5410 * there was no previous command, or the previous command's response was too
5411 * big to save.
5412 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005413#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005414
5415/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005416 * This header byte on a command indicate version 0. Any header byte less
5417 * than this means that we are talking to an old EC which doesn't support
5418 * versioning. In that case, we assume version 0.
5419 *
5420 * Header bytes greater than this indicate a later version. For example,
5421 * EC_CMD_VERSION0 + 1 means we are using version 1.
5422 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005423 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005424 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005425#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005426
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005427/*****************************************************************************/
5428/*
5429 * PD commands
5430 *
5431 * These commands are for PD MCU communication.
5432 */
5433
5434/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005435#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005436#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005437
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005438enum pd_charge_state {
5439 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
5440 PD_CHARGE_NONE, /* No charging allowed */
5441 PD_CHARGE_5V, /* 5V charging only */
5442 PD_CHARGE_MAX /* Charge at max voltage */
5443};
5444
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005445/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005446#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005447
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005448struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005449 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005450 int8_t batt_soc; /* battery state of charge */
5451 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005452} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005453
5454/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005455#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5456#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
5457#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
5458#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5459#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5460#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5461#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08005462#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
5463 PD_STATUS_TCPC_ALERT_1 | \
5464 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005465struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005466 uint32_t curr_lim_ma; /* input current limit */
5467 uint16_t status; /* PD MCU status */
5468 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005469} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005470
5471/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005472#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005473
5474/* PD MCU host event status bits */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005475#define PD_EVENT_UPDATE_DEVICE BIT(0)
5476#define PD_EVENT_POWER_CHANGE BIT(1)
5477#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5478#define PD_EVENT_DATA_SWAP BIT(3)
5479#define PD_EVENT_TYPEC BIT(4)
5480
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005481struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005482 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005483} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005484
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005485/*
5486 * Set USB type-C port role and muxes
5487 *
5488 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5489 *
5490 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5491 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005492#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005493
5494enum usb_pd_control_role {
5495 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5496 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5497 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5498 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5499 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005500 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005501 USB_PD_CTRL_ROLE_COUNT
5502};
5503
5504enum usb_pd_control_mux {
5505 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5506 USB_PD_CTRL_MUX_NONE = 1,
5507 USB_PD_CTRL_MUX_USB = 2,
5508 USB_PD_CTRL_MUX_DP = 3,
5509 USB_PD_CTRL_MUX_DOCK = 4,
5510 USB_PD_CTRL_MUX_AUTO = 5,
5511 USB_PD_CTRL_MUX_COUNT
5512};
5513
Duncan Laurieeb316852015-12-01 18:51:18 -08005514enum usb_pd_control_swap {
5515 USB_PD_CTRL_SWAP_NONE = 0,
5516 USB_PD_CTRL_SWAP_DATA = 1,
5517 USB_PD_CTRL_SWAP_POWER = 2,
5518 USB_PD_CTRL_SWAP_VCONN = 3,
5519 USB_PD_CTRL_SWAP_COUNT
5520};
5521
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005522struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005523 uint8_t port;
5524 uint8_t role;
5525 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005526 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005527} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005528
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005529#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5530#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
5531#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005532
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005533#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5534#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5535#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5536#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5537#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5538#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005539#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */
Duncan Laurieeb316852015-12-01 18:51:18 -08005540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005541struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005542 uint8_t enabled;
5543 uint8_t role;
5544 uint8_t polarity;
5545 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005546} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005547
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005548struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005549 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005550 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005551 uint8_t polarity;
5552 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005553} __ec_align1;
5554
Jett Rinkba2edaf2020-01-14 11:49:06 -07005555/* Possible port partner connections based on CC line states */
5556enum pd_cc_states {
5557 PD_CC_NONE = 0, /* No port partner attached */
5558
5559 /* From DFP perspective */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005560 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005561 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5562 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5563 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
5564
5565 /* From UFP perspective */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005566 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005567 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005568};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005569
Jett Rinkba2edaf2020-01-14 11:49:06 -07005570/* Active/Passive Cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005571#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005572/* Optical/Non-optical cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005573#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005574/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005575#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
5576/* Active Link Uni-Direction */
5577#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005578
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005579struct ec_response_usb_pd_control_v2 {
5580 uint8_t enabled;
5581 uint8_t role;
5582 uint8_t polarity;
5583 char state[32];
Jett Rinkba2edaf2020-01-14 11:49:06 -07005584 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5585 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005586 uint8_t reserved; /* Reserved for future use */
5587 uint8_t control_flags; /* USB_PD_CTRL_*flags */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005588 uint8_t cable_speed; /* TBT_SS_* cable speed */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005589 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005590} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005591
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005592#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005593
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005594/* Maximum number of PD ports on a device, num_ports will be <= this */
5595#define EC_USB_PD_MAX_PORTS 8
5596
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005597struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005598 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005599} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005600
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005601#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005602
5603#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005604struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005605 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005606} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005607
5608enum usb_chg_type {
5609 USB_CHG_TYPE_NONE,
5610 USB_CHG_TYPE_PD,
5611 USB_CHG_TYPE_C,
5612 USB_CHG_TYPE_PROPRIETARY,
5613 USB_CHG_TYPE_BC12_DCP,
5614 USB_CHG_TYPE_BC12_CDP,
5615 USB_CHG_TYPE_BC12_SDP,
5616 USB_CHG_TYPE_OTHER,
5617 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005618 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005619 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005620};
5621enum usb_power_roles {
5622 USB_PD_PORT_POWER_DISCONNECTED,
5623 USB_PD_PORT_POWER_SOURCE,
5624 USB_PD_PORT_POWER_SINK,
5625 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5626};
5627
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005628struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005629 uint16_t voltage_max;
5630 uint16_t voltage_now;
5631 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005632 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005633} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005634
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005635struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005636 uint8_t role;
5637 uint8_t type;
5638 uint8_t dualrole;
5639 uint8_t reserved1;
5640 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005641 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005642} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005643
Yidi Lin42f79592020-09-21 18:04:10 +08005644
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005645/*
5646 * This command will return the number of USB PD charge port + the number
5647 * of dedicated port present.
5648 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5649 */
5650#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005651struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005652 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005653} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005654
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005655/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005656#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005657
5658enum usb_pd_fw_update_cmds {
5659 USB_PD_FW_REBOOT,
5660 USB_PD_FW_FLASH_ERASE,
5661 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005662 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005663};
5664
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005665struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005666 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005667 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005668 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005669 uint32_t size; /* Size to write in bytes */
5670 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005671} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005672
5673/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005674#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005675/* RW hash is first 20 bytes of SHA-256 of RW section */
5676#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005677struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005678 uint16_t dev_id;
5679 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005680 uint8_t reserved; /*
5681 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005682 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005683 * Should have been reserved[2].
5684 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005685 uint32_t current_image; /* One of ec_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005686} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005687
5688/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005689#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005691struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005692 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005693} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005694
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005695/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005696#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005697struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005698 uint16_t vid; /* USB-IF VID */
5699 uint16_t pid; /* USB-IF PID */
5700 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005701} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005702
5703/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005704#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005705
5706/* Negative port parameters have special meaning */
5707enum usb_pd_override_ports {
5708 OVERRIDE_DONT_CHARGE = -2,
5709 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005710 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005711};
5712
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005713struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005714 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005715} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005716
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005717/*
5718 * Read (and delete) one entry of PD event log.
5719 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5720 * future non-PD logs that use the same internal EC event_log.
5721 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005722#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005723
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005724struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005725 uint32_t timestamp; /* relative timestamp in milliseconds */
5726 uint8_t type; /* event type : see PD_EVENT_xx below */
5727 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5728 uint16_t data; /* type-defined data payload */
5729 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005730} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005731
5732/* The timestamp is the microsecond counter shifted to get about a ms. */
5733#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5734
Duncan Laurieeb316852015-12-01 18:51:18 -08005735#define PD_LOG_SIZE_MASK 0x1f
5736#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005737#define PD_LOG_PORT_SHIFT 5
5738#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5739 ((size) & PD_LOG_SIZE_MASK))
5740#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5741#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5742
5743/* PD event log : entry types */
5744/* PD MCU events */
5745#define PD_EVENT_MCU_BASE 0x00
5746#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5747#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5748/* Reserved for custom board event */
5749#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5750/* PD generic accessory events */
5751#define PD_EVENT_ACC_BASE 0x20
5752#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5753#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5754/* PD power supply events */
5755#define PD_EVENT_PS_BASE 0x40
5756#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5757/* PD video dongles events */
5758#define PD_EVENT_VIDEO_BASE 0x60
5759#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5760#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5761/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005762#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005763
5764/*
5765 * PD_EVENT_MCU_CHARGE event definition :
5766 * the payload is "struct usb_chg_measures"
5767 * the data field contains the port state flags as defined below :
5768 */
5769/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005770#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005771/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005772#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005773/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005774#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005775/* Charger type */
5776#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005777#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005778/* Power delivery role */
5779#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5780
5781/*
5782 * PD_EVENT_PS_FAULT data field flags definition :
5783 */
5784#define PS_FAULT_OCP 1
5785#define PS_FAULT_FAST_OCP 2
5786#define PS_FAULT_OVP 3
5787#define PS_FAULT_DISCH 4
5788
5789/*
5790 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5791 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005792struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005793 uint8_t major;
5794 uint8_t minor;
5795 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005796} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005797
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005798struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005799 uint8_t family[2];
5800 uint8_t chipid[2];
5801 struct mcdp_version irom;
5802 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005803} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005804
5805/* struct mcdp_info field decoding */
5806#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5807#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5808
5809/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005810#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005811struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005812 uint16_t svid_idx; /* SVID index to get */
5813 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005814} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005816struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005817 uint16_t svid; /* SVID */
5818 uint16_t opos; /* Object Position */
5819 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005820} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005821
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005822#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005823
5824enum pd_mode_cmd {
5825 PD_EXIT_MODE = 0,
5826 PD_ENTER_MODE = 1,
5827 /* Not a command. Do NOT remove. */
5828 PD_MODE_CMD_COUNT,
5829};
5830
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005831struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005832 uint32_t cmd; /* enum pd_mode_cmd */
5833 uint16_t svid; /* SVID to set */
5834 uint8_t opos; /* Object Position */
5835 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005836} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005837
5838/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005839#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005840
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005841struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005842 uint8_t type; /* event type : see PD_EVENT_xx above */
5843 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005844} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005845
Yidi Lin42f79592020-09-21 18:04:10 +08005846
Gwendal Grignou880b4582016-06-20 08:49:25 -07005847/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005848#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005849
5850enum ec_pd_control_cmd {
5851 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5852 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5853 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005854 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5855 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005856};
5857
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005858struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005859 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005860 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005861} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005862
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005863/* Get info about USB-C SS muxes */
5864#define EC_CMD_USB_PD_MUX_INFO 0x011A
5865
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005866struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005867 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005868} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005869
5870/* Flags representing mux state */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005871#define USB_PD_MUX_NONE 0 /* Open switch */
5872#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5873#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5874#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5875#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
Rob Barnes5ab14662021-09-17 10:24:45 -06005876#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005877#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
Rob Barnes5ab14662021-09-17 10:24:45 -06005878#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005879#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
5880#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005881#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
5882
5883/* USB-C Dock connected */
5884#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005885
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005886struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005887 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005888} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005889
5890#define EC_CMD_PD_CHIP_INFO 0x011B
5891
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005892struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005893 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005894 /*
5895 * Fetch the live chip info or hard-coded + cached chip info
5896 * 0: hardcoded value for VID/PID, cached value for FW version
5897 * 1: live chip value for VID/PID/FW Version
5898 */
5899 uint8_t live;
5900} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005901
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005902struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005903 uint16_t vendor_id;
5904 uint16_t product_id;
5905 uint16_t device_id;
5906 union {
5907 uint8_t fw_version_string[8];
5908 uint64_t fw_version_number;
5909 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005910} __ec_align2;
5911
5912struct ec_response_pd_chip_info_v1 {
5913 uint16_t vendor_id;
5914 uint16_t product_id;
5915 uint16_t device_id;
5916 union {
5917 uint8_t fw_version_string[8];
5918 uint64_t fw_version_number;
5919 };
5920 union {
5921 uint8_t min_req_fw_version_string[8];
5922 uint64_t min_req_fw_version_number;
5923 };
5924} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005925
5926/* Run RW signature verification and get status */
5927#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5928
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005929struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005930 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005931} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005932
5933/* For controlling RWSIG task */
5934#define EC_CMD_RWSIG_ACTION 0x011D
5935
5936enum rwsig_action {
5937 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5938 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5939};
5940
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005941struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005942 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005943} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005944
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005945/* Run verification on a slot */
5946#define EC_CMD_EFS_VERIFY 0x011E
5947
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005948struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005949 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005950} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005951
5952/*
5953 * Retrieve info from Cros Board Info store. Response is based on the data
5954 * type. Integers return a uint32. Strings return a string, using the response
5955 * size to determine how big it is.
5956 */
5957#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5958/*
5959 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5960 * hardware write-protect enabled.
5961 */
5962#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5963
Daisuke Nojirif984a052018-02-15 12:38:15 -08005964enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005965 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5966 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5967 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005968 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005969 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005970 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005971 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005972 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08005973 /* Second Source Factory Cache */
5974 CBI_TAG_SSFC = 8, /* uint32_t bit field */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06005975 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005976 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005977};
5978
5979/*
5980 * Flags to control read operation
5981 *
5982 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5983 * write was successful without reboot.
5984 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005985#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005986
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005987struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005988 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005989 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005990} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005991
5992/*
5993 * Flags to control write behavior.
5994 *
5995 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5996 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005997 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005998 * will be initialized to zero first.
5999 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006000#define CBI_SET_NO_SYNC BIT(0)
6001#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006002
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006003struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08006004 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006005 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006006 uint32_t size; /* Data size */
6007 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006008} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006009
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006010/*
6011 * Information about resets of the AP by the EC and the EC's own uptime.
6012 */
6013#define EC_CMD_GET_UPTIME_INFO 0x0121
6014
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006015/* EC reset causes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006016#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6017#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6018#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6019#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6020#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6021#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6022#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6023#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6024#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6025#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6026#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6027#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6028#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
6029#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
6030 * previous boot
6031 */
6032#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6033#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6034#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6035#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
6036#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006037#define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This
6038 * enables PD in RO for Chromebox.
6039 */
Yidi Lin42f79592020-09-21 18:04:10 +08006040#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6041#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6042#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006043
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006044/*
6045 * Reason codes used by the AP after a shutdown to figure out why it was reset
6046 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6047 * compatibility:
6048 * - New entries must be inserted prior to the _COUNT field
6049 * - If an existing entry is no longer in service, it must be replaced with a
6050 * RESERVED entry instead.
6051 * - The semantic meaning of an entry should not change.
6052 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6053 */
6054enum chipset_reset_reason {
6055 CHIPSET_RESET_BEGIN = 0,
6056 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6057 /* Custom reason defined by a board.c or baseboard.c file */
6058 CHIPSET_RESET_BOARD_CUSTOM,
6059 /* Believe that the AP has hung */
6060 CHIPSET_RESET_HANG_REBOOT,
6061 /* Reset by EC console command */
6062 CHIPSET_RESET_CONSOLE_CMD,
6063 /* Reset by EC host command */
6064 CHIPSET_RESET_HOST_CMD,
6065 /* Keyboard module reset key combination */
6066 CHIPSET_RESET_KB_SYSRESET,
6067 /* Keyboard module warm reboot */
6068 CHIPSET_RESET_KB_WARM_REBOOT,
6069 /* Debug module warm reboot */
6070 CHIPSET_RESET_DBG_WARM_REBOOT,
6071 /* I cannot self-terminate. You must lower me into the steel. */
6072 CHIPSET_RESET_AP_REQ,
6073 /* Reset as side-effect of startup sequence */
6074 CHIPSET_RESET_INIT,
6075 /* EC detected an AP watchdog event. */
6076 CHIPSET_RESET_AP_WATCHDOG,
6077
6078 CHIPSET_RESET_COUNT,
6079};
6080
6081/*
6082 * AP hard shutdowns are logged on the same path as resets.
6083 */
6084enum chipset_shutdown_reason {
6085 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6086 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6087 /* Forcing a shutdown as part of EC initialization */
6088 CHIPSET_SHUTDOWN_INIT,
6089 /* Custom reason on a per-board basis. */
6090 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6091 /* This is a reason to inhibit startup, not cause shut down. */
6092 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6093 /* A power_wait_signal is being asserted */
6094 CHIPSET_SHUTDOWN_WAIT,
6095 /* Critical battery level. */
6096 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6097 /* Because you told me to. */
6098 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6099 /* Forcing a shutdown to effect entry to G3. */
6100 CHIPSET_SHUTDOWN_G3,
6101 /* Force shutdown due to over-temperature. */
6102 CHIPSET_SHUTDOWN_THERMAL,
6103 /* Force a chipset shutdown from the power button through EC */
6104 CHIPSET_SHUTDOWN_BUTTON,
6105
6106 CHIPSET_SHUTDOWN_COUNT,
6107};
6108
6109
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006110struct ec_response_uptime_info {
6111 /*
6112 * Number of milliseconds since the last EC boot. Sysjump resets
6113 * typically do not restart the EC's time_since_boot epoch.
6114 *
6115 * WARNING: The EC's sense of time is much less accurate than the AP's
6116 * sense of time, in both phase and frequency. This timebase is similar
6117 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6118 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006119 uint32_t time_since_ec_boot_ms;
6120
6121 /*
6122 * Number of times the AP was reset by the EC since the last EC boot.
6123 * Note that the AP may be held in reset by the EC during the initial
6124 * boot sequence, such that the very first AP boot may count as more
6125 * than one here.
6126 */
6127 uint32_t ap_resets_since_ec_boot;
6128
6129 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006130 * The set of flags which describe the EC's most recent reset.
6131 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006132 */
6133 uint32_t ec_reset_flags;
6134
6135 /* Empty log entries have both the cause and timestamp set to zero. */
6136 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006137 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006138 uint16_t reset_cause;
6139
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006140 /* Reserved for protocol growth. */
6141 uint16_t reserved;
6142
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006143 /*
6144 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006145 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6146 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006147 */
6148 uint32_t reset_time_ms;
6149 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006150} __ec_align4;
6151
6152/*
6153 * Add entropy to the device secret (stored in the rollback region).
6154 *
6155 * Depending on the chip, the operation may take a long time (e.g. to erase
6156 * flash), so the commands are asynchronous.
6157 */
6158#define EC_CMD_ADD_ENTROPY 0x0122
6159
6160enum add_entropy_action {
6161 /* Add entropy to the current secret. */
6162 ADD_ENTROPY_ASYNC = 0,
6163 /*
6164 * Add entropy, and also make sure that the previous secret is erased.
6165 * (this can be implemented by adding entropy multiple times until
6166 * all rolback blocks have been overwritten).
6167 */
6168 ADD_ENTROPY_RESET_ASYNC = 1,
6169 /* Read back result from the previous operation. */
6170 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006171};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006172
6173struct ec_params_rollback_add_entropy {
6174 uint8_t action;
6175} __ec_align1;
6176
6177/*
6178 * Perform a single read of a given ADC channel.
6179 */
6180#define EC_CMD_ADC_READ 0x0123
6181
6182struct ec_params_adc_read {
6183 uint8_t adc_channel;
6184} __ec_align1;
6185
6186struct ec_response_adc_read {
6187 int32_t adc_value;
6188} __ec_align4;
6189
6190/*
6191 * Read back rollback info
6192 */
6193#define EC_CMD_ROLLBACK_INFO 0x0124
6194
6195struct ec_response_rollback_info {
6196 int32_t id; /* Incrementing number to indicate which region to use. */
6197 int32_t rollback_min_version;
6198 int32_t rw_rollback_version;
6199} __ec_align4;
6200
Yidi Lin42f79592020-09-21 18:04:10 +08006201
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006202/* Issue AP reset */
6203#define EC_CMD_AP_RESET 0x0125
6204
6205/*****************************************************************************/
6206/* Locate peripheral chips
6207 *
6208 * Return values:
6209 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6210 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6211 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6212 */
6213#define EC_CMD_LOCATE_CHIP 0x0126
6214
6215enum ec_chip_type {
6216 EC_CHIP_TYPE_CBI_EEPROM = 0,
6217 EC_CHIP_TYPE_TCPC = 1,
6218 EC_CHIP_TYPE_COUNT,
6219 EC_CHIP_TYPE_MAX = 0xFF,
6220};
6221
6222enum ec_bus_type {
6223 EC_BUS_TYPE_I2C = 0,
6224 EC_BUS_TYPE_EMBEDDED = 1,
6225 EC_BUS_TYPE_COUNT,
6226 EC_BUS_TYPE_MAX = 0xFF,
6227};
6228
6229struct ec_i2c_info {
6230 uint16_t port; /* Physical port for device */
6231 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
6232};
6233
6234struct ec_params_locate_chip {
6235 uint8_t type; /* enum ec_chip_type */
6236 uint8_t index; /* Specifies one instance of chip type */
6237 /* Used for type specific parameters in future */
6238 union {
6239 uint16_t reserved;
6240 };
6241} __ec_align2;
6242
Yidi Lin42f79592020-09-21 18:04:10 +08006243
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006244struct ec_response_locate_chip {
6245 uint8_t bus_type; /* enum ec_bus_type */
6246 uint8_t reserved; /* Aligning the following union to 2 bytes */
6247 union {
6248 struct ec_i2c_info i2c_info;
6249 };
6250} __ec_align2;
6251
Jett Rinkba2edaf2020-01-14 11:49:06 -07006252/*
6253 * Reboot AP on G3
6254 *
6255 * This command is used for validation purpose, where the AP needs to be
6256 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006257 * wake events.
6258 * - With command version 0:
6259 * AP reboots immediately from G3
6260 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6261 * - With command version 1:
6262 * AP reboots after the user specified delay
6263 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006264 */
6265#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6266
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006267struct ec_params_reboot_ap_on_g3_v1 {
6268 /* configurable delay in seconds in G3 state */
6269 uint32_t reboot_ap_at_g3_delay;
6270} __ec_align4;
6271
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006272/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006273/* Get PD port capabilities
6274 *
6275 * Returns the following static *capabilities* of the given port:
6276 * 1) Power role: source, sink, or dual. It is not anticipated that
6277 * future CrOS devices would ever be only a source, so the options are
6278 * sink or dual.
6279 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6280 * believe any CrOS device would support Try.SNK, so this would be source
6281 * or none).
6282 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6283 * for CrOS devices.
6284 */
6285#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6286
6287enum ec_pd_power_role_caps {
6288 EC_PD_POWER_ROLE_SOURCE = 0,
6289 EC_PD_POWER_ROLE_SINK = 1,
6290 EC_PD_POWER_ROLE_DUAL = 2,
6291};
6292
6293enum ec_pd_try_power_role_caps {
6294 EC_PD_TRY_POWER_ROLE_NONE = 0,
6295 EC_PD_TRY_POWER_ROLE_SINK = 1,
6296 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6297};
6298
6299enum ec_pd_data_role_caps {
6300 EC_PD_DATA_ROLE_DFP = 0,
6301 EC_PD_DATA_ROLE_UFP = 1,
6302 EC_PD_DATA_ROLE_DUAL = 2,
6303};
6304
6305/* From: power_manager/power_supply_properties.proto */
6306enum ec_pd_port_location {
6307 /* The location of the port is unknown, or there's only one port. */
6308 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6309
6310 /*
6311 * Various positions on the device. The first word describes the side of
6312 * the device where the port is located while the second clarifies the
6313 * position. For example, LEFT_BACK means the farthest-back port on the
6314 * left side, while BACK_LEFT means the leftmost port on the back of the
6315 * device.
6316 */
6317 EC_PD_PORT_LOCATION_LEFT = 1,
6318 EC_PD_PORT_LOCATION_RIGHT = 2,
6319 EC_PD_PORT_LOCATION_BACK = 3,
6320 EC_PD_PORT_LOCATION_FRONT = 4,
6321 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6322 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
6323 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
6324 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6325 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6326 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
6327};
6328
6329struct ec_params_get_pd_port_caps {
6330 uint8_t port; /* Which port to interrogate */
6331} __ec_align1;
6332
6333struct ec_response_get_pd_port_caps {
6334 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6335 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6336 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6337 uint8_t pd_port_location; /* enum ec_pd_port_location */
6338} __ec_align1;
6339
6340/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006341/*
6342 * Button press simulation
6343 *
6344 * This command is used to simulate a button press.
6345 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6346 * Time duration for which button needs to be pressed is an optional parameter.
6347 *
6348 * NOTE: This is only available on unlocked devices for testing purposes only.
6349 */
6350#define EC_CMD_BUTTON 0x0129
6351
6352struct ec_params_button {
6353 /* Button mask aligned to enum keyboard_button_type */
6354 uint32_t btn_mask;
6355
6356 /* Duration in milliseconds button needs to be pressed */
6357 uint32_t press_ms;
6358} __ec_align1;
6359
6360enum keyboard_button_type {
6361 KEYBOARD_BUTTON_POWER = 0,
6362 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
6363 KEYBOARD_BUTTON_VOLUME_UP = 2,
6364 KEYBOARD_BUTTON_RECOVERY = 3,
6365 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6366 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6367 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6368 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6369 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6370 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6371 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6372 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
6373
6374 KEYBOARD_BUTTON_COUNT
6375};
Yidi Lin42f79592020-09-21 18:04:10 +08006376
Rajat Jainc0495722020-04-02 23:58:35 -07006377/*****************************************************************************/
6378/*
6379 * "Get the Keyboard Config". An EC implementing this command is expected to be
6380 * vivaldi capable, i.e. can send action codes for the top row keys.
6381 * Additionally, capability to send function codes for the same keys is
6382 * optional and acceptable.
6383 *
6384 * Note: If the top row can generate both function and action codes by
6385 * using a dedicated Fn key, it does not matter whether the key sends
6386 * "function" or "action" codes by default. In both cases, the response
6387 * for this command will look the same.
6388 */
6389#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6390
6391/* Possible values for the top row keys */
6392enum action_key {
6393 TK_ABSENT = 0,
6394 TK_BACK = 1,
6395 TK_FORWARD = 2,
6396 TK_REFRESH = 3,
6397 TK_FULLSCREEN = 4,
6398 TK_OVERVIEW = 5,
6399 TK_BRIGHTNESS_DOWN = 6,
6400 TK_BRIGHTNESS_UP = 7,
6401 TK_VOL_MUTE = 8,
6402 TK_VOL_DOWN = 9,
6403 TK_VOL_UP = 10,
6404 TK_SNAPSHOT = 11,
6405 TK_PRIVACY_SCRN_TOGGLE = 12,
6406 TK_KBD_BKLIGHT_DOWN = 13,
6407 TK_KBD_BKLIGHT_UP = 14,
6408 TK_PLAY_PAUSE = 15,
6409 TK_NEXT_TRACK = 16,
6410 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006411 TK_KBD_BKLIGHT_TOGGLE = 18,
6412 TK_MICMUTE = 19,
Rajat Jainc0495722020-04-02 23:58:35 -07006413};
6414
6415/*
6416 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6417 * If this needs to change, please create a new version of the command.
6418 */
6419#define MAX_TOP_ROW_KEYS 15
6420#define MIN_TOP_ROW_KEYS 10
6421
6422/*
6423 * Is the keyboard capable of sending function keys *in addition to*
6424 * action keys. This is possible for e.g. if the keyboard has a
6425 * dedicated Fn key.
6426 */
6427#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
6428/*
6429 * Whether the keyboard has a dedicated numeric keyboard.
6430 */
6431#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
6432/*
6433 * Whether the keyboard has a screenlock key.
6434 */
6435#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
6436
6437struct ec_response_keybd_config {
6438 /*
6439 * Number of top row keys, excluding Esc and Screenlock.
6440 * If this is 0, all Vivaldi keyboard code is disabled.
6441 * (i.e. does not expose any tables to the kernel).
6442 */
6443 uint8_t num_top_row_keys;
6444
6445 /*
6446 * The action keys in the top row, in order from left to right.
6447 * The values are filled from enum action_key. Esc and Screenlock
6448 * keys are not considered part of top row keys.
6449 */
6450 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6451
6452 /* Capability flags */
6453 uint8_t capabilities;
6454
6455} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006456
Yidi Lin42f79592020-09-21 18:04:10 +08006457/*
6458 * Configure smart discharge
6459 */
6460#define EC_CMD_SMART_DISCHARGE 0x012B
6461
6462#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
6463
6464/* Discharge rates when the system is in cutoff or hibernation. */
6465struct discharge_rate {
6466 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6467 uint16_t hibern; /* Discharge rate (uA) in hibernation */
6468};
6469
6470struct smart_discharge_zone {
6471 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6472 int cutoff;
6473 /* When the capacity (mAh) is below this, EC stays up. */
6474 int stayup;
6475};
6476
6477struct ec_params_smart_discharge {
6478 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
6479 /*
6480 * Desired hours for the battery to survive before reaching 0%. Set to
6481 * zero to disable smart discharging. That is, the system hibernates as
6482 * soon as the G3 idle timer expires.
6483 */
6484 uint16_t hours_to_zero;
6485 /* Set both to zero to keep the current rates. */
6486 struct discharge_rate drate;
6487};
6488
6489struct ec_response_smart_discharge {
6490 uint16_t hours_to_zero;
6491 struct discharge_rate drate;
6492 struct smart_discharge_zone dzone;
6493};
6494
6495/*****************************************************************************/
6496/* Voltage regulator controls */
6497
6498/*
6499 * Get basic info of voltage regulator for given index.
6500 *
6501 * Returns the regulator name and supported voltage list in mV.
6502 */
6503#define EC_CMD_REGULATOR_GET_INFO 0x012C
6504
6505/* Maximum length of regulator name */
6506#define EC_REGULATOR_NAME_MAX_LEN 16
6507
6508/* Maximum length of the supported voltage list. */
6509#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6510
6511struct ec_params_regulator_get_info {
6512 uint32_t index;
6513} __ec_align4;
6514
6515struct ec_response_regulator_get_info {
6516 char name[EC_REGULATOR_NAME_MAX_LEN];
6517 uint16_t num_voltages;
6518 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6519} __ec_align2;
6520
6521/*
6522 * Configure the regulator as enabled / disabled.
6523 */
6524#define EC_CMD_REGULATOR_ENABLE 0x012D
6525
6526struct ec_params_regulator_enable {
6527 uint32_t index;
6528 uint8_t enable;
6529} __ec_align4;
6530
6531/*
6532 * Query if the regulator is enabled.
6533 *
6534 * Returns 1 if the regulator is enabled, 0 if not.
6535 */
6536#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6537
6538struct ec_params_regulator_is_enabled {
6539 uint32_t index;
6540} __ec_align4;
6541
6542struct ec_response_regulator_is_enabled {
6543 uint8_t enabled;
6544} __ec_align1;
6545
6546/*
6547 * Set voltage for the voltage regulator within the range specified.
6548 *
6549 * The driver should select the voltage in range closest to min_mv.
6550 *
6551 * Also note that this might be called before the regulator is enabled, and the
6552 * setting should be in effect after the regulator is enabled.
6553 */
6554#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6555
6556struct ec_params_regulator_set_voltage {
6557 uint32_t index;
6558 uint32_t min_mv;
6559 uint32_t max_mv;
6560} __ec_align4;
6561
6562/*
6563 * Get the currently configured voltage for the voltage regulator.
6564 *
6565 * Note that this might be called before the regulator is enabled, and this
6566 * should return the configured output voltage if the regulator is enabled.
6567 */
6568#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6569
6570struct ec_params_regulator_get_voltage {
6571 uint32_t index;
6572} __ec_align4;
6573
6574struct ec_response_regulator_get_voltage {
6575 uint32_t voltage_mv;
6576} __ec_align4;
6577
6578/*
6579 * Gather all discovery information for the given port and partner type.
6580 *
6581 * Note that if discovery has not yet completed, only the currently completed
6582 * responses will be filled in. If the discovery data structures are changed
6583 * in the process of the command running, BUSY will be returned.
6584 *
6585 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6586 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6587 * maximum parameter size.
6588 */
6589#define EC_CMD_TYPEC_DISCOVERY 0x0131
6590
6591enum typec_partner_type {
6592 TYPEC_PARTNER_SOP = 0,
6593 TYPEC_PARTNER_SOP_PRIME = 1,
6594};
6595
6596struct ec_params_typec_discovery {
6597 uint8_t port;
6598 uint8_t partner_type; /* enum typec_partner_type */
6599} __ec_align1;
6600
6601struct svid_mode_info {
6602 uint16_t svid;
6603 uint16_t mode_count; /* Number of modes partner sent */
6604 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6605};
6606
6607struct ec_response_typec_discovery {
6608 uint8_t identity_count; /* Number of identity VDOs partner sent */
6609 uint8_t svid_count; /* Number of SVIDs partner sent */
6610 uint16_t reserved;
6611 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6612 struct svid_mode_info svids[0];
6613} __ec_align1;
6614
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006615/* USB Type-C commands for AP-controlled device policy. */
6616#define EC_CMD_TYPEC_CONTROL 0x0132
6617
6618enum typec_control_command {
6619 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6620 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006621 TYPEC_CONTROL_COMMAND_ENTER_MODE,
6622};
6623
6624/* Modes (USB or alternate) that a type-C port may enter. */
6625enum typec_mode {
6626 TYPEC_MODE_DP,
6627 TYPEC_MODE_TBT,
6628 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006629};
6630
6631struct ec_params_typec_control {
6632 uint8_t port;
6633 uint8_t command; /* enum typec_control_command */
6634 uint16_t reserved;
6635
6636 /*
6637 * This section will be interpreted based on |command|. Define a
6638 * placeholder structure to avoid having to increase the size and bump
6639 * the command version when adding new sub-commands.
6640 */
6641 union {
6642 uint32_t clear_events_mask;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006643 uint8_t mode_to_enter; /* enum typec_mode */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006644 uint8_t placeholder[128];
6645 };
6646} __ec_align1;
6647
6648/*
6649 * Gather all status information for a port.
6650 *
6651 * Note: this covers many of the return fields from the deprecated
6652 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6653 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6654 * EC_CMD_USB_PD_CONTROL command.
6655 *
6656 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006657 */
6658#define EC_CMD_TYPEC_STATUS 0x0133
6659
6660/*
6661 * Power role.
6662 *
6663 * Note this is also used for PD header creation, and values align to those in
6664 * the Power Delivery Specification Revision 3.0 (See
6665 * 6.2.1.1.4 Port Power Role).
6666 */
6667enum pd_power_role {
6668 PD_ROLE_SINK = 0,
6669 PD_ROLE_SOURCE = 1
6670};
6671
6672/*
6673 * Data role.
6674 *
6675 * Note this is also used for PD header creation, and the first two values
6676 * align to those in the Power Delivery Specification Revision 3.0 (See
6677 * 6.2.1.1.6 Port Data Role).
6678 */
6679enum pd_data_role {
6680 PD_ROLE_UFP = 0,
6681 PD_ROLE_DFP = 1,
6682 PD_ROLE_DISCONNECTED = 2,
6683};
6684
6685enum pd_vconn_role {
6686 PD_ROLE_VCONN_OFF = 0,
6687 PD_ROLE_VCONN_SRC = 1,
6688};
6689
6690/*
6691 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6692 * regardless of whether a debug accessory is connected.
6693 */
6694enum tcpc_cc_polarity {
6695 /*
6696 * _CCx: is used to indicate the polarity while not connected to
6697 * a Debug Accessory. Only one CC line will assert a resistor and
6698 * the other will be open.
6699 */
6700 POLARITY_CC1 = 0,
6701 POLARITY_CC2 = 1,
6702
6703 /*
6704 * _CCx_DTS is used to indicate the polarity while connected to a
6705 * SRC Debug Accessory. Assert resistors on both lines.
6706 */
6707 POLARITY_CC1_DTS = 2,
6708 POLARITY_CC2_DTS = 3,
6709
6710 /*
6711 * The current TCPC code relies on these specific POLARITY values.
6712 * Adding in a check to verify if the list grows for any reason
6713 * that this will give a hint that other places need to be
6714 * adjusted.
6715 */
6716 POLARITY_COUNT
6717};
6718
6719#define MODE_DP_PIN_A BIT(0)
6720#define MODE_DP_PIN_B BIT(1)
6721#define MODE_DP_PIN_C BIT(2)
6722#define MODE_DP_PIN_D BIT(3)
6723#define MODE_DP_PIN_E BIT(4)
6724#define MODE_DP_PIN_F BIT(5)
6725#define MODE_DP_PIN_ALL GENMASK(5, 0)
6726
6727#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6728#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006729#define PD_STATUS_EVENT_HARD_RESET BIT(2)
Scott Chao18141d8c2021-07-30 10:40:57 +08006730#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006731
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006732/*
6733 * Encode and decode for BCD revision response
6734 *
6735 * Note: the major revision set is written assuming that the value given is the
6736 * Specification Revision from the PD header, which currently only maps to PD
6737 * 1.0-3.0 with the major revision being one greater than the binary value.
6738 */
6739#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6740#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6741#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
6742
6743/*
6744 * Decode helpers for Source and Sink Capability PDOs
6745 *
6746 * Note: The Power Delivery Specification should be considered the ultimate
6747 * source of truth on the decoding of these PDOs
6748 */
6749#define PDO_TYPE_FIXED (0 << 30)
6750#define PDO_TYPE_BATTERY (1 << 30)
6751#define PDO_TYPE_VARIABLE (2 << 30)
6752#define PDO_TYPE_AUGMENTED (3 << 30)
6753#define PDO_TYPE_MASK (3 << 30)
6754
6755/*
6756 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6757 *
6758 * <31:30> : Fixed Supply
6759 * <29> : Dual-Role Power
6760 * <28> : SNK/SRC dependent
6761 * <27> : Unconstrained Power
6762 * <26> : USB Communications Capable
6763 * <25> : Dual-Role Data
6764 * <24:20> : SNK/SRC dependent
6765 * <19:10> : Voltage in 50mV Units
6766 * <9:0> : Maximum Current in 10mA units
6767 */
6768#define PDO_FIXED_DUAL_ROLE BIT(29)
6769#define PDO_FIXED_UNCONSTRAINED BIT(27)
6770#define PDO_FIXED_COMM_CAP BIT(26)
6771#define PDO_FIXED_DATA_SWAP BIT(25)
6772#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
6773#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6774#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
6775
6776/*
6777 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
6778 *
6779 * <31:30> : Battery
6780 * <29:20> : Maximum Voltage in 50mV units
6781 * <19:10> : Minimum Voltage in 50mV units
6782 * <9:0> : Maximum Allowable Power in 250mW units
6783 */
6784#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6785#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6786#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
6787
6788/*
6789 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
6790 *
6791 * <31:30> : Variable Supply (non-Battery)
6792 * <29:20> : Maximum Voltage in 50mV units
6793 * <19:10> : Minimum Voltage in 50mV units
6794 * <9:0> : Operational Current in 10mA units
6795 */
6796#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6797#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6798#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
6799
6800/*
6801 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
6802 *
6803 * Note this type is reserved in PD 2.0, and only one type of APDO is
6804 * supported as of the cited version.
6805 *
6806 * <31:30> : Augmented Power Data Object
6807 * <29:28> : Programmable Power Supply
6808 * <27> : PPS Power Limited
6809 * <26:25> : Reserved
6810 * <24:17> : Maximum Voltage in 100mV increments
6811 * <16> : Reserved
6812 * <15:8> : Minimum Voltage in 100mV increments
6813 * <7> : Reserved
6814 * <6:0> : Maximum Current in 50mA increments
6815 */
6816#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
6817#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
6818#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
6819
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006820struct ec_params_typec_status {
6821 uint8_t port;
6822} __ec_align1;
6823
6824struct ec_response_typec_status {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006825 uint8_t pd_enabled; /* PD communication enabled - bool */
6826 uint8_t dev_connected; /* Device connected - bool */
6827 uint8_t sop_connected; /* Device is SOP PD capable - bool */
6828 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006829
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006830 uint8_t power_role; /* enum pd_power_role */
6831 uint8_t data_role; /* enum pd_data_role */
6832 uint8_t vconn_role; /* enum pd_vconn_role */
6833 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006834
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006835 uint8_t polarity; /* enum tcpc_cc_polarity */
6836 uint8_t cc_state; /* enum pd_cc_states */
6837 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
6838 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006839
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006840 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006841
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006842 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006843
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006844 /*
6845 * BCD PD revisions for partners
6846 *
6847 * The format has the PD major reversion in the upper nibble, and PD
6848 * minor version in the next nibble. Following two nibbles are
6849 * currently 0.
6850 * ex. PD 3.2 would map to 0x3200
6851 *
6852 * PD major/minor will be 0 if no PD device is connected.
6853 */
6854 uint16_t sop_revision;
6855 uint16_t sop_prime_revision;
6856
6857 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
6858
6859 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006860} __ec_align1;
6861
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006862/**
6863 * Get the number of peripheral charge ports
6864 */
6865#define EC_CMD_PCHG_COUNT 0x0134
6866
6867#define EC_PCHG_MAX_PORTS 8
6868
6869struct ec_response_pchg_count {
6870 uint8_t port_count;
6871} __ec_align1;
6872
6873/**
6874 * Get the status of a peripheral charge port
6875 */
6876#define EC_CMD_PCHG 0x0135
6877
6878struct ec_params_pchg {
6879 uint8_t port;
6880} __ec_align1;
6881
6882struct ec_response_pchg {
6883 uint32_t error; /* enum pchg_error */
6884 uint8_t state; /* enum pchg_state state */
6885 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006886 uint8_t unused0;
6887 uint8_t unused1;
6888 /* Fields added in version 1 */
6889 uint32_t fw_version;
6890 uint32_t dropped_event_count;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006891} __ec_align2;
6892
6893enum pchg_state {
6894 /* Charger is reset and not initialized. */
6895 PCHG_STATE_RESET = 0,
6896 /* Charger is initialized or disabled. */
6897 PCHG_STATE_INITIALIZED,
6898 /* Charger is enabled and ready to detect a device. */
6899 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006900 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006901 PCHG_STATE_DETECTED,
6902 /* Device is being charged. */
6903 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006904 /* Device is fully charged. It implies DETECTED (& not charging). */
6905 PCHG_STATE_FULL,
6906 /* In download (a.k.a. firmware update) mode */
6907 PCHG_STATE_DOWNLOAD,
6908 /* In download mode. Ready for receiving data. */
6909 PCHG_STATE_DOWNLOADING,
6910 /* Device is ready for data communication. */
6911 PCHG_STATE_CONNECTED,
6912 /* Put no more entry below */
6913 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006914};
6915
6916#define EC_PCHG_STATE_TEXT { \
6917 [PCHG_STATE_RESET] = "RESET", \
6918 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
6919 [PCHG_STATE_ENABLED] = "ENABLED", \
6920 [PCHG_STATE_DETECTED] = "DETECTED", \
6921 [PCHG_STATE_CHARGING] = "CHARGING", \
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006922 [PCHG_STATE_FULL] = "FULL", \
6923 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
6924 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
6925 [PCHG_STATE_CONNECTED] = "CONNECTED", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006926 }
6927
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006928/**
6929 * Update firmware of peripheral chip
6930 */
6931#define EC_CMD_PCHG_UPDATE 0x0136
6932
6933/* Port number is encoded in bit[28:31]. */
6934#define EC_MKBP_PCHG_PORT_SHIFT 28
6935/* Utility macro for converting MKBP event to port number. */
6936#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
6937/* Utility macro for extracting event bits. */
6938#define EC_MKBP_PCHG_EVENT_MASK(e) ((e) \
6939 & GENMASK(EC_MKBP_PCHG_PORT_SHIFT-1, 0))
6940
6941#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
6942#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
6943#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
6944#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
6945
6946enum ec_pchg_update_cmd {
6947 /* Reset chip to normal mode. */
6948 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
6949 /* Reset and put a chip in update (a.k.a. download) mode. */
6950 EC_PCHG_UPDATE_CMD_OPEN,
6951 /* Write a block of data containing FW image. */
6952 EC_PCHG_UPDATE_CMD_WRITE,
6953 /* Close update session. */
6954 EC_PCHG_UPDATE_CMD_CLOSE,
6955 /* End of commands */
6956 EC_PCHG_UPDATE_CMD_COUNT,
6957};
6958
6959struct ec_params_pchg_update {
6960 /* PCHG port number */
6961 uint8_t port;
6962 /* enum ec_pchg_update_cmd */
6963 uint8_t cmd;
6964 /* Padding */
6965 uint8_t reserved0;
6966 uint8_t reserved1;
6967 /* Version of new firmware */
6968 uint32_t version;
6969 /* CRC32 of new firmware */
6970 uint32_t crc32;
6971 /* Address in chip memory where <data> is written to */
6972 uint32_t addr;
6973 /* Size of <data> */
6974 uint32_t size;
6975 /* Partial data of new firmware */
6976 uint8_t data[];
6977} __ec_align4;
6978
6979BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT
6980 < BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd)*8));
6981
6982struct ec_response_pchg_update {
6983 /* Block size */
6984 uint32_t block_size;
6985} __ec_align4;
6986
6987
6988#define EC_CMD_DISPLAY_SOC 0x0137
6989
6990struct ec_response_display_soc {
6991 int16_t display_soc; /* Display charge in 10ths of a % (1000=100.0%) */
6992 int16_t full_factor; /* Full factor in 10ths of a % (1000=100.0%) */
6993 int16_t shutdown_soc; /* Shutdown SoC in 10ths of a % (1000=100.0%) */
6994} __ec_align2;
6995
6996
6997#define EC_CMD_SET_BASE_STATE 0x0138
6998
6999struct ec_params_set_base_state {
7000 uint8_t cmd; /* enum ec_set_base_state_cmd */
7001} __ec_align1;
7002
7003enum ec_set_base_state_cmd {
7004 EC_SET_BASE_STATE_DETACH = 0,
7005 EC_SET_BASE_STATE_ATTACH,
7006 EC_SET_BASE_STATE_RESET,
7007};
7008
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007009/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007010/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007011
7012/*****************************************************************************/
7013/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007014 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007015 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007016#define EC_CMD_CR51_BASE 0x0300
7017#define EC_CMD_CR51_LAST 0x03FF
7018
7019/*****************************************************************************/
7020/* Fingerprint MCU commands: range 0x0400-0x040x */
7021
7022/* Fingerprint SPI sensor passthru command: prototyping ONLY */
7023#define EC_CMD_FP_PASSTHRU 0x0400
7024
7025#define EC_FP_FLAG_NOT_COMPLETE 0x1
7026
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007027struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007028 uint16_t len; /* Number of bytes to write then read */
7029 uint16_t flags; /* EC_FP_FLAG_xxx */
7030 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007031} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007032
7033/* Configure the Fingerprint MCU behavior */
7034#define EC_CMD_FP_MODE 0x0402
7035
7036/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007037#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007038/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007039#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007040/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007041#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007042/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007043#define FP_MODE_CAPTURE BIT(3)
7044/* Finger enrollment session on-going */
7045#define FP_MODE_ENROLL_SESSION BIT(4)
7046/* Enroll the current finger image */
7047#define FP_MODE_ENROLL_IMAGE BIT(5)
7048/* Try to match the current finger image */
7049#define FP_MODE_MATCH BIT(6)
7050/* Reset and re-initialize the sensor. */
7051#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007052/* Sensor maintenance for dead pixels. */
7053#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007054/* special value: don't change anything just read back current mode */
7055#define FP_MODE_DONT_CHANGE BIT(31)
7056
7057#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
7058 FP_MODE_FINGER_DOWN | \
7059 FP_MODE_FINGER_UP | \
7060 FP_MODE_CAPTURE | \
7061 FP_MODE_ENROLL_SESSION | \
7062 FP_MODE_ENROLL_IMAGE | \
7063 FP_MODE_MATCH | \
7064 FP_MODE_RESET_SENSOR | \
Yidi Lin42f79592020-09-21 18:04:10 +08007065 FP_MODE_SENSOR_MAINTENANCE | \
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007066 FP_MODE_DONT_CHANGE)
7067
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007068/* Capture types defined in bits [30..28] */
7069#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007070#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
7071/*
7072 * This enum must remain ordered, if you add new values you must ensure that
7073 * FP_CAPTURE_TYPE_MAX is still the last one.
7074 */
7075enum fp_capture_type {
7076 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
7077 FP_CAPTURE_VENDOR_FORMAT = 0,
7078 /* Simple raw image capture (produces width x height x bpp bits) */
7079 FP_CAPTURE_SIMPLE_IMAGE = 1,
7080 /* Self test pattern (e.g. checkerboard) */
7081 FP_CAPTURE_PATTERN0 = 2,
7082 /* Self test pattern (e.g. inverted checkerboard) */
7083 FP_CAPTURE_PATTERN1 = 3,
7084 /* Capture for Quality test with fixed contrast */
7085 FP_CAPTURE_QUALITY_TEST = 4,
7086 /* Capture for pixel reset value test */
7087 FP_CAPTURE_RESET_TEST = 5,
7088 FP_CAPTURE_TYPE_MAX,
7089};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007090/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007091#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
7092 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007093
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007094struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007095 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007096} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007097
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007098struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007099 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007100} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007101
7102/* Retrieve Fingerprint sensor information */
7103#define EC_CMD_FP_INFO 0x0403
7104
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007105/* Number of dead pixels detected on the last maintenance */
7106#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007107/* Unknown number of dead pixels detected on the last maintenance */
7108#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007109/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007110#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007111/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007112#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007113/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007114#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007115/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007116#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007117
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007118struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007119 /* Sensor identification */
7120 uint32_t vendor_id;
7121 uint32_t product_id;
7122 uint32_t model_id;
7123 uint32_t version;
7124 /* Image frame characteristics */
7125 uint32_t frame_size;
7126 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7127 uint16_t width;
7128 uint16_t height;
7129 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007130 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007131} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007132
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007133struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007134 /* Sensor identification */
7135 uint32_t vendor_id;
7136 uint32_t product_id;
7137 uint32_t model_id;
7138 uint32_t version;
7139 /* Image frame characteristics */
7140 uint32_t frame_size;
7141 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7142 uint16_t width;
7143 uint16_t height;
7144 uint16_t bpp;
7145 uint16_t errors; /* see FP_ERROR_ flags above */
7146 /* Template/finger current information */
7147 uint32_t template_size; /* max template size in bytes */
7148 uint16_t template_max; /* maximum number of fingers/templates */
7149 uint16_t template_valid; /* number of valid fingers/templates */
7150 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007151 uint32_t template_version; /* version of the template format */
7152} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007153
7154/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007155#define EC_CMD_FP_FRAME 0x0404
7156
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007157/* constants defining the 'offset' field which also contains the frame index */
7158#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007159/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007160#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007161/* First frame buffer holding a template */
7162#define FP_FRAME_INDEX_TEMPLATE 1
7163#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007164#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
7165
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007166/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007167#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007168
7169/* Constants for encryption parameters */
7170#define FP_CONTEXT_NONCE_BYTES 12
7171#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7172#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007173#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007174#define FP_CONTEXT_TPM_BYTES 32
7175
Jett Rinkba2edaf2020-01-14 11:49:06 -07007176/* Constants for positive match parameters. */
7177#define FP_POSITIVE_MATCH_SALT_BYTES 16
7178
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007179struct ec_fp_template_encryption_metadata {
7180 /*
7181 * Version of the structure format (N=3).
7182 */
7183 uint16_t struct_version;
7184 /* Reserved bytes, set to 0. */
7185 uint16_t reserved;
7186 /*
7187 * The salt is *only* ever used for key derivation. The nonce is unique,
7188 * a different one is used for every message.
7189 */
7190 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007191 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007192 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7193};
7194
7195struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007196 /*
7197 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7198 * in the high nibble, and the real offset within the frame in
7199 * FP_FRAME_OFFSET_MASK.
7200 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007201 uint32_t offset;
7202 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007203} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007204
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007205/* Load a template into the MCU */
7206#define EC_CMD_FP_TEMPLATE 0x0405
7207
7208/* Flag in the 'size' field indicating that the full template has been sent */
7209#define FP_TEMPLATE_COMMIT 0x80000000
7210
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007211struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007212 uint32_t offset;
7213 uint32_t size;
7214 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007215} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007216
7217/* Clear the current fingerprint user context and set a new one */
7218#define EC_CMD_FP_CONTEXT 0x0406
7219
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007220struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007221 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007222} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007223
Jett Rinkba2edaf2020-01-14 11:49:06 -07007224enum fp_context_action {
7225 FP_CONTEXT_ASYNC = 0,
7226 FP_CONTEXT_GET_RESULT = 1,
7227};
7228
7229/* Version 1 of the command is "asynchronous". */
7230struct ec_params_fp_context_v1 {
7231 uint8_t action; /**< enum fp_context_action */
7232 uint8_t reserved[3]; /**< padding for alignment */
7233 uint32_t userid[FP_CONTEXT_USERID_WORDS];
7234} __ec_align4;
7235
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007236#define EC_CMD_FP_STATS 0x0407
7237
7238#define FPSTATS_CAPTURE_INV BIT(0)
7239#define FPSTATS_MATCHING_INV BIT(1)
7240
7241struct ec_response_fp_stats {
7242 uint32_t capture_time_us;
7243 uint32_t matching_time_us;
7244 uint32_t overall_time_us;
7245 struct {
7246 uint32_t lo;
7247 uint32_t hi;
7248 } overall_t0;
7249 uint8_t timestamps_invalid;
7250 int8_t template_matched;
7251} __ec_align2;
7252
7253#define EC_CMD_FP_SEED 0x0408
7254struct ec_params_fp_seed {
7255 /*
7256 * Version of the structure format (N=3).
7257 */
7258 uint16_t struct_version;
7259 /* Reserved bytes, set to 0. */
7260 uint16_t reserved;
7261 /* Seed from the TPM. */
7262 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7263} __ec_align4;
7264
7265#define EC_CMD_FP_ENC_STATUS 0x0409
7266
7267/* FP TPM seed has been set or not */
7268#define FP_ENC_STATUS_SEED_SET BIT(0)
7269
7270struct ec_response_fp_encryption_status {
7271 /* Used bits in encryption engine status */
7272 uint32_t valid_flags;
7273 /* Encryption engine status */
7274 uint32_t status;
7275} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007276
Jett Rinkba2edaf2020-01-14 11:49:06 -07007277#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7278struct ec_params_fp_read_match_secret {
7279 uint16_t fgr;
7280} __ec_align4;
7281
7282/* The positive match secret has the length of the SHA256 digest. */
7283#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7284struct ec_response_fp_read_match_secret {
7285 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7286} __ec_align4;
7287
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007288/*****************************************************************************/
7289/* Touchpad MCU commands: range 0x0500-0x05FF */
7290
7291/* Perform touchpad self test */
7292#define EC_CMD_TP_SELF_TEST 0x0500
7293
7294/* Get number of frame types, and the size of each type */
7295#define EC_CMD_TP_FRAME_INFO 0x0501
7296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007297struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007298 uint32_t n_frames;
7299 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007300} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007301
7302/* Create a snapshot of current frame readings */
7303#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7304
7305/* Read the frame */
7306#define EC_CMD_TP_FRAME_GET 0x0503
7307
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007308struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007309 uint32_t frame_index;
7310 uint32_t offset;
7311 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007312} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007313
7314/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007315/* EC-EC communication commands: range 0x0600-0x06FF */
7316
7317#define EC_COMM_TEXT_MAX 8
7318
7319/*
7320 * Get battery static information, i.e. information that never changes, or
7321 * very infrequently.
7322 */
7323#define EC_CMD_BATTERY_GET_STATIC 0x0600
7324
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007325/**
7326 * struct ec_params_battery_static_info - Battery static info parameters
7327 * @index: Battery index.
7328 */
7329struct ec_params_battery_static_info {
7330 uint8_t index;
7331} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007332
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007333/**
7334 * struct ec_response_battery_static_info - Battery static info response
7335 * @design_capacity: Battery Design Capacity (mAh)
7336 * @design_voltage: Battery Design Voltage (mV)
7337 * @manufacturer: Battery Manufacturer String
7338 * @model: Battery Model Number String
7339 * @serial: Battery Serial Number String
7340 * @type: Battery Type String
7341 * @cycle_count: Battery Cycle Count
7342 */
7343struct ec_response_battery_static_info {
7344 uint16_t design_capacity;
7345 uint16_t design_voltage;
7346 char manufacturer[EC_COMM_TEXT_MAX];
7347 char model[EC_COMM_TEXT_MAX];
7348 char serial[EC_COMM_TEXT_MAX];
7349 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007350 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007351 uint32_t cycle_count;
7352} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007353
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007354/**
7355 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7356 * Equivalent to struct ec_response_battery_static_info, but with longer
7357 * strings.
7358 * @design_capacity: battery design capacity (in mAh)
7359 * @design_voltage: battery design voltage (in mV)
7360 * @cycle_count: battery cycle count
7361 * @manufacturer_ext: battery manufacturer string
7362 * @model_ext: battery model string
7363 * @serial_ext: battery serial number string
7364 * @type_ext: battery type string
7365 */
7366struct ec_response_battery_static_info_v1 {
7367 uint16_t design_capacity;
7368 uint16_t design_voltage;
7369 uint32_t cycle_count;
7370 char manufacturer_ext[12];
7371 char model_ext[12];
7372 char serial_ext[12];
7373 char type_ext[12];
7374} __ec_align4;
7375
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007376/*
7377 * Get battery dynamic information, i.e. information that is likely to change
7378 * every time it is read.
7379 */
7380#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7381
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007382/**
7383 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7384 * @index: Battery index.
7385 */
7386struct ec_params_battery_dynamic_info {
7387 uint8_t index;
7388} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007389
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007390/**
7391 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7392 * @actual_voltage: Battery voltage (mV)
7393 * @actual_current: Battery current (mA); negative=discharging
7394 * @remaining_capacity: Remaining capacity (mAh)
7395 * @full_capacity: Capacity (mAh, might change occasionally)
7396 * @flags: Flags, see EC_BATT_FLAG_*
7397 * @desired_voltage: Charging voltage desired by battery (mV)
7398 * @desired_current: Charging current desired by battery (mA)
7399 */
7400struct ec_response_battery_dynamic_info {
7401 int16_t actual_voltage;
7402 int16_t actual_current;
7403 int16_t remaining_capacity;
7404 int16_t full_capacity;
7405 int16_t flags;
7406 int16_t desired_voltage;
7407 int16_t desired_current;
7408} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007409
7410/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007411 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007412 */
7413#define EC_CMD_CHARGER_CONTROL 0x0602
7414
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007415/**
7416 * struct ec_params_charger_control - Charger control parameters
7417 * @max_current: Charger current (mA). Positive to allow base to draw up to
7418 * max_current and (possibly) charge battery, negative to request current
7419 * from base (OTG).
7420 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7421 * >= 0.
7422 * @allow_charging: Allow base battery charging (only makes sense if
7423 * max_current > 0).
7424 */
7425struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007426 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007427 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007428 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007429} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007430
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007431/* Get ACK from the USB-C SS muxes */
7432#define EC_CMD_USB_PD_MUX_ACK 0x0603
7433
7434struct ec_params_usb_pd_mux_ack {
7435 uint8_t port; /* USB-C port number */
7436} __ec_align1;
7437
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007438/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007439/*
7440 * Reserve a range of host commands for board-specific, experimental, or
7441 * special purpose features. These can be (re)used without updating this file.
7442 *
7443 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7444 * their EC commands for easier development, testing, debugging, and support.
7445 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007446 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7447 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7448 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007449 * In your experimental code, you may want to do something like this:
7450 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007451 * #define EC_CMD_MAGIC_FOO 0x0000
7452 * #define EC_CMD_MAGIC_BAR 0x0001
7453 * #define EC_CMD_MAGIC_HEY 0x0002
7454 *
7455 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7456 * EC_VER_MASK(0);
7457 *
7458 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7459 * EC_VER_MASK(0);
7460 *
7461 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7462 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007463 */
7464#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7465#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7466
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007467/*
7468 * Given the private host command offset, calculate the true private host
7469 * command value.
7470 */
7471#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7472 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7473
Duncan Laurie93e24442014-01-06 12:30:52 -08007474/*****************************************************************************/
7475/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007476 * Passthru commands
7477 *
7478 * Some platforms have sub-processors chained to each other. For example.
7479 *
7480 * AP <--> EC <--> PD MCU
7481 *
7482 * The top 2 bits of the command number are used to indicate which device the
7483 * command is intended for. Device 0 is always the device receiving the
7484 * command; other device mapping is board-specific.
7485 *
7486 * When a device receives a command to be passed to a sub-processor, it passes
7487 * it on with the device number set back to 0. This allows the sub-processor
7488 * to remain blissfully unaware of whether the command originated on the next
7489 * device up the chain, or was passed through from the AP.
7490 *
7491 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7492 * AP sends command 0x4002 to the EC
7493 * EC sends command 0x0002 to the PD MCU
7494 * EC forwards PD MCU response back to the AP
7495 */
7496
7497/* Offset and max command number for sub-device n */
7498#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7499#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7500
7501/*****************************************************************************/
7502/*
Duncan Laurie93e24442014-01-06 12:30:52 -08007503 * Deprecated constants. These constants have been renamed for clarity. The
7504 * meaning and size has not changed. Programs that use the old names should
7505 * switch to the new names soon, as the old names may not be carried forward
7506 * forever.
7507 */
7508#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
7509#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
7510#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
7511
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007512#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007513
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007514#ifdef __cplusplus
7515}
7516#endif
7517
Duncan Laurieeb316852015-12-01 18:51:18 -08007518#endif /* __CROS_EC_EC_COMMANDS_H */