blob: 7ba35655a7f6ae6c0cf5a53a145c3126d2c2dfe2 [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
455/* Retimer firmware update operations */
456#define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
457#define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
458#define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
459#define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
460#define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
461#define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
462#define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
463#define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
464
465#define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x) & 0x0f)
466#define EC_ACPI_MEM_USB_RETIMER_OP(x) \
467 (((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
468
469/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700470 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
471 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
472 */
473#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
474#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
475
476/* Current version of ACPI memory address space */
477#define EC_ACPI_MEM_VERSION_CURRENT 2
478
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -0600479
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800480/*
481 * This header file is used in coreboot both in C and ACPI code. The ACPI code
482 * is pre-processed to handle constants but the ASL compiler is unable to
483 * handle actual C code so keep it separate.
484 */
485#ifndef __ACPI__
486
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800487#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800488/*
489 * Define __packed if someone hasn't beat us to it. Linux kernel style
490 * checking prefers __packed over __attribute__((packed)).
491 */
492#ifndef __packed
493#define __packed __attribute__((packed))
494#endif
495
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700496#ifndef __aligned
497#define __aligned(x) __attribute__((aligned(x)))
498#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800499#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700500
501/*
502 * Attributes for EC request and response packets. Just defining __packed
503 * results in inefficient assembly code on ARM, if the structure is actually
504 * 32-bit aligned, as it should be for all buffers.
505 *
506 * Be very careful when adding these to existing structures. They will round
507 * up the structure size to the specified boundary.
508 *
509 * Also be very careful to make that if a structure is included in some other
510 * parent structure that the alignment will still be true given the packing of
511 * the parent structure. This is particularly important if the sub-structure
512 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200513 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700514 *
515 * Also be very careful using __packed - particularly when nesting non-packed
516 * structures inside packed ones. In fact, DO NOT use __packed directly;
517 * always use one of these attributes.
518 *
519 * Once everything is annotated properly, the following search strings should
520 * not return ANY matches in this file other than right here:
521 *
522 * "__packed" - generates inefficient code; all sub-structs must also be packed
523 *
524 * "struct [^_]" - all structs should be annotated, except for structs that are
525 * members of other structs/unions (and their original declarations should be
526 * annotated).
527 */
528#ifdef CONFIG_HOSTCMD_ALIGNED
529
530/*
531 * Packed structures where offset and size are always aligned to 1, 2, or 4
532 * byte boundary.
533 */
534#define __ec_align1 __packed
535#define __ec_align2 __packed __aligned(2)
536#define __ec_align4 __packed __aligned(4)
537
538/*
539 * Packed structure which must be under-aligned, because its size is not a
540 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
541 * of all multi-byte fields in it, even though they are themselves aligned.
542 *
543 * In theory, we could duplicate the structure with __aligned(4) for accessing
544 * its members, but use the __packed version for sizeof().
545 */
546#define __ec_align_size1 __packed
547
548/*
549 * Packed structure which must be under-aligned, because its offset inside a
550 * parent structure is not a 4-byte multiple.
551 */
552#define __ec_align_offset1 __packed
553#define __ec_align_offset2 __packed __aligned(2)
554
555/*
556 * Structures which are complicated enough that I'm skipping them on the first
557 * pass. They are effectively unchanged from their previous definitions.
558 *
559 * TODO(rspangler): Figure out what to do with these. It's likely necessary
560 * to work out the size and offset of each member and add explicit padding to
561 * maintain those.
562 */
563#define __ec_todo_packed __packed
564#define __ec_todo_unpacked
565
566#else /* !CONFIG_HOSTCMD_ALIGNED */
567
568/*
569 * Packed structures make no assumption about alignment, so they do inefficient
570 * byte-wise reads.
571 */
572#define __ec_align1 __packed
573#define __ec_align2 __packed
574#define __ec_align4 __packed
575#define __ec_align_size1 __packed
576#define __ec_align_offset1 __packed
577#define __ec_align_offset2 __packed
578#define __ec_todo_packed __packed
579#define __ec_todo_unpacked
580
581#endif /* !CONFIG_HOSTCMD_ALIGNED */
582
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800583/* LPC command status byte masks */
584/* EC has written a byte in the data register and host hasn't read it yet */
585#define EC_LPC_STATUS_TO_HOST 0x01
586/* Host has written a command/data byte and the EC hasn't read it yet */
587#define EC_LPC_STATUS_FROM_HOST 0x02
588/* EC is processing a command */
589#define EC_LPC_STATUS_PROCESSING 0x04
590/* Last write to EC was a command, not data */
591#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700592/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800593#define EC_LPC_STATUS_BURST_MODE 0x10
594/* SCI event is pending (requesting SCI query) */
595#define EC_LPC_STATUS_SCI_PENDING 0x20
596/* SMI event is pending (requesting SMI query) */
597#define EC_LPC_STATUS_SMI_PENDING 0x40
598/* (reserved) */
599#define EC_LPC_STATUS_RESERVED 0x80
600
601/*
602 * EC is busy. This covers both the EC processing a command, and the host has
603 * written a new command but the EC hasn't picked it up yet.
604 */
605#define EC_LPC_STATUS_BUSY_MASK \
606 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
607
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800608/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700609 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700610 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800611enum ec_status {
612 EC_RES_SUCCESS = 0,
613 EC_RES_INVALID_COMMAND = 1,
614 EC_RES_ERROR = 2,
615 EC_RES_INVALID_PARAM = 3,
616 EC_RES_ACCESS_DENIED = 4,
617 EC_RES_INVALID_RESPONSE = 5,
618 EC_RES_INVALID_VERSION = 6,
619 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700620 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
621 EC_RES_UNAVAILABLE = 9, /* No response available */
622 EC_RES_TIMEOUT = 10, /* We got a timeout */
623 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800624 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
625 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700626 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700627 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600628 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
629 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
630 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
631 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
632 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700633
634 EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */
635} __packed;
636BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800637
638/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600639 * Host event codes. ACPI query EC command uses code 0 to mean "no event
640 * pending". We explicitly specify each value in the enum listing so they won't
641 * change if we delete/insert an item or rearrange the list (it needs to be
642 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800643 */
644enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600645 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800646 EC_HOST_EVENT_LID_CLOSED = 1,
647 EC_HOST_EVENT_LID_OPEN = 2,
648 EC_HOST_EVENT_POWER_BUTTON = 3,
649 EC_HOST_EVENT_AC_CONNECTED = 4,
650 EC_HOST_EVENT_AC_DISCONNECTED = 5,
651 EC_HOST_EVENT_BATTERY_LOW = 6,
652 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
653 EC_HOST_EVENT_BATTERY = 8,
654 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700655 /* Event generated by a device attached to the EC */
656 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800657 EC_HOST_EVENT_THERMAL = 11,
658 EC_HOST_EVENT_USB_CHARGER = 12,
659 EC_HOST_EVENT_KEY_PRESSED = 13,
660 /*
661 * EC has finished initializing the host interface. The host can check
662 * for this event following sending a EC_CMD_REBOOT_EC command to
663 * determine when the EC is ready to accept subsequent commands.
664 */
665 EC_HOST_EVENT_INTERFACE_READY = 14,
666 /* Keyboard recovery combo has been pressed */
667 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
668
669 /* Shutdown due to thermal overload */
670 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
671 /* Shutdown due to battery level too low */
672 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
673
Duncan Laurie93e24442014-01-06 12:30:52 -0800674 /* Suggest that the AP throttle itself */
675 EC_HOST_EVENT_THROTTLE_START = 18,
676 /* Suggest that the AP resume normal speed */
677 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700678
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800679 /* Hang detect logic detected a hang and host event timeout expired */
680 EC_HOST_EVENT_HANG_DETECT = 20,
681 /* Hang detect logic detected a hang and warm rebooted the AP */
682 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700683
684 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700685 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800686
Duncan Lauried8401182014-09-29 08:32:19 -0700687 /* Battery Status flags have changed */
688 EC_HOST_EVENT_BATTERY_STATUS = 23,
689
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700690 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800691 EC_HOST_EVENT_PANIC = 24,
692
Furquan Shaikh066cc852015-06-20 15:53:03 -0700693 /* Keyboard fastboot combo has been pressed */
694 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
695
Gwendal Grignou880b4582016-06-20 08:49:25 -0700696 /* EC RTC event occurred */
697 EC_HOST_EVENT_RTC = 26,
698
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700699 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700700 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700701
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700702 /* EC desires to change state of host-controlled USB mux */
703 EC_HOST_EVENT_USB_MUX = 28,
704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800705 /*
706 * The device has changed "modes". This can be one of the following:
707 *
708 * - TABLET/LAPTOP mode
709 * - detachable base attach/detach event
710 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400711 EC_HOST_EVENT_MODE_CHANGE = 29,
712
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700713 /* Keyboard recovery combo with hardware reinitialization */
714 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
715
Jett Rinkba2edaf2020-01-14 11:49:06 -0700716 /* WoV */
717 EC_HOST_EVENT_WOV = 31,
718
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700719 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800720 * The high bit of the event mask is not used as a host event code. If
721 * it reads back as set, then the entire event mask should be
722 * considered invalid by the host. This can happen when reading the
723 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
724 * not initialized on the EC, or improperly configured on the host.
725 */
726 EC_HOST_EVENT_INVALID = 32
727};
728/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800729#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800731/**
732 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
733 * @flags: The host argument flags.
734 * @command_version: Command version.
735 * @data_size: The length of data.
736 * @checksum: Checksum; sum of command + flags + command_version + data_size +
737 * all params/response data bytes.
738 */
739struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800740 uint8_t flags;
741 uint8_t command_version;
742 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800743 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800744} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800745
746/* Flags for ec_lpc_host_args.flags */
747/*
748 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
749 * params.
750 *
751 * If EC gets a command and this flag is not set, this is an old-style command.
752 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
753 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700754 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800755 */
756#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
757/*
758 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
759 *
760 * If EC responds to a command and this flag is not set, this is an old-style
761 * response. Command version is 0 and response data from EC is at
762 * EC_LPC_ADDR_OLD_PARAM with unknown length.
763 */
764#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
765
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800766/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800767/*
768 * Byte codes returned by EC over SPI interface.
769 *
770 * These can be used by the AP to debug the EC interface, and to determine
771 * when the EC is not in a state where it will ever get around to responding
772 * to the AP.
773 *
774 * Example of sequence of bytes read from EC for a current good transfer:
775 * 1. - - AP asserts chip select (CS#)
776 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
777 * 3. - - EC starts handling CS# interrupt
778 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
779 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
780 * bytes looking for EC_SPI_FRAME_START
781 * 6. - - EC finishes processing and sets up response
782 * 7. EC_SPI_FRAME_START - AP reads frame byte
783 * 8. (response packet) - AP reads response packet
784 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
785 * 10 - - AP deasserts chip select
786 * 11 - - EC processes CS# interrupt and sets up DMA for
787 * next request
788 *
789 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
790 * the following byte values:
791 * EC_SPI_OLD_READY
792 * EC_SPI_RX_READY
793 * EC_SPI_RECEIVING
794 * EC_SPI_PROCESSING
795 *
796 * Then the EC found an error in the request, or was not ready for the request
797 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
798 * because the EC is unable to tell when the AP is done sending its request.
799 */
800
801/*
802 * Framing byte which precedes a response packet from the EC. After sending a
803 * request, the AP will clock in bytes until it sees the framing byte, then
804 * clock in the response packet.
805 */
806#define EC_SPI_FRAME_START 0xec
807
808/*
809 * Padding bytes which are clocked out after the end of a response packet.
810 */
811#define EC_SPI_PAST_END 0xed
812
813/*
814 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
815 * that the AP will send a valid packet header (starting with
816 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
817 */
818#define EC_SPI_RX_READY 0xf8
819
820/*
821 * EC has started receiving the request from the AP, but hasn't started
822 * processing it yet.
823 */
824#define EC_SPI_RECEIVING 0xf9
825
826/* EC has received the entire request from the AP and is processing it. */
827#define EC_SPI_PROCESSING 0xfa
828
829/*
830 * EC received bad data from the AP, such as a packet header with an invalid
831 * length. EC will ignore all data until chip select deasserts.
832 */
833#define EC_SPI_RX_BAD_DATA 0xfb
834
835/*
836 * EC received data from the AP before it was ready. That is, the AP asserted
837 * chip select and started clocking data before the EC was ready to receive it.
838 * EC will ignore all data until chip select deasserts.
839 */
840#define EC_SPI_NOT_READY 0xfc
841
842/*
843 * EC was ready to receive a request from the AP. EC has treated the byte sent
844 * by the AP as part of a request packet, or (for old-style ECs) is processing
845 * a fully received packet but is not ready to respond yet.
846 */
847#define EC_SPI_OLD_READY 0xfd
848
849/*****************************************************************************/
850
851/*
852 * Protocol version 2 for I2C and SPI send a request this way:
853 *
854 * 0 EC_CMD_VERSION0 + (command version)
855 * 1 Command number
856 * 2 Length of params = N
857 * 3..N+2 Params, if any
858 * N+3 8-bit checksum of bytes 0..N+2
859 *
860 * The corresponding response is:
861 *
862 * 0 Result code (EC_RES_*)
863 * 1 Length of params = M
864 * 2..M+1 Params, if any
865 * M+2 8-bit checksum of bytes 0..M+1
866 */
867#define EC_PROTO2_REQUEST_HEADER_BYTES 3
868#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
869#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
870 EC_PROTO2_REQUEST_TRAILER_BYTES)
871
872#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
873#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
874#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
875 EC_PROTO2_RESPONSE_TRAILER_BYTES)
876
877/* Parameter length was limited by the LPC interface */
878#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
879
880/* Maximum request and response packet sizes for protocol version 2 */
881#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
882 EC_PROTO2_MAX_PARAM_SIZE)
883#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
884 EC_PROTO2_MAX_PARAM_SIZE)
885
886/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800887
888/*
889 * Value written to legacy command port / prefix byte to indicate protocol
890 * 3+ structs are being used. Usage is bus-dependent.
891 */
892#define EC_COMMAND_PROTOCOL_3 0xda
893
894#define EC_HOST_REQUEST_VERSION 3
895
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800896/**
897 * struct ec_host_request - Version 3 request from host.
898 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
899 * receives a header with a version it doesn't know how to
900 * parse.
901 * @checksum: Checksum of request and data; sum of all bytes including checksum
902 * should total to 0.
903 * @command: Command to send (EC_CMD_...)
904 * @command_version: Command version.
905 * @reserved: Unused byte in current protocol version; set to 0.
906 * @data_len: Length of data which follows this header.
907 */
908struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800909 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800910 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800911 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800912 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800913 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800914 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800915} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800916
917#define EC_HOST_RESPONSE_VERSION 3
918
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800919/**
920 * struct ec_host_response - Version 3 response from EC.
921 * @struct_version: Struct version (=3).
922 * @checksum: Checksum of response and data; sum of all bytes including
923 * checksum should total to 0.
924 * @result: EC's response to the command (separate from communication failure)
925 * @data_len: Length of data which follows this header.
926 * @reserved: Unused bytes in current protocol version; set to 0.
927 */
928struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800929 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800930 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800931 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800932 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800933 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800934} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800935
936/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600937
938/*
939 * Host command protocol V4.
940 *
941 * Packets always start with a request or response header. They are followed
942 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +0100943 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600944 * polynomial.
945 *
946 * Host algorithm when sending a request q:
947 *
948 * 101) tries_left=(some value, e.g. 3);
949 * 102) q.seq_num++
950 * 103) q.seq_dup=0
951 * 104) Calculate q.header_crc.
952 * 105) Send request q to EC.
953 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
954 *
955 * 201) If r.struct_version != 4, go to 301.
956 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
957 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
958 * 204) If r.seq_num != q.seq_num, go to 301.
959 * 205) If r.seq_dup == q.seq_dup, return success.
960 * 207) If r.seq_dup == 1, go to 301.
961 * 208) Return error.
962 *
963 * 301) If --tries_left <= 0, return error.
964 * 302) If q.seq_dup == 1, go to 105.
965 * 303) q.seq_dup = 1
966 * 304) Go to 104.
967 *
968 * EC algorithm when receiving a request q.
969 * EC has response buffer r, error buffer e.
970 *
971 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
972 * and go to 301
973 * 102) If q.header_crc mismatches calculated CRC, set e.result =
974 * EC_RES_INVALID_HEADER_CRC and go to 301
975 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
976 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
977 * and go to 301.
978 * 104) If q.seq_dup == 0, go to 201.
979 * 105) If q.seq_num != r.seq_num, go to 201.
980 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
981 *
982 * 201) Process request q into response r.
983 * 202) r.seq_num = q.seq_num
984 * 203) r.seq_dup = q.seq_dup
985 * 204) Calculate r.header_crc
986 * 205) If r.data_len > 0 and data is no longer available, set e.result =
987 * EC_RES_DUP_UNAVAILABLE and go to 301.
988 * 206) Send response r.
989 *
990 * 301) e.seq_num = q.seq_num
991 * 302) e.seq_dup = q.seq_dup
992 * 303) Calculate e.header_crc.
993 * 304) Send error response e.
994 */
995
996/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800997struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600998 /*
999 * bits 0-3: struct_version: Structure version (=4)
1000 * bit 4: is_response: Is response (=0)
1001 * bits 5-6: seq_num: Sequence number
1002 * bit 7: seq_dup: Sequence duplicate flag
1003 */
1004 uint8_t fields0;
1005
1006 /*
1007 * bits 0-4: command_version: Command version
1008 * bits 5-6: Reserved (set 0, ignore on read)
1009 * bit 7: data_crc_present: Is data CRC present after data
1010 */
1011 uint8_t fields1;
1012
1013 /* Command code (EC_CMD_*) */
1014 uint16_t command;
1015
1016 /* Length of data which follows this header (not including data CRC) */
1017 uint16_t data_len;
1018
1019 /* Reserved (set 0, ignore on read) */
1020 uint8_t reserved;
1021
1022 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1023 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001024} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001025
1026/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001027struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001028 /*
1029 * bits 0-3: struct_version: Structure version (=4)
1030 * bit 4: is_response: Is response (=1)
1031 * bits 5-6: seq_num: Sequence number
1032 * bit 7: seq_dup: Sequence duplicate flag
1033 */
1034 uint8_t fields0;
1035
1036 /*
1037 * bits 0-6: Reserved (set 0, ignore on read)
1038 * bit 7: data_crc_present: Is data CRC present after data
1039 */
1040 uint8_t fields1;
1041
1042 /* Result code (EC_RES_*) */
1043 uint16_t result;
1044
1045 /* Length of data which follows this header (not including data CRC) */
1046 uint16_t data_len;
1047
1048 /* Reserved (set 0, ignore on read) */
1049 uint8_t reserved;
1050
1051 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1052 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001053} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001054
1055/* Fields in fields0 byte */
1056#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1057#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1058#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1059#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1060#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1061
1062/* Fields in fields1 byte */
1063#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1064#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1065
1066/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001067/*
1068 * Notes on commands:
1069 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001070 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001071 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001072 * specified, the command does not input or output data, respectively.
1073 * Parameter/response length is implicit in the structs. Some underlying
1074 * communication protocols (I2C, SPI) may add length or checksum headers, but
1075 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001076 *
1077 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1078 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001079 */
1080
1081/*****************************************************************************/
1082/* General / test commands */
1083
1084/*
1085 * Get protocol version, used to deal with non-backward compatible protocol
1086 * changes.
1087 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001088#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001089
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001090/**
1091 * struct ec_response_proto_version - Response to the proto version command.
1092 * @version: The protocol version.
1093 */
1094struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001095 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001096} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001097
1098/*
1099 * Hello. This is a simple command to test the EC is responsive to
1100 * commands.
1101 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001102#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001103
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001104/**
1105 * struct ec_params_hello - Parameters to the hello command.
1106 * @in_data: Pass anything here.
1107 */
1108struct ec_params_hello {
1109 uint32_t in_data;
1110} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001111
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001112/**
1113 * struct ec_response_hello - Response to the hello command.
1114 * @out_data: Output will be in_data + 0x01020304.
1115 */
1116struct ec_response_hello {
1117 uint32_t out_data;
1118} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001119
1120/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001121#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001122
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001123#if !defined(CHROMIUM_EC) && !defined(__KERNEL__)
1124/*
1125 * enum ec_current_image is deprecated and replaced by enum ec_image. This
1126 * macro exists for backwards compatibility of external projects until they
1127 * have been updated: b/149987779.
1128 */
1129#define ec_current_image ec_image
1130#endif
1131
1132enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001133 EC_IMAGE_UNKNOWN = 0,
1134 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001135 EC_IMAGE_RW,
1136 EC_IMAGE_RW_A = EC_IMAGE_RW,
1137 EC_IMAGE_RO_B,
1138 EC_IMAGE_RW_B
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001139};
1140
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001141/**
1142 * struct ec_response_get_version - Response to the get version command.
1143 * @version_string_ro: Null-terminated RO firmware version string.
1144 * @version_string_rw: Null-terminated RW firmware version string.
1145 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001146 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001147 */
1148struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001149 char version_string_ro[32];
1150 char version_string_rw[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001151 char reserved[32];
1152 uint32_t current_image;
1153} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001154
1155/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001156#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001157
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001158/**
1159 * struct ec_params_read_test - Parameters for the read test command.
1160 * @offset: Starting value for read buffer.
1161 * @size: Size to read in bytes.
1162 */
1163struct ec_params_read_test {
1164 uint32_t offset;
1165 uint32_t size;
1166} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001167
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001168/**
1169 * struct ec_response_read_test - Response to the read test command.
1170 * @data: Data returned by the read test command.
1171 */
1172struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001173 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001174} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001175
1176/*
1177 * Get build information
1178 *
1179 * Response is null-terminated string.
1180 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001181#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001182
1183/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001184#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001185
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001186/**
1187 * struct ec_response_get_chip_info - Response to the get chip info command.
1188 * @vendor: Null-terminated string for chip vendor.
1189 * @name: Null-terminated string for chip name.
1190 * @revision: Null-terminated string for chip mask version.
1191 */
1192struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001193 char vendor[32];
1194 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001195 char revision[32];
1196} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001197
1198/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001199#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001200
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001201/**
1202 * struct ec_response_board_version - Response to the board version command.
1203 * @board_version: A monotonously incrementing number.
1204 */
1205struct ec_response_board_version {
1206 uint16_t board_version;
1207} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001208
1209/*
1210 * Read memory-mapped data.
1211 *
1212 * This is an alternate interface to memory-mapped data for bus protocols
1213 * which don't support direct-mapped memory - I2C, SPI, etc.
1214 *
1215 * Response is params.size bytes of data.
1216 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001217#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001218
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001219/**
1220 * struct ec_params_read_memmap - Parameters for the read memory map command.
1221 * @offset: Offset in memmap (EC_MEMMAP_*).
1222 * @size: Size to read in bytes.
1223 */
1224struct ec_params_read_memmap {
1225 uint8_t offset;
1226 uint8_t size;
1227} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001228
1229/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001230#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001231
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001232/**
1233 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1234 * @cmd: Command to check.
1235 */
1236struct ec_params_get_cmd_versions {
1237 uint8_t cmd;
1238} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001239
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001240/**
1241 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1242 * versions (v1)
1243 * @cmd: Command to check.
1244 */
1245struct ec_params_get_cmd_versions_v1 {
1246 uint16_t cmd;
1247} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001248
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001249/**
1250 * struct ec_response_get_cmd_version - Response to the get command versions.
1251 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1252 * a desired version.
1253 */
1254struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001255 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001256} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001257
Duncan Laurie433432b2013-06-03 10:38:22 -07001258/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001259 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001260 * on lpc since it has its own out-of-band busy indicator.
1261 *
1262 * lpc must read the status from the command register. Attempting this on
1263 * lpc will overwrite the args/parameter space and corrupt its data.
1264 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001265#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001266
1267/* Avoid using ec_status which is for return values */
1268enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001269 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001270};
1271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001272/**
1273 * struct ec_response_get_comms_status - Response to the get comms status
1274 * command.
1275 * @flags: Mask of enum ec_comms_status.
1276 */
1277struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001278 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001279} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001280
Duncan Laurie93e24442014-01-06 12:30:52 -08001281/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001282#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001283
1284/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001285struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001286 uint32_t ec_result;
1287 uint32_t ret_len;
1288 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001289} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001290
1291/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001292struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001293 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001294} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001295
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001296/* Get protocol information */
1297#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001298
1299/* Flags for ec_response_get_protocol_info.flags */
1300/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001301#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001302
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001303/**
1304 * struct ec_response_get_protocol_info - Response to the get protocol info.
1305 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1306 * version n).
1307 * @max_request_packet_size: Maximum request packet size in bytes.
1308 * @max_response_packet_size: Maximum response packet size in bytes.
1309 * @flags: see EC_PROTOCOL_INFO_*
1310 */
1311struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001312 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001313 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001314 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001315 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001316 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001317} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001318
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001319
Duncan Laurie93e24442014-01-06 12:30:52 -08001320/*****************************************************************************/
1321/* Get/Set miscellaneous values */
1322
1323/* The upper byte of .flags tells what to do (nothing means "get") */
1324#define EC_GSV_SET 0x80000000
1325
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001326/*
1327 * The lower three bytes of .flags identifies the parameter, if that has
1328 * meaning for an individual command.
1329 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001330#define EC_GSV_PARAM_MASK 0x00ffffff
1331
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001332struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001333 uint32_t flags;
1334 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001335} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001336
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001337struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001338 uint32_t flags;
1339 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001340} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001341
Duncan Laurieeb316852015-12-01 18:51:18 -08001342/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001343#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001344
Duncan Laurieeb316852015-12-01 18:51:18 -08001345/*****************************************************************************/
1346/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001347#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001348
1349/* Supported features */
1350enum ec_feature_code {
1351 /*
1352 * This image contains a limited set of features. Another image
1353 * in RW partition may support more features.
1354 */
1355 EC_FEATURE_LIMITED = 0,
1356 /*
1357 * Commands for probing/reading/writing/erasing the flash in the
1358 * EC are present.
1359 */
1360 EC_FEATURE_FLASH = 1,
1361 /*
1362 * Can control the fan speed directly.
1363 */
1364 EC_FEATURE_PWM_FAN = 2,
1365 /*
1366 * Can control the intensity of the keyboard backlight.
1367 */
1368 EC_FEATURE_PWM_KEYB = 3,
1369 /*
1370 * Support Google lightbar, introduced on Pixel.
1371 */
1372 EC_FEATURE_LIGHTBAR = 4,
1373 /* Control of LEDs */
1374 EC_FEATURE_LED = 5,
1375 /* Exposes an interface to control gyro and sensors.
1376 * The host goes through the EC to access these sensors.
1377 * In addition, the EC may provide composite sensors, like lid angle.
1378 */
1379 EC_FEATURE_MOTION_SENSE = 6,
1380 /* The keyboard is controlled by the EC */
1381 EC_FEATURE_KEYB = 7,
1382 /* The AP can use part of the EC flash as persistent storage. */
1383 EC_FEATURE_PSTORE = 8,
1384 /* The EC monitors BIOS port 80h, and can return POST codes. */
1385 EC_FEATURE_PORT80 = 9,
1386 /*
1387 * Thermal management: include TMP specific commands.
1388 * Higher level than direct fan control.
1389 */
1390 EC_FEATURE_THERMAL = 10,
1391 /* Can switch the screen backlight on/off */
1392 EC_FEATURE_BKLIGHT_SWITCH = 11,
1393 /* Can switch the wifi module on/off */
1394 EC_FEATURE_WIFI_SWITCH = 12,
1395 /* Monitor host events, through for example SMI or SCI */
1396 EC_FEATURE_HOST_EVENTS = 13,
1397 /* The EC exposes GPIO commands to control/monitor connected devices. */
1398 EC_FEATURE_GPIO = 14,
1399 /* The EC can send i2c messages to downstream devices. */
1400 EC_FEATURE_I2C = 15,
1401 /* Command to control charger are included */
1402 EC_FEATURE_CHARGER = 16,
1403 /* Simple battery support. */
1404 EC_FEATURE_BATTERY = 17,
1405 /*
1406 * Support Smart battery protocol
1407 * (Common Smart Battery System Interface Specification)
1408 */
1409 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001410 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001411 EC_FEATURE_HANG_DETECT = 19,
1412 /* Report power information, for pit only */
1413 EC_FEATURE_PMU = 20,
1414 /* Another Cros EC device is present downstream of this one */
1415 EC_FEATURE_SUB_MCU = 21,
1416 /* Support USB Power delivery (PD) commands */
1417 EC_FEATURE_USB_PD = 22,
1418 /* Control USB multiplexer, for audio through USB port for instance. */
1419 EC_FEATURE_USB_MUX = 23,
1420 /* Motion Sensor code has an internal software FIFO */
1421 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1422 /* Support temporary secure vstore */
1423 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001424 /* EC decides on USB-C SS mux state, muxes configured by host */
1425 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1426 /* EC has RTC feature that can be controlled by host commands */
1427 EC_FEATURE_RTC = 27,
1428 /* The MCU exposes a Fingerprint sensor */
1429 EC_FEATURE_FINGERPRINT = 28,
1430 /* The MCU exposes a Touchpad */
1431 EC_FEATURE_TOUCHPAD = 29,
1432 /* The MCU has RWSIG task enabled */
1433 EC_FEATURE_RWSIG = 30,
1434 /* EC has device events support */
1435 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001436 /* EC supports the unified wake masks for LPC/eSPI systems */
1437 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001438 /* EC supports 64-bit host events */
1439 EC_FEATURE_HOST_EVENT64 = 33,
1440 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1441 EC_FEATURE_EXEC_IN_RAM = 34,
1442 /* EC supports CEC commands */
1443 EC_FEATURE_CEC = 35,
1444 /* EC supports tight sensor timestamping. */
1445 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001446 /*
1447 * EC supports tablet mode detection aligned to Chrome and allows
1448 * setting of threshold by host command using
1449 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1450 */
1451 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001452 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001453 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001454 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1455 * be sent to RO to be precise.
1456 */
1457 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001458 /* The MCU is a System Companion Processor (SCP). */
1459 EC_FEATURE_SCP = 39,
1460 /* The MCU is an Integrated Sensor Hub */
1461 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001462 /* New TCPMv2 TYPEC_ prefaced commands supported */
1463 EC_FEATURE_TYPEC_CMD = 41,
1464 /*
1465 * The EC will wait for direction from the AP to enter Type-C alternate
1466 * modes or USB4.
1467 */
1468 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1469 /*
1470 * The EC will wait for an acknowledge from the AP after setting the
1471 * mux.
1472 */
1473 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Duncan Laurieeb316852015-12-01 18:51:18 -08001474};
1475
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001476#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1477#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1478
1479struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001480 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001481} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001482
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001483/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001484/* Get the board's SKU ID from EC */
1485#define EC_CMD_GET_SKU_ID 0x000E
1486
Kevin Chiue2bb0592017-09-12 09:13:41 +08001487/* Set SKU ID from AP */
1488#define EC_CMD_SET_SKU_ID 0x000F
1489
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001490struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001491 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001492} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001493
1494/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001495/* Flash commands */
1496
1497/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001498#define EC_CMD_FLASH_INFO 0x0010
1499#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001500
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001501/**
1502 * struct ec_response_flash_info - Response to the flash info command.
1503 * @flash_size: Usable flash size in bytes.
1504 * @write_block_size: Write block size. Write offset and size must be a
1505 * multiple of this.
1506 * @erase_block_size: Erase block size. Erase offset and size must be a
1507 * multiple of this.
1508 * @protect_block_size: Protection block size. Protection offset and size
1509 * must be a multiple of this.
1510 *
1511 * Version 0 returns these fields.
1512 */
1513struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001514 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001515 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001516 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001517 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001518} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001519
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001520/*
1521 * Flags for version 1+ flash info command
1522 * EC flash erases bits to 0 instead of 1.
1523 */
1524#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001525
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001526/*
1527 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001528 * be necessary on a chip where write/erase can be corrupted by other board
1529 * activity, or where the chip needs to enable some sort of programming voltage,
1530 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001531 * chip functionality.
1532 */
1533#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001534
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001535/**
1536 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1537 * @flash_size: Usable flash size in bytes.
1538 * @write_block_size: Write block size. Write offset and size must be a
1539 * multiple of this.
1540 * @erase_block_size: Erase block size. Erase offset and size must be a
1541 * multiple of this.
1542 * @protect_block_size: Protection block size. Protection offset and size
1543 * must be a multiple of this.
1544 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1545 * size is exactly this and offset is a multiple of this.
1546 * For example, an EC may have a write buffer which can do
1547 * half-page operations if data is aligned, and a slower
1548 * word-at-a-time write mode.
1549 * @flags: Flags; see EC_FLASH_INFO_*
1550 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001551 * Version 1 returns the same initial fields as version 0, with additional
1552 * fields following.
1553 *
1554 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001555 * if they did we'd define the version 0 structure as a sub-structure of this
1556 * one.
1557 *
1558 * Version 2 supports flash banks of different sizes:
1559 * The caller specified the number of banks it has preallocated
1560 * (num_banks_desc)
1561 * The EC returns the number of banks describing the flash memory.
1562 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001563 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001564struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001565 /* Version 0 fields; see above for description */
1566 uint32_t flash_size;
1567 uint32_t write_block_size;
1568 uint32_t erase_block_size;
1569 uint32_t protect_block_size;
1570
1571 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001572 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001573 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001574} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001575
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001576struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001577 /* Number of banks to describe */
1578 uint16_t num_banks_desc;
1579 /* Reserved; set 0; ignore on read */
1580 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001581} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001582
1583struct ec_flash_bank {
1584 /* Number of sector is in this bank. */
1585 uint16_t count;
1586 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1587 uint8_t size_exp;
1588 /* Minimal write size for the sectors in this bank */
1589 uint8_t write_size_exp;
1590 /* Erase size for the sectors in this bank */
1591 uint8_t erase_size_exp;
1592 /* Size for write protection, usually identical to erase size. */
1593 uint8_t protect_size_exp;
1594 /* Reserved; set 0; ignore on read */
1595 uint8_t reserved[2];
1596};
1597
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001598struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001599 /* Total flash in the EC. */
1600 uint32_t flash_size;
1601 /* Flags; see EC_FLASH_INFO_* */
1602 uint32_t flags;
1603 /* Maximum size to use to send data to write to the EC. */
1604 uint32_t write_ideal_size;
1605 /* Number of banks present in the EC. */
1606 uint16_t num_banks_total;
1607 /* Number of banks described in banks array. */
1608 uint16_t num_banks_desc;
1609 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001610} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001611
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001612/*
1613 * Read flash
1614 *
1615 * Response is params.size bytes of data.
1616 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001617#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001618
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001619/**
1620 * struct ec_params_flash_read - Parameters for the flash read command.
1621 * @offset: Byte offset to read.
1622 * @size: Size to read in bytes.
1623 */
1624struct ec_params_flash_read {
1625 uint32_t offset;
1626 uint32_t size;
1627} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001628
1629/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001630#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001631#define EC_VER_FLASH_WRITE 1
1632
1633/* Version 0 of the flash command supported only 64 bytes of data */
1634#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001635
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001636/**
1637 * struct ec_params_flash_write - Parameters for the flash write command.
1638 * @offset: Byte offset to write.
1639 * @size: Size to write in bytes.
1640 */
1641struct ec_params_flash_write {
1642 uint32_t offset;
1643 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001644 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001645} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001646
1647/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001648#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001649
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001650/**
1651 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1652 * @offset: Byte offset to erase.
1653 * @size: Size to erase in bytes.
1654 */
1655struct ec_params_flash_erase {
1656 uint32_t offset;
1657 uint32_t size;
1658} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001659
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001660/*
1661 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001662 * subcommands can returns:
1663 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1664 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1665 * EC_RES_ERROR : other errors.
1666 * EC_RES_BUSY : an existing erase operation is in progress.
1667 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1668 *
1669 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1670 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1671 * the proper result.
1672 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1673 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1674 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1675 * permitted while erasing. (For instance, STM32F4).
1676 */
1677enum ec_flash_erase_cmd {
1678 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1679 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1680 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1681};
1682
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001683/**
1684 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1685 * @cmd: One of ec_flash_erase_cmd.
1686 * @reserved: Pad byte; currently always contains 0.
1687 * @flag: No flags defined yet; set to 0.
1688 * @params: Same as v0 parameters.
1689 */
1690struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001691 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001692 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001693 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001694 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001695} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001696
1697/*
1698 * Get/set flash protection.
1699 *
1700 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1701 * firmware write protect GPIO, not all flags will take effect immediately;
1702 * some flags require a subsequent hard reset to take effect. Check the
1703 * returned flags bits to see what actually happened.
1704 *
1705 * If mask=0, simply returns the current flags state.
1706 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001707#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001708#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1709
1710/* Flags for flash protection */
1711/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001712#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001713/*
1714 * RO flash code protected now. If this bit is set, at-boot status cannot
1715 * be changed.
1716 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001717#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001718/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001719#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001720/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001721#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001722/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001723#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001724/*
1725 * Error - flash protection is in inconsistent state. At least one bank of
1726 * flash which should be protected is not protected. Usually fixed by
1727 * re-requesting the desired flags, or by a hard reset if that fails.
1728 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001729#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001730/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001731#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001732/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001733#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001734/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001735#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001736/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001737#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001738/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001739#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001740
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001741
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001742/**
1743 * struct ec_params_flash_protect - Parameters for the flash protect command.
1744 * @mask: Bits in flags to apply.
1745 * @flags: New flags to apply.
1746 */
1747struct ec_params_flash_protect {
1748 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001749 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001750} __ec_align4;
1751
1752/**
1753 * struct ec_response_flash_protect - Response to the flash protect command.
1754 * @flags: Current value of flash protect flags.
1755 * @valid_flags: Flags which are valid on this platform. This allows the
1756 * caller to distinguish between flags which aren't set vs. flags
1757 * which can't be set on this platform.
1758 * @writable_flags: Flags which can be changed given the current protection
1759 * state.
1760 */
1761struct ec_response_flash_protect {
1762 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001763 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001764 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001765} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001766
1767/*
1768 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1769 * write protect. These commands may be reused with version > 0.
1770 */
1771
1772/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001773#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001774#define EC_VER_FLASH_REGION_INFO 1
1775
1776enum ec_flash_region {
1777 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001778 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001779 /*
1780 * Region which holds active RW image. 'Active' is different from
1781 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1782 * scheduled to run, active/non-active applies only to RW images (for
1783 * the same reason 'update' applies only to RW images. It's a state of
1784 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1785 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1786 * doesn't enter 'running' state but it's still active on a flash.
1787 */
1788 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001789 /*
1790 * Region which should be write-protected in the factory (a superset of
1791 * EC_FLASH_REGION_RO)
1792 */
1793 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001794 /* Region which holds updatable (non-active) RW image */
1795 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001796 /* Number of regions */
1797 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001798};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001799/*
1800 * 'RW' is vague if there are multiple RW images; we mean the active one,
1801 * so the old constant is deprecated.
1802 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001803#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001804
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001805/**
1806 * struct ec_params_flash_region_info - Parameters for the flash region info
1807 * command.
1808 * @region: Flash region; see EC_FLASH_REGION_*
1809 */
1810struct ec_params_flash_region_info {
1811 uint32_t region;
1812} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001813
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001814struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001815 uint32_t offset;
1816 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001817} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001818
Rob Barnes8bc5fa92021-06-28 09:32:28 -06001819/*
1820 * Read/write VbNvContext
1821 *
1822 * Deprecated as of February 2021. No current devices use VBNV in EC
1823 * BBRAM anymore, so this is guaranteed to fail.
1824 *
1825 * TODO(b/178689388): remove from this header once no external
1826 * dependencies reference these constants.
1827 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001828#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001829#define EC_VER_VBNV_CONTEXT 1
1830#define EC_VBNV_BLOCK_SIZE 16
1831
1832enum ec_vbnvcontext_op {
1833 EC_VBNV_CONTEXT_OP_READ,
1834 EC_VBNV_CONTEXT_OP_WRITE,
1835};
1836
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001837struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001838 uint32_t op;
1839 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001840} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001841
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001842struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001843 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001844} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001845
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001846
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001847/* Get SPI flash information */
1848#define EC_CMD_FLASH_SPI_INFO 0x0018
1849
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001850struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001851 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1852 uint8_t jedec[3];
1853
1854 /* Pad byte; currently always contains 0 */
1855 uint8_t reserved0;
1856
1857 /* Manufacturer / device ID from command 0x90 */
1858 uint8_t mfr_dev_id[2];
1859
1860 /* Status registers from command 0x05 and 0x35 */
1861 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001862} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001863
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001864
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001865/* Select flash during flash operations */
1866#define EC_CMD_FLASH_SELECT 0x0019
1867
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001868/**
1869 * struct ec_params_flash_select - Parameters for the flash select command.
1870 * @select: 1 to select flash, 0 to deselect flash
1871 */
1872struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001873 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001874} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001875
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001876
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001877/**
1878 * Request random numbers to be generated and returned.
1879 * Can be used to test the random number generator is truly random.
1880 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1881 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1882 */
1883#define EC_CMD_RAND_NUM 0x001A
1884#define EC_VER_RAND_NUM 0
1885
1886struct ec_params_rand_num {
1887 uint16_t num_rand_bytes; /**< num random bytes to generate */
1888} __ec_align4;
1889
1890struct ec_response_rand_num {
1891 uint8_t rand[0]; /**< generated random numbers */
1892} __ec_align4;
1893
1894BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1895
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001896/**
1897 * Get information about the key used to sign the RW firmware.
1898 * For more details on the fields, see "struct vb21_packed_key".
1899 */
1900#define EC_CMD_RWSIG_INFO 0x001B
1901#define EC_VER_RWSIG_INFO 0
1902
1903#define VBOOT2_KEY_ID_BYTES 20
1904
1905#ifdef CHROMIUM_EC
1906/* Don't force external projects to depend on the vboot headers. */
1907#include "vb21_struct.h"
1908BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1909#endif
1910
1911struct ec_response_rwsig_info {
1912 /**
1913 * Signature algorithm used by the key
1914 * (enum vb2_signature_algorithm).
1915 */
1916 uint16_t sig_alg;
1917
1918 /**
1919 * Hash digest algorithm used with the key
1920 * (enum vb2_hash_algorithm).
1921 */
1922 uint16_t hash_alg;
1923
1924 /** Key version. */
1925 uint32_t key_version;
1926
1927 /** Key ID (struct vb2_id). */
1928 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
1929
1930 uint8_t key_is_valid;
1931
1932 /** Alignment padding. */
1933 uint8_t reserved[3];
1934} __ec_align4;
1935
1936BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
1937
1938/**
1939 * Get information about the system, such as reset flags, locked state, etc.
1940 */
1941#define EC_CMD_SYSINFO 0x001C
1942#define EC_VER_SYSINFO 0
1943
1944enum sysinfo_flags {
1945 SYSTEM_IS_LOCKED = BIT(0),
1946 SYSTEM_IS_FORCE_LOCKED = BIT(1),
1947 SYSTEM_JUMP_ENABLED = BIT(2),
1948 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
1949 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4)
1950};
1951
1952struct ec_response_sysinfo {
1953 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
1954 uint32_t current_image; /**< enum ec_current_image */
1955 uint32_t flags; /**< enum sysinfo_flags */
1956} __ec_align4;
1957
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001958/*****************************************************************************/
1959/* PWM commands */
1960
1961/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001962#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001963
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001964struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001965 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001966} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001967
1968/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001969#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001970
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001971/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001972struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001973 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001974} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001975
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001976/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001977struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001978 uint32_t rpm;
1979 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001980} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001981
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001982/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001983/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001984#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001985
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001986struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001987 uint8_t percent;
1988 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001989} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001990
1991/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001992/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001993#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001994
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001995struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001996 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001997} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001998
1999/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002000#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002001
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002002/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002003struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002004 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002005} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002006
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002007/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002008struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002009 uint32_t percent;
2010 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002011} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002012
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002013#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002014/* 16 bit duty cycle, 0xffff = 100% */
2015#define EC_PWM_MAX_DUTY 0xffff
2016
2017enum ec_pwm_type {
2018 /* All types, indexed by board-specific enum pwm_channel */
2019 EC_PWM_TYPE_GENERIC = 0,
2020 /* Keyboard backlight */
2021 EC_PWM_TYPE_KB_LIGHT,
2022 /* Display backlight */
2023 EC_PWM_TYPE_DISPLAY_LIGHT,
2024 EC_PWM_TYPE_COUNT,
2025};
2026
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002027struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002028 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2029 uint8_t pwm_type; /* ec_pwm_type */
2030 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002031} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002032
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002033#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002034
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002035struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002036 uint8_t pwm_type; /* ec_pwm_type */
2037 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002038} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002039
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002040struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002041 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002042} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002043
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002044/*****************************************************************************/
2045/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002046 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002047 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2048 * into a subcommand. We'll make separate structs for subcommands with
2049 * different input args, so that we know how much to expect.
2050 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002051#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002053struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002054 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002055} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002056
Duncan Laurie433432b2013-06-03 10:38:22 -07002057#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002058
2059/*
2060 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002061 * host command, but the alignment is the same regardless. Keep it that way.
2062 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002063struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002064 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002065 int32_t google_ramp_up;
2066 int32_t google_ramp_down;
2067 int32_t s3s0_ramp_up;
2068 int32_t s0_tick_delay[2]; /* AC=0/1 */
2069 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2070 int32_t s0s3_ramp_down;
2071 int32_t s3_sleep_for;
2072 int32_t s3_ramp_up;
2073 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002074
2075 /* Oscillation */
2076 uint8_t new_s0;
2077 uint8_t osc_min[2]; /* AC=0/1 */
2078 uint8_t osc_max[2]; /* AC=0/1 */
2079 uint8_t w_ofs[2]; /* AC=0/1 */
2080
2081 /* Brightness limits based on the backlight and AC. */
2082 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2083 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2084 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2085
2086 /* Battery level thresholds */
2087 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2088
2089 /* Map [AC][battery_level] to color index */
2090 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2091 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2092
2093 /* Color palette */
2094 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002095} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002097struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002098 /* Timing */
2099 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;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002108 int32_t s5_ramp_up;
2109 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002110 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002111 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002112 int32_t tap_display_time;
2113
2114 /* Tap-for-battery params */
2115 uint8_t tap_pct_red;
2116 uint8_t tap_pct_green;
2117 uint8_t tap_seg_min_on;
2118 uint8_t tap_seg_max_on;
2119 uint8_t tap_seg_osc;
2120 uint8_t tap_idx[3];
2121
2122 /* Oscillation */
2123 uint8_t osc_min[2]; /* AC=0/1 */
2124 uint8_t osc_max[2]; /* AC=0/1 */
2125 uint8_t w_ofs[2]; /* AC=0/1 */
2126
2127 /* Brightness limits based on the backlight and AC. */
2128 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2129 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2130 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2131
2132 /* Battery level thresholds */
2133 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2134
2135 /* Map [AC][battery_level] to color index */
2136 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2137 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2138
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002139 /* s5: single color pulse on inhibited power-up */
2140 uint8_t s5_idx;
2141
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002142 /* Color palette */
2143 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002144} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002145
Duncan Laurieeb316852015-12-01 18:51:18 -08002146/* Lightbar command params v2
2147 * crbug.com/467716
2148 *
2149 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2150 * logical groups to make it more manageable ( < 120 bytes).
2151 *
2152 * NOTE: Each of these groups must be less than 120 bytes.
2153 */
2154
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002155struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002156 /* Timing */
2157 int32_t google_ramp_up;
2158 int32_t google_ramp_down;
2159 int32_t s3s0_ramp_up;
2160 int32_t s0_tick_delay[2]; /* AC=0/1 */
2161 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2162 int32_t s0s3_ramp_down;
2163 int32_t s3_sleep_for;
2164 int32_t s3_ramp_up;
2165 int32_t s3_ramp_down;
2166 int32_t s5_ramp_up;
2167 int32_t s5_ramp_down;
2168 int32_t tap_tick_delay;
2169 int32_t tap_gate_delay;
2170 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002171} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002172
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002173struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002174 /* Tap-for-battery params */
2175 uint8_t tap_pct_red;
2176 uint8_t tap_pct_green;
2177 uint8_t tap_seg_min_on;
2178 uint8_t tap_seg_max_on;
2179 uint8_t tap_seg_osc;
2180 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002181} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002182
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002183struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002184 /* Oscillation */
2185 uint8_t osc_min[2]; /* AC=0/1 */
2186 uint8_t osc_max[2]; /* AC=0/1 */
2187 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002188} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002189
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002190struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002191 /* Brightness limits based on the backlight and AC. */
2192 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2193 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2194 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002195} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002196
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002197struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002198 /* Battery level thresholds */
2199 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002200} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002201
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002202struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002203 /* Map [AC][battery_level] to color index */
2204 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2205 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2206
2207 /* s5: single color pulse on inhibited power-up */
2208 uint8_t s5_idx;
2209
2210 /* Color palette */
2211 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002212} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002213
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002214/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002215#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002216struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002217 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002218 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002219} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002220
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002221struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002222 uint8_t cmd; /* Command (see enum lightbar_command) */
2223 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002224 /*
2225 * The following commands have no args:
2226 *
2227 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2228 * version, get_brightness, get_demo, suspend, resume,
2229 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2230 * get_params_v2_bright, get_params_v2_thlds,
2231 * get_params_v2_colors
2232 *
2233 * Don't use an empty struct, because C++ hates that.
2234 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002235
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002236 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002237 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002238 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002239
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002240 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002241 uint8_t ctrl, reg, value;
2242 } reg;
2243
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002244 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002245 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002246 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002247
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002248 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002249 uint8_t led;
2250 } get_rgb;
2251
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002252 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002253 uint8_t enable;
2254 } manual_suspend_ctrl;
2255
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002256 struct lightbar_params_v0 set_params_v0;
2257 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002258
2259 struct lightbar_params_v2_timing set_v2par_timing;
2260 struct lightbar_params_v2_tap set_v2par_tap;
2261 struct lightbar_params_v2_oscillation set_v2par_osc;
2262 struct lightbar_params_v2_brightness set_v2par_bright;
2263 struct lightbar_params_v2_thresholds set_v2par_thlds;
2264 struct lightbar_params_v2_colors set_v2par_colors;
2265
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002266 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002267 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002268} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002269
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002270struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002271 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002272 struct __ec_todo_unpacked {
2273 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002274 uint8_t reg;
2275 uint8_t ic0;
2276 uint8_t ic1;
2277 } vals[23];
2278 } dump;
2279
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002280 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002281 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002282 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002283
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002284 struct lightbar_params_v0 get_params_v0;
2285 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002286
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002287
Duncan Laurieeb316852015-12-01 18:51:18 -08002288 struct lightbar_params_v2_timing get_params_v2_timing;
2289 struct lightbar_params_v2_tap get_params_v2_tap;
2290 struct lightbar_params_v2_oscillation get_params_v2_osc;
2291 struct lightbar_params_v2_brightness get_params_v2_bright;
2292 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2293 struct lightbar_params_v2_colors get_params_v2_colors;
2294
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002295 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002296 uint32_t num;
2297 uint32_t flags;
2298 } version;
2299
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002300 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002301 uint8_t red, green, blue;
2302 } get_rgb;
2303
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002304 /*
2305 * The following commands have no response:
2306 *
2307 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2308 * set_params_v0, set_params_v1, set_program,
2309 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2310 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2311 * set_v2par_thlds, set_v2par_colors
2312 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002313 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002314} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002315
2316/* Lightbar commands */
2317enum lightbar_command {
2318 LIGHTBAR_CMD_DUMP = 0,
2319 LIGHTBAR_CMD_OFF = 1,
2320 LIGHTBAR_CMD_ON = 2,
2321 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002322 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002323 LIGHTBAR_CMD_SEQ = 5,
2324 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002325 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002326 LIGHTBAR_CMD_GET_SEQ = 8,
2327 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002328 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2329 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002330 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002331 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2332 LIGHTBAR_CMD_GET_RGB = 14,
2333 LIGHTBAR_CMD_GET_DEMO = 15,
2334 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2335 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002336 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002337 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2338 LIGHTBAR_CMD_SUSPEND = 20,
2339 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002340 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2341 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2342 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2343 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2344 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2345 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2346 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2347 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2348 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2349 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2350 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2351 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002352 LIGHTBAR_NUM_CMDS
2353};
2354
2355/*****************************************************************************/
2356/* LED control commands */
2357
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002358#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002359
Bill Richardsone221aad2013-06-12 10:50:41 -07002360enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002361 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002362 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002363 /*
2364 * LED to indicate system power state (on or in suspend).
2365 * May be on power button or on C-panel.
2366 */
2367 EC_LED_ID_POWER_LED,
2368 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002369 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002370 /* LED to indicate left side */
2371 EC_LED_ID_LEFT_LED,
2372 /* LED to indicate right side */
2373 EC_LED_ID_RIGHT_LED,
2374 /* LED to indicate recovery mode with HW_REINIT */
2375 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2376 /* LED to indicate sysrq debug mode. */
2377 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002378
2379 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002380};
Duncan Laurie433432b2013-06-03 10:38:22 -07002381
Bill Richardsone221aad2013-06-12 10:50:41 -07002382/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002383#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2384#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002385
2386enum ec_led_colors {
2387 EC_LED_COLOR_RED = 0,
2388 EC_LED_COLOR_GREEN,
2389 EC_LED_COLOR_BLUE,
2390 EC_LED_COLOR_YELLOW,
2391 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002392 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002393
2394 EC_LED_COLOR_COUNT
2395};
2396
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002397struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002398 uint8_t led_id; /* Which LED to control */
2399 uint8_t flags; /* Control flags */
2400
2401 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002402} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002403
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002404struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002405 /*
2406 * Available brightness value range.
2407 *
2408 * Range 0 means color channel not present.
2409 * Range 1 means on/off control.
2410 * Other values means the LED is control by PWM.
2411 */
2412 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002413} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002414
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002415/*****************************************************************************/
2416/* Verified boot commands */
2417
2418/*
2419 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2420 * reused for other purposes with version > 0.
2421 */
2422
2423/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002424#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002425
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002426struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002427 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2428 uint8_t hash_type; /* enum ec_vboot_hash_type */
2429 uint8_t nonce_size; /* Nonce size; may be 0 */
2430 uint8_t reserved0; /* Reserved; set 0 */
2431 uint32_t offset; /* Offset in flash to hash */
2432 uint32_t size; /* Number of bytes to hash */
2433 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002434} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002435
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002436struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002437 uint8_t status; /* enum ec_vboot_hash_status */
2438 uint8_t hash_type; /* enum ec_vboot_hash_type */
2439 uint8_t digest_size; /* Size of hash digest in bytes */
2440 uint8_t reserved0; /* Ignore; will be 0 */
2441 uint32_t offset; /* Offset in flash which was hashed */
2442 uint32_t size; /* Number of bytes hashed */
2443 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002444} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002445
2446enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002447 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2448 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2449 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2450 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002451};
2452
2453enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002454 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002455};
2456
2457enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002458 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2459 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2460 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002461};
2462
Duncan Laurie433432b2013-06-03 10:38:22 -07002463/*
2464 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2465 * If one of these is specified, the EC will automatically update offset and
2466 * size to the correct values for the specified image (RO or RW).
2467 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002468#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2469#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2470#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2471
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002472/*
2473 * 'RW' is vague if there are multiple RW images; we mean the active one,
2474 * so the old constant is deprecated.
2475 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002476#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002477
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002478/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002479/*
2480 * Motion sense commands. We'll make separate structs for sub-commands with
2481 * different input args, so that we know how much to expect.
2482 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002483#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002484
2485/* Motion sense commands */
2486enum motionsense_command {
2487 /*
2488 * Dump command returns all motion sensor data including motion sense
2489 * module flags and individual sensor flags.
2490 */
2491 MOTIONSENSE_CMD_DUMP = 0,
2492
2493 /*
2494 * Info command returns data describing the details of a given sensor,
2495 * including enum motionsensor_type, enum motionsensor_location, and
2496 * enum motionsensor_chip.
2497 */
2498 MOTIONSENSE_CMD_INFO = 1,
2499
2500 /*
2501 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002502 * in milliseconds.
2503 * It is per sensor, the EC run sample task at the minimum of all
2504 * sensors EC_RATE.
2505 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2506 * to collect all the sensor samples.
2507 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2508 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002509 */
2510 MOTIONSENSE_CMD_EC_RATE = 2,
2511
2512 /*
2513 * Sensor ODR command is a setter/getter command for the output data
2514 * rate of a specific motion sensor in millihertz.
2515 */
2516 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2517
2518 /*
2519 * Sensor range command is a setter/getter command for the range of
2520 * a specified motion sensor in +/-G's or +/- deg/s.
2521 */
2522 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2523
2524 /*
2525 * Setter/getter command for the keyboard wake angle. When the lid
2526 * angle is greater than this value, keyboard wake is disabled in S3,
2527 * and when the lid angle goes less than this value, keyboard wake is
2528 * enabled. Note, the lid angle measurement is an approximate,
2529 * un-calibrated value, hence the wake angle isn't exact.
2530 */
2531 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2532
Duncan Laurieeb316852015-12-01 18:51:18 -08002533 /*
2534 * Returns a single sensor data.
2535 */
2536 MOTIONSENSE_CMD_DATA = 6,
2537
2538 /*
2539 * Return sensor fifo info.
2540 */
2541 MOTIONSENSE_CMD_FIFO_INFO = 7,
2542
2543 /*
2544 * Insert a flush element in the fifo and return sensor fifo info.
2545 * The host can use that element to synchronize its operation.
2546 */
2547 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2548
2549 /*
2550 * Return a portion of the fifo.
2551 */
2552 MOTIONSENSE_CMD_FIFO_READ = 9,
2553
2554 /*
2555 * Perform low level calibration.
2556 * On sensors that support it, ask to do offset calibration.
2557 */
2558 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2559
2560 /*
2561 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002562 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002563 * The offsets can be calculated by the host, or via
2564 * PERFORM_CALIB command.
2565 */
2566 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2567
2568 /*
2569 * List available activities for a MOTION sensor.
2570 * Indicates if they are enabled or disabled.
2571 */
2572 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2573
2574 /*
2575 * Activity management
2576 * Enable/Disable activity recognition.
2577 */
2578 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2579
2580 /*
2581 * Lid Angle
2582 */
2583 MOTIONSENSE_CMD_LID_ANGLE = 14,
2584
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002585 /*
2586 * Allow the FIFO to trigger interrupt via MKBP events.
2587 * By default the FIFO does not send interrupt to process the FIFO
2588 * until the AP is ready or it is coming from a wakeup sensor.
2589 */
2590 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2591
2592 /*
2593 * Spoof the readings of the sensors. The spoofed readings can be set
2594 * to arbitrary values, or will lock to the last read actual values.
2595 */
2596 MOTIONSENSE_CMD_SPOOF = 16,
2597
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002598 /* Set lid angle for tablet mode detection. */
2599 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2600
2601 /*
2602 * Sensor Scale command is a setter/getter command for the calibration
2603 * scale.
2604 */
2605 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2606
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002607 /*
2608 * Read the current online calibration values (if available).
2609 */
2610 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2611
Yidi Lin42f79592020-09-21 18:04:10 +08002612 /*
2613 * Activity management
2614 * Retrieve current status of given activity.
2615 */
2616 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2617
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002618 /* Number of motionsense sub-commands. */
2619 MOTIONSENSE_NUM_CMDS
2620};
2621
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002622/* List of motion sensor types. */
2623enum motionsensor_type {
2624 MOTIONSENSE_TYPE_ACCEL = 0,
2625 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002626 MOTIONSENSE_TYPE_MAG = 2,
2627 MOTIONSENSE_TYPE_PROX = 3,
2628 MOTIONSENSE_TYPE_LIGHT = 4,
2629 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002630 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002631 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002632 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002633 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002634};
2635
2636/* List of motion sensor locations. */
2637enum motionsensor_location {
2638 MOTIONSENSE_LOC_BASE = 0,
2639 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002640 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002641 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002642};
2643
2644/* List of motion sensor chips. */
2645enum motionsensor_chip {
2646 MOTIONSENSE_CHIP_KXCJ9 = 0,
2647 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002648 MOTIONSENSE_CHIP_BMI160 = 2,
2649 MOTIONSENSE_CHIP_SI1141 = 3,
2650 MOTIONSENSE_CHIP_SI1142 = 4,
2651 MOTIONSENSE_CHIP_SI1143 = 5,
2652 MOTIONSENSE_CHIP_KX022 = 6,
2653 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002654 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002655 MOTIONSENSE_CHIP_BMP280 = 9,
2656 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002657 MOTIONSENSE_CHIP_BH1730 = 11,
2658 MOTIONSENSE_CHIP_GPIO = 12,
2659 MOTIONSENSE_CHIP_LIS2DH = 13,
2660 MOTIONSENSE_CHIP_LSM6DSM = 14,
2661 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002662 MOTIONSENSE_CHIP_LIS2MDL = 16,
2663 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2664 MOTIONSENSE_CHIP_LSM6DSO = 18,
2665 MOTIONSENSE_CHIP_LNG2DM = 19,
2666 MOTIONSENSE_CHIP_TCS3400 = 20,
2667 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2668 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002669 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002670 MOTIONSENSE_CHIP_BMI260 = 24,
2671 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002672 MOTIONSENSE_CHIP_ICM42607 = 26,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002673 MOTIONSENSE_CHIP_MAX,
2674};
2675
2676/* List of orientation positions */
2677enum motionsensor_orientation {
2678 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2679 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2680 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2681 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2682 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002683};
2684
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002685struct ec_response_activity_data {
2686 uint8_t activity; /* motionsensor_activity */
2687 uint8_t state;
2688} __ec_todo_packed;
2689
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002690struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002691 /* Flags for each sensor. */
2692 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002693 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002694 uint8_t sensor_num;
2695 /* Each sensor is up to 3-axis. */
2696 union {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002697 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002698 /* for sensors using unsigned data */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002699 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002700 struct __ec_todo_packed {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002701 uint16_t reserved;
2702 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002703 };
2704 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002705 struct ec_response_activity_data activity_data;
2706 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002707 };
2708 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002709} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002710
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002711/* Response to AP reporting calibration data for a given sensor. */
2712struct ec_response_online_calibration_data {
2713 /** The calibration values. */
2714 int16_t data[3];
2715};
2716
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002717/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002718struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002719 /* Size of the fifo */
2720 uint16_t size;
2721 /* Amount of space used in the fifo */
2722 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002723 /* Timestamp recorded in us.
2724 * aka accurate timestamp when host event was triggered.
2725 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002726 uint32_t timestamp;
2727 /* Total amount of vector lost */
2728 uint16_t total_lost;
2729 /* Lost events since the last fifo_info, per sensors */
2730 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002731} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002732
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002733struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002734 uint32_t number_data;
2735 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002736} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002737
2738/* List supported activity recognition */
2739enum motionsensor_activity {
2740 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2741 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2742 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002743 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002744 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002745};
2746
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002747struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002748 uint8_t sensor_num;
2749 uint8_t activity; /* one of enum motionsensor_activity */
2750 uint8_t enable; /* 1: enable, 0: disable */
2751 uint8_t reserved;
2752 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002753} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002754
2755/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002756#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002757
2758/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002759#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002760
2761/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002762 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002763 * data contains time stamp
2764 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002765#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2766#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2767#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2768#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2769#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002770
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002771#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2772
Duncan Laurieeb316852015-12-01 18:51:18 -08002773/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002774 * Send this value for the data element to only perform a read. If you
2775 * send any other value, the EC will interpret it as data to set and will
2776 * return the actual value set.
2777 */
2778#define EC_MOTION_SENSE_NO_VALUE -1
2779
Duncan Laurieeb316852015-12-01 18:51:18 -08002780#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2781
2782/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2783/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002784#define MOTION_SENSE_SET_OFFSET BIT(0)
2785
2786/* Default Scale value, factor 1. */
2787#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002788
2789#define LID_ANGLE_UNRELIABLE 500
2790
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002791enum motionsense_spoof_mode {
2792 /* Disable spoof mode. */
2793 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2794
2795 /* Enable spoof mode, but use provided component values. */
2796 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2797
2798 /* Enable spoof mode, but use the current sensor values. */
2799 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2800
2801 /* Query the current spoof mode status for the sensor. */
2802 MOTIONSENSE_SPOOF_MODE_QUERY,
2803};
2804
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002805struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002806 uint8_t cmd;
2807 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002808 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002809 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002810 /*
2811 * Maximal number of sensor the host is expecting.
2812 * 0 means the host is only interested in the number
2813 * of sensors controlled by the EC.
2814 */
2815 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002816 } dump;
2817
2818 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002819 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002820 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002821 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002822 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2823 * kb_wake_angle: angle to wakup AP.
2824 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002825 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002826 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002828 /*
2829 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2830 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002831 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002832 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002833 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002834
2835 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002836 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2837 * Allow entering/exiting the calibration mode.
2838 */
2839 struct __ec_todo_unpacked {
2840 uint8_t sensor_num;
2841 uint8_t enable;
2842 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002843
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002844 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002845 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2846 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002847 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002848 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002849 uint8_t sensor_num;
2850
2851 /* Rounding flag, true for round-up, false for down. */
2852 uint8_t roundup;
2853
2854 uint16_t reserved;
2855
2856 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2857 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002858 } ec_rate, sensor_odr, sensor_range;
2859
2860 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002861 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002862 uint8_t sensor_num;
2863
2864 /*
2865 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2866 * the calibration information in the EC.
2867 * If unset, just retrieve calibration information.
2868 */
2869 uint16_t flags;
2870
2871 /*
2872 * Temperature at calibration, in units of 0.01 C
2873 * 0x8000: invalid / unknown.
2874 * 0x0: 0C
2875 * 0x7fff: +327.67C
2876 */
2877 int16_t temp;
2878
2879 /*
2880 * Offset for calibration.
2881 * Unit:
2882 * Accelerometer: 1/1024 g
2883 * Gyro: 1/1024 deg/s
2884 * Compass: 1/16 uT
2885 */
2886 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002887 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002888
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002889 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2890 struct __ec_todo_packed {
2891 uint8_t sensor_num;
2892
2893 /*
2894 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2895 * the calibration information in the EC.
2896 * If unset, just retrieve calibration information.
2897 */
2898 uint16_t flags;
2899
2900 /*
2901 * Temperature at calibration, in units of 0.01 C
2902 * 0x8000: invalid / unknown.
2903 * 0x0: 0C
2904 * 0x7fff: +327.67C
2905 */
2906 int16_t temp;
2907
2908 /*
2909 * Scale for calibration:
2910 * By default scale is 1, it is encoded on 16bits:
2911 * 1 = BIT(15)
2912 * ~2 = 0xFFFF
2913 * ~0 = 0.
2914 */
2915 uint16_t scale[3];
2916 } sensor_scale;
2917
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002918
Duncan Laurieeb316852015-12-01 18:51:18 -08002919 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002920 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002921
2922 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002923 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002924 /*
2925 * Number of expected vector to return.
2926 * EC may return less or 0 if none available.
2927 */
2928 uint32_t max_data_vector;
2929 } fifo_read;
2930
Yidi Lin42f79592020-09-21 18:04:10 +08002931 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08002932 struct ec_motion_sense_activity set_activity;
2933
2934 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002935 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002936
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002937 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2938 struct __ec_todo_unpacked {
2939 /*
2940 * 1: enable, 0 disable fifo,
2941 * EC_MOTION_SENSE_NO_VALUE return value.
2942 */
2943 int8_t enable;
2944 } fifo_int_enable;
2945
2946 /* Used for MOTIONSENSE_CMD_SPOOF */
2947 struct __ec_todo_packed {
2948 uint8_t sensor_id;
2949
2950 /* See enum motionsense_spoof_mode. */
2951 uint8_t spoof_enable;
2952
2953 /* Ignored, used for alignment. */
2954 uint8_t reserved;
2955
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002956 union {
2957 /* Individual component values to spoof. */
2958 int16_t components[3];
2959
2960 /* Used when spoofing an activity */
2961 struct {
2962 /* enum motionsensor_activity */
2963 uint8_t activity_num;
2964
2965 /* spoof activity state */
2966 uint8_t activity_state;
2967 };
2968 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002969 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002970
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002971 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2972 struct __ec_todo_unpacked {
2973 /*
2974 * Lid angle threshold for switching between tablet and
2975 * clamshell mode.
2976 */
2977 int16_t lid_angle;
2978
2979 /*
2980 * Hysteresis degree to prevent fluctuations between
2981 * clamshell and tablet mode if lid angle keeps
2982 * changing around the threshold. Lid motion driver will
2983 * use lid_angle + hys_degree to trigger tablet mode and
2984 * lid_angle - hys_degree to trigger clamshell mode.
2985 */
2986 int16_t hys_degree;
2987 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002988
2989 /*
2990 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
2991 * Allow reading a single sensor's online calibration value.
2992 */
2993 struct __ec_todo_unpacked {
2994 uint8_t sensor_num;
2995 } online_calib_read;
2996
Yidi Lin42f79592020-09-21 18:04:10 +08002997 /*
2998 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
2999 */
3000 struct __ec_todo_unpacked {
3001 uint8_t sensor_num;
3002 uint8_t activity; /* enum motionsensor_activity */
3003 } get_activity;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003004 };
3005} __ec_todo_packed;
3006
Jett Rinkba2edaf2020-01-14 11:49:06 -07003007enum motion_sense_cmd_info_flags {
3008 /* The sensor supports online calibration */
3009 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3010};
3011
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003012struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003013 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003014 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003015 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003016 /* Flags representing the motion sensor module. */
3017 uint8_t module_flags;
3018
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003019 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003020 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003021
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003022 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003023 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003024 * for holding all the data.
3025 */
3026 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003027 } dump;
3028
3029 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003030 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003031 /* Should be element of enum motionsensor_type. */
3032 uint8_t type;
3033
3034 /* Should be element of enum motionsensor_location. */
3035 uint8_t location;
3036
3037 /* Should be element of enum motionsensor_chip. */
3038 uint8_t chip;
3039 } info;
3040
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003041 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3042 struct __ec_todo_unpacked {
3043 /* Should be element of enum motionsensor_type. */
3044 uint8_t type;
3045
3046 /* Should be element of enum motionsensor_location. */
3047 uint8_t location;
3048
3049 /* Should be element of enum motionsensor_chip. */
3050 uint8_t chip;
3051
3052 /* Minimum sensor sampling frequency */
3053 uint32_t min_frequency;
3054
3055 /* Maximum sensor sampling frequency */
3056 uint32_t max_frequency;
3057
3058 /* Max number of sensor events that could be in fifo */
3059 uint32_t fifo_max_event_count;
3060 } info_3;
3061
Jett Rinkba2edaf2020-01-14 11:49:06 -07003062 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3063 struct __ec_align4 {
3064 /* Should be element of enum motionsensor_type. */
3065 uint8_t type;
3066
3067 /* Should be element of enum motionsensor_location. */
3068 uint8_t location;
3069
3070 /* Should be element of enum motionsensor_chip. */
3071 uint8_t chip;
3072
3073 /* Minimum sensor sampling frequency */
3074 uint32_t min_frequency;
3075
3076 /* Maximum sensor sampling frequency */
3077 uint32_t max_frequency;
3078
3079 /* Max number of sensor events that could be in fifo */
3080 uint32_t fifo_max_event_count;
3081
3082 /*
3083 * Should be elements of
3084 * enum motion_sense_cmd_info_flags
3085 */
3086 uint32_t flags;
3087 } info_4;
3088
Duncan Laurieeb316852015-12-01 18:51:18 -08003089 /* Used for MOTIONSENSE_CMD_DATA */
3090 struct ec_response_motion_sensor_data data;
3091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003092 /*
3093 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003094 * MOTIONSENSE_CMD_SENSOR_RANGE,
3095 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3096 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3097 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003098 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003099 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003100 /* Current value of the parameter queried. */
3101 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003102 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
3103 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003104
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003105 /*
3106 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3107 * PERFORM_CALIB.
3108 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003109 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003110 int16_t temp;
3111 int16_t offset[3];
3112 } sensor_offset, perform_calib;
3113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003114 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3115 struct __ec_todo_unpacked {
3116 int16_t temp;
3117 uint16_t scale[3];
3118 } sensor_scale;
3119
Duncan Laurieeb316852015-12-01 18:51:18 -08003120 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3121
3122 struct ec_response_motion_sense_fifo_data fifo_read;
3123
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003124 struct ec_response_online_calibration_data online_calib_read;
3125
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003126 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003127 uint16_t reserved;
3128 uint32_t enabled;
3129 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003130 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003131
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003132 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003133
Duncan Laurieeb316852015-12-01 18:51:18 -08003134 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003135 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003136 /*
3137 * Angle between 0 and 360 degree if available,
3138 * LID_ANGLE_UNRELIABLE otherwise.
3139 */
3140 uint16_t value;
3141 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003142
3143 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3144 struct __ec_todo_unpacked {
3145 /*
3146 * Lid angle threshold for switching between tablet and
3147 * clamshell mode.
3148 */
3149 uint16_t lid_angle;
3150
3151 /* Hysteresis degree. */
3152 uint16_t hys_degree;
3153 } tablet_mode_threshold;
3154
Yidi Lin42f79592020-09-21 18:04:10 +08003155 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3156 struct __ec_todo_unpacked {
3157 uint8_t state;
3158 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003159 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003160} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003161
3162/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003163/* Force lid open command */
3164
3165/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003166#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003167
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003168struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003169 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003170} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003171
3172/*****************************************************************************/
3173/* Configure the behavior of the power button */
3174#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3175
3176enum ec_config_power_button_flags {
3177 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003178 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003179};
3180
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003181struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003182 /* See enum ec_config_power_button_flags */
3183 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003184} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003185
3186/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003187/* USB charging control commands */
3188
3189/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003190#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003191
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003192enum usb_charge_mode {
3193 /* Disable USB port. */
3194 USB_CHARGE_MODE_DISABLED,
3195 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3196 USB_CHARGE_MODE_SDP2,
3197 /* Set USB port to Charging Downstream Port, BC 1.2. */
3198 USB_CHARGE_MODE_CDP,
3199 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3200 USB_CHARGE_MODE_DCP_SHORT,
3201 /* Enable USB port (for dumb ports). */
3202 USB_CHARGE_MODE_ENABLED,
3203 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3204 USB_CHARGE_MODE_DEFAULT,
3205
3206 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003207};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003208
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003209enum usb_suspend_charge {
3210 /* Enable charging in suspend */
3211 USB_ALLOW_SUSPEND_CHARGE,
3212 /* Disable charging in suspend */
3213 USB_DISALLOW_SUSPEND_CHARGE
3214};
3215
3216struct ec_params_usb_charge_set_mode {
3217 uint8_t usb_port_id;
3218 uint8_t mode:7; /* enum usb_charge_mode */
3219 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
3220} __ec_align1;
3221
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003222/*****************************************************************************/
3223/* Persistent storage for host */
3224
3225/* Maximum bytes that can be read/written in a single command */
3226#define EC_PSTORE_SIZE_MAX 64
3227
3228/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003229#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003230
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003231struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003232 /* Persistent storage size, in bytes */
3233 uint32_t pstore_size;
3234 /* Access size; read/write offset and size must be a multiple of this */
3235 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003236} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003237
3238/*
3239 * Read persistent storage
3240 *
3241 * Response is params.size bytes of data.
3242 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003243#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003244
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003245struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003246 uint32_t offset; /* Byte offset to read */
3247 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003248} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003249
3250/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003251#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003252
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003253struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003254 uint32_t offset; /* Byte offset to write */
3255 uint32_t size; /* Size to write in bytes */
3256 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003257} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003258
3259/*****************************************************************************/
3260/* Real-time clock */
3261
3262/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003263struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003264 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003265} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003266
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003267struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003268 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003269} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003270
3271/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003272#define EC_CMD_RTC_GET_VALUE 0x0044
3273#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003274
3275/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003276#define EC_CMD_RTC_SET_VALUE 0x0046
3277#define EC_CMD_RTC_SET_ALARM 0x0047
3278
3279/* Pass as time param to SET_ALARM to clear the current alarm */
3280#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003281
3282/*****************************************************************************/
3283/* Port80 log access */
3284
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003285/* Maximum entries that can be read/written in a single command */
3286#define EC_PORT80_SIZE_MAX 32
3287
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003288/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003289#define EC_CMD_PORT80_LAST_BOOT 0x0048
3290#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003291
3292enum ec_port80_subcmd {
3293 EC_PORT80_GET_INFO = 0,
3294 EC_PORT80_READ_BUFFER,
3295};
3296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003297struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003298 uint16_t subcmd;
3299 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003300 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003301 uint32_t offset;
3302 uint32_t num_entries;
3303 } read_buffer;
3304 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003305} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003306
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003307struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003308 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003309 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003310 uint32_t writes;
3311 uint32_t history_size;
3312 uint32_t last_boot;
3313 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003314 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003315 uint16_t codes[EC_PORT80_SIZE_MAX];
3316 } data;
3317 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003318} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003319
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003320struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003321 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003322} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003323
3324/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003325/* Temporary secure storage for host verified boot use */
3326
3327/* Number of bytes in a vstore slot */
3328#define EC_VSTORE_SLOT_SIZE 64
3329
3330/* Maximum number of vstore slots */
3331#define EC_VSTORE_SLOT_MAX 32
3332
3333/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003334#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003335struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003336 /* Indicates which slots are locked */
3337 uint32_t slot_locked;
3338 /* Total number of slots available */
3339 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003340} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003341
3342/*
3343 * Read temporary secure storage
3344 *
3345 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3346 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003347#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003348
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003349struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003350 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003351} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003352
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003353struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003354 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003355} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003356
3357/*
3358 * Write temporary secure storage and lock it.
3359 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003360#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003361
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003362struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003363 uint8_t slot; /* Slot to write to */
3364 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003365} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003366
3367/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003368/* Thermal engine commands. Note that there are two implementations. We'll
3369 * reuse the command number, but the data and behavior is incompatible.
3370 * Version 0 is what originally shipped on Link.
3371 * Version 1 separates the CPU thermal limits from the fan control.
3372 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003373
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003374#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3375#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003376
Duncan Laurie93e24442014-01-06 12:30:52 -08003377/* The version 0 structs are opaque. You have to know what they are for
3378 * the get/set commands to make any sense.
3379 */
3380
3381/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003382struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003383 uint8_t sensor_type;
3384 uint8_t threshold_id;
3385 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003386} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003387
Duncan Laurie93e24442014-01-06 12:30:52 -08003388/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003389struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003390 uint8_t sensor_type;
3391 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003392} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003393
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003394struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003395 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003396} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003397
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003398
Duncan Laurie93e24442014-01-06 12:30:52 -08003399/* The version 1 structs are visible. */
3400enum ec_temp_thresholds {
3401 EC_TEMP_THRESH_WARN = 0,
3402 EC_TEMP_THRESH_HIGH,
3403 EC_TEMP_THRESH_HALT,
3404
3405 EC_TEMP_THRESH_COUNT
3406};
3407
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003408/*
3409 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003410 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003411 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003412 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3413 * hysteresis.
3414 * For example,
3415 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3416 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3417 * EC will throttle ap when temperature >= 301 K, and release throttling when
3418 * temperature <= 299 K.
3419 *
3420 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3421 * For example,
3422 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3423 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3424 * EC will throttle ap when temperature >= 301 K, and release throttling when
3425 * temperature <= 294 K.
3426 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003427 * Note that this structure is a sub-structure of
3428 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003429 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003430struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003431 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003432 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003433 uint32_t temp_fan_off; /* no active cooling needed */
3434 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003435} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003436
3437/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003438struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003439 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003440} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003441/* This returns a struct ec_thermal_config */
3442
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003443/*
3444 * Version 1 - set config for one sensor.
3445 * Use read-modify-write for best results!
3446 */
3447struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003448 uint32_t sensor_num;
3449 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003450} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003451/* This returns no data */
3452
3453/****************************************************************************/
3454
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003455/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003456#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003457
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003458/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003459struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003460 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003461} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003462
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003463/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003464#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3465#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003466
3467/*
3468 * The original TMP006 calibration only needed four params, but now we need
3469 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3470 * the params opaque. The v1 "get" response will include the algorithm number
3471 * and how many params it requires. That way we can change the EC code without
3472 * needing to update this file. We can also use a different algorithm on each
3473 * sensor.
3474 */
3475
3476/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003477struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003478 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003479} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003480
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003481/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003482struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003483 float s0;
3484 float b0;
3485 float b1;
3486 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003487} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003488
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003489struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003490 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003491 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003492 float s0;
3493 float b0;
3494 float b1;
3495 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003496} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003497
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003498/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003499struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003500 uint8_t algorithm;
3501 uint8_t num_params;
3502 uint8_t reserved[2];
3503 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003504} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003505
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003506struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003507 uint8_t index;
3508 uint8_t algorithm;
3509 uint8_t num_params;
3510 uint8_t reserved;
3511 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003512} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003513
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003514
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003515/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003516#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003517
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003518struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003519 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003520} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003521
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003522struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003523 int32_t t; /* In 1/100 K */
3524 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003525} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003526
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003527/*****************************************************************************/
3528/* MKBP - Matrix KeyBoard Protocol */
3529
3530/*
3531 * Read key state
3532 *
3533 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3534 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003535 *
3536 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3537 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3538 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003539 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003540#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003541
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003542/*
3543 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3544 */
3545#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003546
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003547struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003548 uint32_t rows;
3549 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003550 /* Formerly "switches", which was 0. */
3551 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003552} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003553
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003554struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003555 uint8_t info_type;
3556 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003557} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003558
3559enum ec_mkbp_info_type {
3560 /*
3561 * Info about the keyboard matrix: number of rows and columns.
3562 *
3563 * Returns struct ec_response_mkbp_info.
3564 */
3565 EC_MKBP_INFO_KBD = 0,
3566
3567 /*
3568 * For buttons and switches, info about which specifically are
3569 * supported. event_type must be set to one of the values in enum
3570 * ec_mkbp_event.
3571 *
3572 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3573 * bitmask indicating which buttons or switches are present. See the
3574 * bit inidices below.
3575 */
3576 EC_MKBP_INFO_SUPPORTED = 1,
3577
3578 /*
3579 * Instantaneous state of buttons and switches.
3580 *
3581 * event_type must be set to one of the values in enum ec_mkbp_event.
3582 *
3583 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3584 * indicating the current state of the keyboard matrix.
3585 *
3586 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3587 * event state.
3588 *
3589 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3590 * state of supported buttons.
3591 *
3592 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3593 * state of supported switches.
3594 */
3595 EC_MKBP_INFO_CURRENT = 2,
3596};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003597
3598/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003599#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003600
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003601struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003602 uint8_t col;
3603 uint8_t row;
3604 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003605} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003606
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003607#define EC_CMD_GET_KEYBOARD_ID 0x0063
3608
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003609struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003610 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003611} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003612
3613enum keyboard_id {
3614 KEYBOARD_ID_UNSUPPORTED = 0,
3615 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3616};
3617
Duncan Laurie433432b2013-06-03 10:38:22 -07003618/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003619#define EC_CMD_MKBP_SET_CONFIG 0x0064
3620#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003621
3622/* flags */
3623enum mkbp_config_flags {
3624 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3625};
3626
3627enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003628 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3629 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3630 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3631 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3632 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3633 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3634 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003635};
3636
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003637/*
3638 * Configuration for our key scanning algorithm.
3639 *
3640 * Note that this is used as a sub-structure of
3641 * ec_{params/response}_mkbp_get_config.
3642 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003643struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003644 uint32_t valid_mask; /* valid fields */
3645 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3646 uint8_t valid_flags; /* which flags are valid */
3647 uint16_t scan_period_us; /* period between start of scans */
3648 /* revert to interrupt mode after no activity for this long */
3649 uint32_t poll_timeout_us;
3650 /*
3651 * minimum post-scan relax time. Once we finish a scan we check
3652 * the time until we are due to start the next one. If this time is
3653 * shorter this field, we use this instead.
3654 */
3655 uint16_t min_post_scan_delay_us;
3656 /* delay between setting up output and waiting for it to settle */
3657 uint16_t output_settle_us;
3658 uint16_t debounce_down_us; /* time for debounce on key down */
3659 uint16_t debounce_up_us; /* time for debounce on key up */
3660 /* maximum depth to allow for fifo (0 = no keyscan output) */
3661 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003662} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003663
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003664struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003665 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003666} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003667
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003668struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003669 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003670} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003671
3672/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003673#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003674
3675enum ec_keyscan_seq_cmd {
3676 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3677 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3678 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3679 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3680 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3681};
3682
3683enum ec_collect_flags {
3684 /*
3685 * Indicates this scan was processed by the EC. Due to timing, some
3686 * scans may be skipped.
3687 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003688 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003689};
3690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003691struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003692 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003693} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003694
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003695struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003696 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3697 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003698 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003699 uint8_t active; /* still active */
3700 uint8_t num_items; /* number of items */
3701 /* Current item being presented */
3702 uint8_t cur_item;
3703 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003704 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003705 /*
3706 * Absolute time for this scan, measured from the
3707 * start of the sequence.
3708 */
3709 uint32_t time_us;
3710 uint8_t scan[0]; /* keyscan data */
3711 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003712 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003713 uint8_t start_item; /* First item to return */
3714 uint8_t num_items; /* Number of items to return */
3715 } collect;
3716 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003717} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003718
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003719struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003720 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003721 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003722 uint8_t num_items; /* Number of items */
3723 /* Data for each item */
3724 struct ec_collect_item item[0];
3725 } collect;
3726 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003727} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003728
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003729/*
3730 * Get the next pending MKBP event.
3731 *
3732 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3733 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003734#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003735
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003736#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3737
3738/*
3739 * We use the most significant bit of the event type to indicate to the host
3740 * that the EC has more MKBP events available to provide.
3741 */
3742#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3743
3744/* The mask to apply to get the raw event type */
3745#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3746
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003747enum ec_mkbp_event {
3748 /* Keyboard matrix changed. The event data is the new matrix state. */
3749 EC_MKBP_EVENT_KEY_MATRIX = 0,
3750
3751 /* New host event. The event data is 4 bytes of host event flags. */
3752 EC_MKBP_EVENT_HOST_EVENT = 1,
3753
Duncan Laurieeb316852015-12-01 18:51:18 -08003754 /* New Sensor FIFO data. The event data is fifo_info structure. */
3755 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3756
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003757 /* The state of the non-matrixed buttons have changed. */
3758 EC_MKBP_EVENT_BUTTON = 3,
3759
3760 /* The state of the switches have changed. */
3761 EC_MKBP_EVENT_SWITCH = 4,
3762
3763 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3764 EC_MKBP_EVENT_FINGERPRINT = 5,
3765
3766 /*
3767 * Sysrq event: send emulated sysrq. The event data is sysrq,
3768 * corresponding to the key to be pressed.
3769 */
3770 EC_MKBP_EVENT_SYSRQ = 6,
3771
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003772 /*
3773 * New 64-bit host event.
3774 * The event data is 8 bytes of host event flags.
3775 */
3776 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3777
3778 /* Notify the AP that something happened on CEC */
3779 EC_MKBP_EVENT_CEC_EVENT = 8,
3780
3781 /* Send an incoming CEC message to the AP */
3782 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3783
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003784 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3785 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3786
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003787 /* New online calibration values are available. */
3788 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3789
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003790 /* Peripheral device charger event */
3791 EC_MKBP_EVENT_PCHG = 12,
3792
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003793 /* Number of MKBP events */
3794 EC_MKBP_EVENT_COUNT,
3795};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003796BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003797
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003798union __ec_align_offset1 ec_response_get_next_data {
3799 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003800
3801 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003802 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003803 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003804
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003805 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003806 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003807 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003808 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003809 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003810
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003811 uint32_t buttons;
3812
3813 uint32_t switches;
3814
3815 uint32_t fp_events;
3816
3817 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003818
3819 /* CEC events from enum mkbp_cec_event */
3820 uint32_t cec_events;
3821};
3822
3823union __ec_align_offset1 ec_response_get_next_data_v1 {
3824 uint8_t key_matrix[16];
3825
3826 /* Unaligned */
3827 uint32_t host_event;
3828 uint64_t host_event64;
3829
3830 struct __ec_todo_unpacked {
3831 /* For aligning the fifo_info */
3832 uint8_t reserved[3];
3833 struct ec_response_motion_sense_fifo_info info;
3834 } sensor_fifo;
3835
3836 uint32_t buttons;
3837
3838 uint32_t switches;
3839
3840 uint32_t fp_events;
3841
3842 uint32_t sysrq;
3843
3844 /* CEC events from enum mkbp_cec_event */
3845 uint32_t cec_events;
3846
3847 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003848};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003849BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003850
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003851struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003852 uint8_t event_type;
3853 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003854 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003855} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003856
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003857struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003858 uint8_t event_type;
3859 /* Followed by event data if any */
3860 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003861} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003862
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003863/* Bit indices for buttons and switches.*/
3864/* Buttons */
3865#define EC_MKBP_POWER_BUTTON 0
3866#define EC_MKBP_VOL_UP 1
3867#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003868#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003869
3870/* Switches */
3871#define EC_MKBP_LID_OPEN 0
3872#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003873#define EC_MKBP_BASE_ATTACHED 2
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003874#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003875
Gwendal Grignou880b4582016-06-20 08:49:25 -07003876/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003877#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003878
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003879struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003880 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003881} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003882
3883/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3884#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003885#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3886#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3887#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3888 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3889#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3890#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3891#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3892 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003893#define EC_MKBP_FP_ENROLL BIT(27)
3894#define EC_MKBP_FP_MATCH BIT(28)
3895#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3896#define EC_MKBP_FP_FINGER_UP BIT(30)
3897#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003898/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3899#define EC_MKBP_FP_ERR_ENROLL_OK 0
3900#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3901#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3902#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3903#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3904/* Can be used to detect if image was usable for enrollment or not. */
3905#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3906/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3907#define EC_MKBP_FP_ERR_MATCH_NO 0
3908#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003909#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003910#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3911#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3912#define EC_MKBP_FP_ERR_MATCH_YES 1
3913#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3914#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3915
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003916
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003917#define EC_CMD_MKBP_WAKE_MASK 0x0069
3918enum ec_mkbp_event_mask_action {
3919 /* Retrieve the value of a wake mask. */
3920 GET_WAKE_MASK = 0,
3921
3922 /* Set the value of a wake mask. */
3923 SET_WAKE_MASK,
3924};
3925
3926enum ec_mkbp_mask_type {
3927 /*
3928 * These are host events sent via MKBP.
3929 *
3930 * Some examples are:
3931 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3932 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3933 *
3934 * The only things that should be in this mask are:
3935 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3936 */
3937 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3938
3939 /*
3940 * These are MKBP events. Some examples are:
3941 *
3942 * EC_MKBP_EVENT_KEY_MATRIX
3943 * EC_MKBP_EVENT_SWITCH
3944 *
3945 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3946 */
3947 EC_MKBP_EVENT_WAKE_MASK,
3948};
3949
3950struct ec_params_mkbp_event_wake_mask {
3951 /* One of enum ec_mkbp_event_mask_action */
3952 uint8_t action;
3953
3954 /*
3955 * Which MKBP mask are you interested in acting upon? This is one of
3956 * ec_mkbp_mask_type.
3957 */
3958 uint8_t mask_type;
3959
3960 /* If setting a new wake mask, this contains the mask to set. */
3961 uint32_t new_wake_mask;
3962};
3963
3964struct ec_response_mkbp_event_wake_mask {
3965 uint32_t wake_mask;
3966};
3967
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003968/*****************************************************************************/
3969/* Temperature sensor commands */
3970
3971/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003972#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003973
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003974struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003975 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003976} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003977
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003978struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003979 char sensor_name[32];
3980 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003981} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003982
3983/*****************************************************************************/
3984
3985/*
3986 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3987 * commands accidentally sent to the wrong interface. See the ACPI section
3988 * below.
3989 */
3990
3991/*****************************************************************************/
3992/* Host event commands */
3993
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003994
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003995/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003996/*
3997 * Host event mask params and response structures, shared by all of the host
3998 * event commands below.
3999 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004000struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004001 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004002} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004003
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004004struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004005 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004006} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004007
4008/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004009#define EC_CMD_HOST_EVENT_GET_B 0x0087
4010#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4011#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
4012#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004013
4014/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004015#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4016#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4017#define EC_CMD_HOST_EVENT_CLEAR 0x008C
4018#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
4019#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004020
Jenny TC1dfc2c32017-12-14 14:24:39 +05304021/*
4022 * Unified host event programming interface - Should be used by newer versions
4023 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004024 *
4025 * EC returns:
4026 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4027 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304028 */
4029
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004030struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304031
4032 /* Action requested by host - one of enum ec_host_event_action. */
4033 uint8_t action;
4034
4035 /*
4036 * Mask type that the host requested the action on - one of
4037 * enum ec_host_event_mask_type.
4038 */
4039 uint8_t mask_type;
4040
4041 /* Set to 0, ignore on read */
4042 uint16_t reserved;
4043
4044 /* Value to be used in case of set operations. */
4045 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004046} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304047
4048/*
4049 * Response structure returned by EC_CMD_HOST_EVENT.
4050 * Update the value on a GET request. Set to 0 on GET/CLEAR
4051 */
4052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004053struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304054
4055 /* Mask value in case of get operation */
4056 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004057} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304058
4059enum ec_host_event_action {
4060 /*
4061 * params.value is ignored. Value of mask_type populated
4062 * in response.value
4063 */
4064 EC_HOST_EVENT_GET,
4065
4066 /* Bits in params.value are set */
4067 EC_HOST_EVENT_SET,
4068
4069 /* Bits in params.value are cleared */
4070 EC_HOST_EVENT_CLEAR,
4071};
4072
4073enum ec_host_event_mask_type {
4074
4075 /* Main host event copy */
4076 EC_HOST_EVENT_MAIN,
4077
4078 /* Copy B of host events */
4079 EC_HOST_EVENT_B,
4080
4081 /* SCI Mask */
4082 EC_HOST_EVENT_SCI_MASK,
4083
4084 /* SMI Mask */
4085 EC_HOST_EVENT_SMI_MASK,
4086
4087 /* Mask of events that should be always reported in hostevents */
4088 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4089
4090 /* Active wake mask */
4091 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4092
4093 /* Lazy wake mask for S0ix */
4094 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4095
4096 /* Lazy wake mask for S3 */
4097 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4098
4099 /* Lazy wake mask for S5 */
4100 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4101};
4102
4103#define EC_CMD_HOST_EVENT 0x00A4
4104
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004105/*****************************************************************************/
4106/* Switch commands */
4107
4108/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004109#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004110
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004111struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004112 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004113} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004114
4115/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004116#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004117#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004118
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004119/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004120struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004121 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004122} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004123
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004124/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004125struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004126 /* Flags to enable now */
4127 uint8_t now_flags;
4128
4129 /* Which flags to copy from now_flags */
4130 uint8_t now_mask;
4131
4132 /*
4133 * Flags to leave enabled in S3, if they're on at the S0->S3
4134 * transition. (Other flags will be disabled by the S0->S3
4135 * transition.)
4136 */
4137 uint8_t suspend_flags;
4138
4139 /* Which flags to copy from suspend_flags */
4140 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004141} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004142
4143/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004144struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004145 /* Flags to enable now */
4146 uint8_t now_flags;
4147
4148 /* Flags to leave enabled in S3 */
4149 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004150} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004151
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004152/*****************************************************************************/
4153/* GPIO commands. Only available on EC if write protect has been disabled. */
4154
4155/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004156#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004157
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004158struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004159 char name[32];
4160 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004161} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004162
4163/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004164#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004165
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004166/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004167struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004168 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004169} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004170
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004171struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004172 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004173} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004174
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004175/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004176struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004177 uint8_t subcmd;
4178 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004179 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004180 char name[32];
4181 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004182 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004183 uint8_t index;
4184 } get_info;
4185 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004186} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004187
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004188struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004189 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004190 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004191 uint8_t val;
4192 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004193 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004194 uint8_t val;
4195 char name[32];
4196 uint32_t flags;
4197 } get_info;
4198 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004199} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004200
4201enum gpio_get_subcmd {
4202 EC_GPIO_GET_BY_NAME = 0,
4203 EC_GPIO_GET_COUNT = 1,
4204 EC_GPIO_GET_INFO = 2,
4205};
4206
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004207/*****************************************************************************/
4208/* I2C commands. Only available when flash write protect is unlocked. */
4209
Duncan Laurie93e24442014-01-06 12:30:52 -08004210/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004211 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4212 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4213 *
4214 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004215 */
4216
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004217/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004218#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004219
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004220struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004221 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004222 uint8_t read_size; /* Either 8 or 16. */
4223 uint8_t port;
4224 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004225} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004226
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004227struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004228 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004229} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004230
4231/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004232#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004233
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004234struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004235 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004236 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004237 uint8_t write_size; /* Either 8 or 16. */
4238 uint8_t port;
4239 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004240} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004241
4242/*****************************************************************************/
4243/* Charge state commands. Only available when flash write protect unlocked. */
4244
Duncan Laurie93e24442014-01-06 12:30:52 -08004245/* Force charge state machine to stop charging the battery or force it to
4246 * discharge the battery.
4247 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004248#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08004249#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004250
Duncan Laurie93e24442014-01-06 12:30:52 -08004251enum ec_charge_control_mode {
4252 CHARGE_CONTROL_NORMAL = 0,
4253 CHARGE_CONTROL_IDLE,
4254 CHARGE_CONTROL_DISCHARGE,
4255};
4256
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004257struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004258 uint32_t mode; /* enum charge_control_mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004259} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004260
4261/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004262
4263/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004264#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004265
4266/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004267 * Read data from the saved snapshot. If the subcmd parameter is
4268 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4269 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4270 * end of the previous snapshot.
4271 *
4272 * The params are only looked at in version >= 1 of this command. Prior
4273 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004274 *
4275 * Response is null-terminated string. Empty string, if there is no more
4276 * remaining output.
4277 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004278#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004279
Duncan Laurieeb316852015-12-01 18:51:18 -08004280enum ec_console_read_subcmd {
4281 CONSOLE_READ_NEXT = 0,
4282 CONSOLE_READ_RECENT
4283};
4284
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004285struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004286 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004287} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004288
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004289/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004290
4291/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004292 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004293 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004294 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4295 * EC_RES_SUCCESS if the command was successful.
4296 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004297 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004298#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004299
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004300#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004301
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004302struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004303 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004304} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004305
Duncan Laurie433432b2013-06-03 10:38:22 -07004306/*****************************************************************************/
4307/* USB port mux control. */
4308
4309/*
4310 * Switch USB mux or return to automatic switching.
4311 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004312#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004313
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004314struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004315 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004316} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004317
4318/*****************************************************************************/
4319/* LDOs / FETs control. */
4320
4321enum ec_ldo_state {
4322 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4323 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4324};
4325
4326/*
4327 * Switch on/off a LDO.
4328 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004329#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004330
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004331struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004332 uint8_t index;
4333 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004334} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004335
4336/*
4337 * Get LDO state.
4338 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004339#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004340
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004341struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004342 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004343} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004344
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004345struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004346 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004347} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004348
4349/*****************************************************************************/
4350/* Power info. */
4351
4352/*
4353 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004354 *
4355 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004356 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004357#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004358
Jett Rinkba2edaf2020-01-14 11:49:06 -07004359/*
4360 * v1 of EC_CMD_POWER_INFO
4361 */
4362enum system_power_source {
4363 /*
4364 * Haven't established which power source is used yet,
4365 * or no presence signals are available
4366 */
4367 POWER_SOURCE_UNKNOWN = 0,
4368 /* System is running on battery alone */
4369 POWER_SOURCE_BATTERY = 1,
4370 /* System is running on A/C alone */
4371 POWER_SOURCE_AC = 2,
4372 /* System is running on A/C and battery */
4373 POWER_SOURCE_AC_BATTERY = 3,
4374};
4375
4376struct ec_response_power_info_v1 {
4377 /* enum system_power_source */
4378 uint8_t system_power_source;
4379 /* Battery state-of-charge, 0-100, 0 if not present */
4380 uint8_t battery_soc;
4381 /* AC Adapter 100% rating, Watts */
4382 uint8_t ac_adapter_100pct;
4383 /* AC Adapter 10ms rating, Watts */
4384 uint8_t ac_adapter_10ms;
4385 /* Battery 1C rating, derated */
4386 uint8_t battery_1cd;
4387 /* Rest of Platform average, Watts */
4388 uint8_t rop_avg;
4389 /* Rest of Platform peak, Watts */
4390 uint8_t rop_peak;
4391 /* Nominal charger efficiency, % */
4392 uint8_t nominal_charger_eff;
4393 /* Rest of Platform VR Average Efficiency, % */
4394 uint8_t rop_avg_eff;
4395 /* Rest of Platform VR Peak Efficiency, % */
4396 uint8_t rop_peak_eff;
4397 /* SoC VR Efficiency at Average level, % */
4398 uint8_t soc_avg_eff;
4399 /* SoC VR Efficiency at Peak level, % */
4400 uint8_t soc_peak_eff;
4401 /* Intel-specific items */
4402 struct {
4403 /* Battery's level of DBPT support: 0, 2 */
4404 uint8_t batt_dbpt_support_level;
4405 /*
4406 * Maximum peak power from battery (10ms), Watts
4407 * If DBPT is not supported, this is 0
4408 */
4409 uint8_t batt_dbpt_max_peak_power;
4410 /*
4411 * Sustained peak power from battery, Watts
4412 * If DBPT is not supported, this is 0
4413 */
4414 uint8_t batt_dbpt_sus_peak_power;
4415 } intel;
4416} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004417
4418/*****************************************************************************/
4419/* I2C passthru command */
4420
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004421#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004422
Duncan Laurie433432b2013-06-03 10:38:22 -07004423/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004424#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004425
4426/* Mask for address */
4427#define EC_I2C_ADDR_MASK 0x3ff
4428
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004429#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4430#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004431
4432/* Any error */
4433#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4434
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004435struct ec_params_i2c_passthru_msg {
Rob Barnes8bc5fa92021-06-28 09:32:28 -06004436 uint16_t addr_flags; /* I2C peripheral address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004437 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004438} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004440struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004441 uint8_t port; /* I2C port number */
4442 uint8_t num_msgs; /* Number of messages */
4443 struct ec_params_i2c_passthru_msg msg[];
4444 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004445} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004446
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004447struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004448 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4449 uint8_t num_msgs; /* Number of messages processed */
4450 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004451} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004452
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004453/*****************************************************************************/
4454/* Power button hang detect */
4455
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004456#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004457
4458/* Reasons to start hang detection timer */
4459/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004460#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004461
4462/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004463#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004464
4465 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004466#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004467
4468/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004469#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004470
4471/* Reasons to cancel hang detection */
4472
4473/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004474#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004475
4476/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004477#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004478
4479/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004480#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004481
4482/*
4483 * If this flag is set, all the other fields are ignored, and the hang detect
4484 * timer is started. This provides the AP a way to start the hang timer
4485 * without reconfiguring any of the other hang detect settings. Note that
4486 * you must previously have configured the timeouts.
4487 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004488#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004489
4490/*
4491 * If this flag is set, all the other fields are ignored (including
4492 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4493 * without reconfiguring any of the other hang detect settings.
4494 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004495#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004496
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004497struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004498 /* Flags; see EC_HANG_* */
4499 uint32_t flags;
4500
4501 /* Timeout in msec before generating host event, if enabled */
4502 uint16_t host_event_timeout_msec;
4503
4504 /* Timeout in msec before generating warm reboot, if enabled */
4505 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004506} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004507
4508/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004509/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004510
4511/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004512 * This is the single catch-all host command to exchange data regarding the
4513 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004514 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004515#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004516
4517/* Subcommands for this host command */
4518enum charge_state_command {
4519 CHARGE_STATE_CMD_GET_STATE,
4520 CHARGE_STATE_CMD_GET_PARAM,
4521 CHARGE_STATE_CMD_SET_PARAM,
4522 CHARGE_STATE_NUM_CMDS
4523};
4524
4525/*
4526 * Known param numbers are defined here. Ranges are reserved for board-specific
4527 * params, which are handled by the particular implementations.
4528 */
4529enum charge_state_params {
4530 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4531 CS_PARAM_CHG_CURRENT, /* charger current limit */
4532 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4533 CS_PARAM_CHG_STATUS, /* charger-specific status */
4534 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004535 CS_PARAM_LIMIT_POWER, /*
4536 * Check if power is limited due to
4537 * low battery and / or a weak external
4538 * charger. READ ONLY.
4539 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004540 /* How many so far? */
4541 CS_NUM_BASE_PARAMS,
4542
4543 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4544 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4545 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4546
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004547 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4548 CS_PARAM_DEBUG_MIN = 0x20000,
4549 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4550 CS_PARAM_DEBUG_MANUAL_MODE,
4551 CS_PARAM_DEBUG_SEEMS_DEAD,
4552 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4553 CS_PARAM_DEBUG_BATT_REMOVED,
4554 CS_PARAM_DEBUG_MANUAL_CURRENT,
4555 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4556 CS_PARAM_DEBUG_MAX = 0x2ffff,
4557
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004558 /* Other custom param ranges go here... */
4559};
4560
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004561struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004562 uint8_t cmd; /* enum charge_state_command */
4563 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004564 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004565
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004566 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004567 uint32_t param; /* enum charge_state_param */
4568 } get_param;
4569
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004570 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004571 uint32_t param; /* param to set */
4572 uint32_t value; /* value to set */
4573 } set_param;
4574 };
Yidi Lin42f79592020-09-21 18:04:10 +08004575 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004576} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004577
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004578struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004579 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004580 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004581 int ac;
4582 int chg_voltage;
4583 int chg_current;
4584 int chg_input_current;
4585 int batt_state_of_charge;
4586 } get_state;
4587
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004588 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004589 uint32_t value;
4590 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004591
4592 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004593 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004594} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004595
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004596
Duncan Laurie433432b2013-06-03 10:38:22 -07004597/*
4598 * Set maximum battery charging current.
4599 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004600#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004601
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004602struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004603 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004604} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004605
4606/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004607 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004608 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004609#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004610
Duncan Laurieeb316852015-12-01 18:51:18 -08004611/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004612struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004613 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4614 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004615} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004616
Duncan Laurieeb316852015-12-01 18:51:18 -08004617#define EC_POWER_LIMIT_NONE 0xffff
4618
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004619/*
4620 * Set maximum voltage & current of a dedicated charge port
4621 */
4622#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4623
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004624struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004625 uint16_t current_lim; /* in mA */
4626 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004627} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004628
Duncan Laurieeb316852015-12-01 18:51:18 -08004629/*****************************************************************************/
4630/* Hibernate/Deep Sleep Commands */
4631
4632/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004633#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004634
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004635struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004636 /*
4637 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4638 * current settings without changing them.
4639 */
4640 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004641} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004642
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004643struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004644 /*
4645 * The current time in seconds in which the system has been in the G3
4646 * state. This value is reset if the EC transitions out of G3.
4647 */
4648 uint32_t time_g3;
4649
4650 /*
4651 * The current time remaining in seconds until the EC should hibernate.
4652 * This value is also reset if the EC transitions out of G3.
4653 */
4654 uint32_t time_remaining;
4655
4656 /*
4657 * The current time in seconds that the EC should wait in G3 before
4658 * hibernating.
4659 */
4660 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004661} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004662
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004663/* Inform the EC when entering a sleep state */
4664#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4665
4666enum host_sleep_event {
4667 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4668 HOST_SLEEP_EVENT_S3_RESUME = 2,
4669 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004670 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4671 /* S3 suspend with additional enabled wake sources */
4672 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004673};
4674
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004675struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004676 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004677} __ec_align1;
4678
4679/*
4680 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4681 * transition failures
4682 */
4683#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4684
4685/* Disable timeout detection for this sleep transition */
4686#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4687
4688struct ec_params_host_sleep_event_v1 {
4689 /* The type of sleep being entered or exited. */
4690 uint8_t sleep_event;
4691
4692 /* Padding */
4693 uint8_t reserved;
4694 union {
4695 /* Parameters that apply for suspend messages. */
4696 struct {
4697 /*
4698 * The timeout in milliseconds between when this message
4699 * is received and when the EC will declare sleep
4700 * transition failure if the sleep signal is not
4701 * asserted.
4702 */
4703 uint16_t sleep_timeout_ms;
4704 } suspend_params;
4705
4706 /* No parameters for non-suspend messages. */
4707 };
4708} __ec_align2;
4709
4710/* A timeout occurred when this bit is set */
4711#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4712
4713/*
4714 * The mask defining which bits correspond to the number of sleep transitions,
4715 * as well as the maximum number of suspend line transitions that will be
4716 * reported back to the host.
4717 */
4718#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4719
4720struct ec_response_host_sleep_event_v1 {
4721 union {
4722 /* Response fields that apply for resume messages. */
4723 struct {
4724 /*
4725 * The number of sleep power signal transitions that
4726 * occurred since the suspend message. The high bit
4727 * indicates a timeout occurred.
4728 */
4729 uint32_t sleep_transitions;
4730 } resume_response;
4731
4732 /* No response fields for non-resume messages. */
4733 };
4734} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004735
4736/*****************************************************************************/
4737/* Device events */
4738#define EC_CMD_DEVICE_EVENT 0x00AA
4739
4740enum ec_device_event {
4741 EC_DEVICE_EVENT_TRACKPAD,
4742 EC_DEVICE_EVENT_DSP,
4743 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004744 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004745};
4746
4747enum ec_device_event_param {
4748 /* Get and clear pending device events */
4749 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4750 /* Get device event mask */
4751 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4752 /* Set device event mask */
4753 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4754};
4755
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004756#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004757
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004758struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004759 uint32_t event_mask;
4760 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004761} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004762
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004763struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004764 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004765} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004766
Duncan Laurie433432b2013-06-03 10:38:22 -07004767/*****************************************************************************/
4768/* Smart battery pass-through */
4769
4770/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004771#define EC_CMD_SB_READ_WORD 0x00B0
4772#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004773
4774/* Get / Set string smart battery parameters
4775 * formatted as SMBUS "block".
4776 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004777#define EC_CMD_SB_READ_BLOCK 0x00B2
4778#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004779
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004780struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004781 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004782} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004783
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004784struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004785 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004786} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004787
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004788struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004789 uint8_t reg;
4790 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004791} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004792
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004793struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004794 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004795} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004796
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004797struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004798 uint8_t reg;
4799 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004800} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004801
4802/*****************************************************************************/
4803/* Battery vendor parameters
4804 *
4805 * Get or set vendor-specific parameters in the battery. Implementations may
4806 * differ between boards or batteries. On a set operation, the response
4807 * contains the actual value set, which may be rounded or clipped from the
4808 * requested value.
4809 */
4810
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004811#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004812
4813enum ec_battery_vendor_param_mode {
4814 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4815 BATTERY_VENDOR_PARAM_MODE_SET,
4816};
4817
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004818struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004819 uint32_t param;
4820 uint32_t value;
4821 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004822} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004823
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004824struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004825 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004826} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004827
4828/*****************************************************************************/
4829/*
4830 * Smart Battery Firmware Update Commands
4831 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004832#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004833
4834enum ec_sb_fw_update_subcmd {
4835 EC_SB_FW_UPDATE_PREPARE = 0x0,
4836 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4837 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4838 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4839 EC_SB_FW_UPDATE_END = 0x4,
4840 EC_SB_FW_UPDATE_STATUS = 0x5,
4841 EC_SB_FW_UPDATE_PROTECT = 0x6,
4842 EC_SB_FW_UPDATE_MAX = 0x7,
4843};
4844
4845#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4846#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4847#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4848
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004849struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004850 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4851 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004852} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004853
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004854struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004855 struct ec_sb_fw_update_header hdr;
4856 union {
4857 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4858 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4859 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4860 /* EC_SB_FW_UPDATE_END = 0x4 */
4861 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4862 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004863 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004864
4865 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004866 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004867 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4868 } write;
4869 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004870} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004871
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004872struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004873 union {
4874 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004875 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004876 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4877 } info;
4878
4879 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004880 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004881 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4882 } status;
4883 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004884} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004885
4886/*
4887 * Entering Verified Boot Mode Command
4888 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4889 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004890 *
4891 * EC no longer needs to know what mode vboot has entered,
4892 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004893 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004894#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004895
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004896struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004897 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004898} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004899
4900#define VBOOT_MODE_NORMAL 0
4901#define VBOOT_MODE_DEVELOPER 1
4902#define VBOOT_MODE_RECOVERY 2
4903
Duncan Laurie433432b2013-06-03 10:38:22 -07004904/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004905/*
4906 * I2C passthru protection command: Protects I2C tunnels against access on
4907 * certain addresses (board-specific).
4908 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004909#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004910
4911enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004912 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
4913 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
4914 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07004915};
4916
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004917struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004918 uint8_t subcmd;
4919 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004920} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004921
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004922struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004923 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004924} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004925
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004926
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004927/*****************************************************************************/
4928/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004929 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004930 *
4931 * These commands are for sending and receiving message via HDMI CEC
4932 */
4933
4934#define MAX_CEC_MSG_LEN 16
4935
4936/* CEC message from the AP to be written on the CEC bus */
4937#define EC_CMD_CEC_WRITE_MSG 0x00B8
4938
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004939/**
4940 * struct ec_params_cec_write - Message to write to the CEC bus
4941 * @msg: message content to write to the CEC bus
4942 */
4943struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004944 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004945} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004946
4947/* Set various CEC parameters */
4948#define EC_CMD_CEC_SET 0x00BA
4949
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004950/**
4951 * struct ec_params_cec_set - CEC parameters set
4952 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4953 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4954 * or 1 to enable CEC functionality, in case cmd is
4955 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4956 * address between 0 and 15 or 0xff to unregister
4957 */
4958struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004959 uint8_t cmd; /* enum cec_command */
4960 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004961} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004962
4963/* Read various CEC parameters */
4964#define EC_CMD_CEC_GET 0x00BB
4965
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004966/**
4967 * struct ec_params_cec_get - CEC parameters get
4968 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4969 */
4970struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004971 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004972} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004973
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004974/**
4975 * struct ec_response_cec_get - CEC parameters get response
4976 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4977 * disabled or 1 if CEC functionality is enabled,
4978 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4979 * configured logical address between 0 and 15 or 0xff if unregistered
4980 */
4981struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004982 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004983} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004984
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004985/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004986enum cec_command {
4987 /* CEC reading, writing and events enable */
4988 CEC_CMD_ENABLE,
4989 /* CEC logical address */
4990 CEC_CMD_LOGICAL_ADDRESS,
4991};
4992
4993/* Events from CEC to AP */
4994enum mkbp_cec_event {
4995 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004996 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004997 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004998 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004999};
5000
Gwendal Grignou880b4582016-06-20 08:49:25 -07005001/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005002
Jett Rinkba2edaf2020-01-14 11:49:06 -07005003/* Commands for audio codec. */
5004#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005005
Jett Rinkba2edaf2020-01-14 11:49:06 -07005006enum ec_codec_subcmd {
5007 EC_CODEC_GET_CAPABILITIES = 0x0,
5008 EC_CODEC_GET_SHM_ADDR = 0x1,
5009 EC_CODEC_SET_SHM_ADDR = 0x2,
5010 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005011};
5012
Jett Rinkba2edaf2020-01-14 11:49:06 -07005013enum ec_codec_cap {
5014 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5015 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5016 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005017};
5018
Jett Rinkba2edaf2020-01-14 11:49:06 -07005019enum ec_codec_shm_id {
5020 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5021 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5022 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005023};
5024
Jett Rinkba2edaf2020-01-14 11:49:06 -07005025enum ec_codec_shm_type {
5026 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5027 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005028};
5029
Jett Rinkba2edaf2020-01-14 11:49:06 -07005030struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5031 uint8_t shm_id;
5032 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005033};
5034
Jett Rinkba2edaf2020-01-14 11:49:06 -07005035struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5036 uint64_t phys_addr;
5037 uint32_t len;
5038 uint8_t shm_id;
5039 uint8_t reserved[3];
5040};
5041
5042struct __ec_align4 ec_param_ec_codec {
5043 uint8_t cmd; /* enum ec_codec_subcmd */
5044 uint8_t reserved[3];
5045
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005046 union {
Jett Rinkba2edaf2020-01-14 11:49:06 -07005047 struct ec_param_ec_codec_get_shm_addr
5048 get_shm_addr_param;
5049 struct ec_param_ec_codec_set_shm_addr
5050 set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005051 };
5052};
5053
Jett Rinkba2edaf2020-01-14 11:49:06 -07005054struct __ec_align4 ec_response_ec_codec_get_capabilities {
5055 uint32_t capabilities;
5056};
5057
5058struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5059 uint64_t phys_addr;
5060 uint32_t len;
5061 uint8_t type;
5062 uint8_t reserved[3];
5063};
5064
5065/*****************************************************************************/
5066
5067/* Commands for DMIC on audio codec. */
5068#define EC_CMD_EC_CODEC_DMIC 0x00BD
5069
5070enum ec_codec_dmic_subcmd {
5071 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5072 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5073 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5074 EC_CODEC_DMIC_SUBCMD_COUNT,
5075};
5076
5077enum ec_codec_dmic_channel {
5078 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5079 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5080 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5081 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5082 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5083 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5084 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5085 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5086 EC_CODEC_DMIC_CHANNEL_COUNT,
5087};
5088
5089struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5090 uint8_t channel; /* enum ec_codec_dmic_channel */
5091 uint8_t gain;
5092 uint8_t reserved[2];
5093};
5094
5095struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5096 uint8_t channel; /* enum ec_codec_dmic_channel */
5097 uint8_t reserved[3];
5098};
5099
5100struct __ec_align4 ec_param_ec_codec_dmic {
5101 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5102 uint8_t reserved[3];
5103
5104 union {
5105 struct ec_param_ec_codec_dmic_set_gain_idx
5106 set_gain_idx_param;
5107 struct ec_param_ec_codec_dmic_get_gain_idx
5108 get_gain_idx_param;
5109 };
5110};
5111
5112struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5113 uint8_t max_gain;
5114};
5115
5116struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5117 uint8_t gain;
5118};
5119
5120/*****************************************************************************/
5121
5122/* Commands for I2S RX on audio codec. */
5123
5124#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5125
5126enum ec_codec_i2s_rx_subcmd {
5127 EC_CODEC_I2S_RX_ENABLE = 0x0,
5128 EC_CODEC_I2S_RX_DISABLE = 0x1,
5129 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5130 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5131 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005132 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005133 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5134};
5135
5136enum ec_codec_i2s_rx_sample_depth {
5137 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5138 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5139 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5140};
5141
5142enum ec_codec_i2s_rx_daifmt {
5143 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5144 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5145 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5146 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5147};
5148
5149struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5150 uint8_t depth;
5151 uint8_t reserved[3];
5152};
5153
5154struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5155 uint8_t left;
5156 uint8_t right;
5157 uint8_t reserved[2];
5158};
5159
5160struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5161 uint8_t daifmt;
5162 uint8_t reserved[3];
5163};
5164
5165struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5166 uint32_t bclk;
5167};
5168
5169struct __ec_align4 ec_param_ec_codec_i2s_rx {
5170 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5171 uint8_t reserved[3];
5172
5173 union {
5174 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5175 set_sample_depth_param;
5176 struct ec_param_ec_codec_i2s_rx_set_daifmt
5177 set_daifmt_param;
5178 struct ec_param_ec_codec_i2s_rx_set_bclk
5179 set_bclk_param;
5180 };
5181};
5182
5183/*****************************************************************************/
5184/* Commands for WoV on audio codec. */
5185
5186#define EC_CMD_EC_CODEC_WOV 0x00BF
5187
5188enum ec_codec_wov_subcmd {
5189 EC_CODEC_WOV_SET_LANG = 0x0,
5190 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5191 EC_CODEC_WOV_GET_LANG = 0x2,
5192 EC_CODEC_WOV_ENABLE = 0x3,
5193 EC_CODEC_WOV_DISABLE = 0x4,
5194 EC_CODEC_WOV_READ_AUDIO = 0x5,
5195 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5196 EC_CODEC_WOV_SUBCMD_COUNT,
5197};
5198
5199/*
5200 * @hash is SHA256 of the whole language model.
5201 * @total_len indicates the length of whole language model.
5202 * @offset is the cursor from the beginning of the model.
5203 * @buf is the packet buffer.
5204 * @len denotes how many bytes in the buf.
5205 */
5206struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5207 uint8_t hash[32];
5208 uint32_t total_len;
5209 uint32_t offset;
5210 uint8_t buf[128];
5211 uint32_t len;
5212};
5213
5214struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5215 uint8_t hash[32];
5216 uint32_t total_len;
5217};
5218
5219struct __ec_align4 ec_param_ec_codec_wov {
5220 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5221 uint8_t reserved[3];
5222
5223 union {
5224 struct ec_param_ec_codec_wov_set_lang
5225 set_lang_param;
5226 struct ec_param_ec_codec_wov_set_lang_shm
5227 set_lang_shm_param;
5228 };
5229};
5230
5231struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5232 uint8_t hash[32];
5233};
5234
5235struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5236 uint8_t buf[128];
5237 uint32_t len;
5238};
5239
5240struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5241 uint32_t offset;
5242 uint32_t len;
5243};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005244
5245/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005246/* Commands for PoE PSE controller */
5247
5248#define EC_CMD_PSE 0x00C0
5249
5250enum ec_pse_subcmd {
5251 EC_PSE_STATUS = 0x0,
5252 EC_PSE_ENABLE = 0x1,
5253 EC_PSE_DISABLE = 0x2,
5254 EC_PSE_SUBCMD_COUNT,
5255};
5256
5257struct __ec_align1 ec_params_pse {
5258 uint8_t cmd; /* enum ec_pse_subcmd */
5259 uint8_t port; /* PSE port */
5260};
5261
5262enum ec_pse_status {
5263 EC_PSE_STATUS_DISABLED = 0x0,
5264 EC_PSE_STATUS_ENABLED = 0x1,
5265 EC_PSE_STATUS_POWERED = 0x2,
5266};
5267
5268struct __ec_align1 ec_response_pse_status {
5269 uint8_t status; /* enum ec_pse_status */
5270};
5271
5272/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005273/* System commands */
5274
5275/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005276 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5277 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005278 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005279#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005280
5281/* Command */
5282enum ec_reboot_cmd {
5283 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005284 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005285 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005286 /* (command 3 was jump to RW-B) */
5287 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005288 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08005289 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Yidi Lin42f79592020-09-21 18:04:10 +08005290 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_IDLE flag */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005291 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005292};
5293
5294/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005295#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5296#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5297#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005298
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005299struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005300 uint8_t cmd; /* enum ec_reboot_cmd */
5301 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005302} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005303
Duncan Laurie433432b2013-06-03 10:38:22 -07005304/*
5305 * Get information on last EC panic.
5306 *
5307 * Returns variable-length platform-dependent panic information. See panic.h
5308 * for details.
5309 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005310#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005311
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005312/*****************************************************************************/
5313/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005314 * Special commands
5315 *
5316 * These do not follow the normal rules for commands. See each command for
5317 * details.
5318 */
5319
5320/*
5321 * Reboot NOW
5322 *
5323 * This command will work even when the EC LPC interface is busy, because the
5324 * reboot command is processed at interrupt level. Note that when the EC
5325 * reboots, the host will reboot too, so there is no response to this command.
5326 *
5327 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5328 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005329#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005330
5331/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005332 * Resend last response (not supported on LPC).
5333 *
5334 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5335 * there was no previous command, or the previous command's response was too
5336 * big to save.
5337 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005338#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005339
5340/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005341 * This header byte on a command indicate version 0. Any header byte less
5342 * than this means that we are talking to an old EC which doesn't support
5343 * versioning. In that case, we assume version 0.
5344 *
5345 * Header bytes greater than this indicate a later version. For example,
5346 * EC_CMD_VERSION0 + 1 means we are using version 1.
5347 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005348 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005349 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005350#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005351
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005352/*****************************************************************************/
5353/*
5354 * PD commands
5355 *
5356 * These commands are for PD MCU communication.
5357 */
5358
5359/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005360#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005361#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005362
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005363enum pd_charge_state {
5364 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
5365 PD_CHARGE_NONE, /* No charging allowed */
5366 PD_CHARGE_5V, /* 5V charging only */
5367 PD_CHARGE_MAX /* Charge at max voltage */
5368};
5369
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005370/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005371#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005372
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005373struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005374 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005375 int8_t batt_soc; /* battery state of charge */
5376 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005377} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005378
5379/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005380#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5381#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
5382#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
5383#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5384#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5385#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5386#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08005387#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
5388 PD_STATUS_TCPC_ALERT_1 | \
5389 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005390struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005391 uint32_t curr_lim_ma; /* input current limit */
5392 uint16_t status; /* PD MCU status */
5393 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005394} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005395
5396/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005397#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005398
5399/* PD MCU host event status bits */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005400#define PD_EVENT_UPDATE_DEVICE BIT(0)
5401#define PD_EVENT_POWER_CHANGE BIT(1)
5402#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5403#define PD_EVENT_DATA_SWAP BIT(3)
5404#define PD_EVENT_TYPEC BIT(4)
5405
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005406struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005407 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005408} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005409
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005410/*
5411 * Set USB type-C port role and muxes
5412 *
5413 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5414 *
5415 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5416 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005417#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005418
5419enum usb_pd_control_role {
5420 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5421 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5422 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5423 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5424 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005425 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005426 USB_PD_CTRL_ROLE_COUNT
5427};
5428
5429enum usb_pd_control_mux {
5430 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5431 USB_PD_CTRL_MUX_NONE = 1,
5432 USB_PD_CTRL_MUX_USB = 2,
5433 USB_PD_CTRL_MUX_DP = 3,
5434 USB_PD_CTRL_MUX_DOCK = 4,
5435 USB_PD_CTRL_MUX_AUTO = 5,
5436 USB_PD_CTRL_MUX_COUNT
5437};
5438
Duncan Laurieeb316852015-12-01 18:51:18 -08005439enum usb_pd_control_swap {
5440 USB_PD_CTRL_SWAP_NONE = 0,
5441 USB_PD_CTRL_SWAP_DATA = 1,
5442 USB_PD_CTRL_SWAP_POWER = 2,
5443 USB_PD_CTRL_SWAP_VCONN = 3,
5444 USB_PD_CTRL_SWAP_COUNT
5445};
5446
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005447struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005448 uint8_t port;
5449 uint8_t role;
5450 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005451 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005452} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005453
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005454#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5455#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
5456#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005457
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005458#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5459#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5460#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5461#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5462#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5463#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005464#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */
Duncan Laurieeb316852015-12-01 18:51:18 -08005465
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005466struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005467 uint8_t enabled;
5468 uint8_t role;
5469 uint8_t polarity;
5470 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005471} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005472
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005473struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005474 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005475 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005476 uint8_t polarity;
5477 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005478} __ec_align1;
5479
Jett Rinkba2edaf2020-01-14 11:49:06 -07005480/* Possible port partner connections based on CC line states */
5481enum pd_cc_states {
5482 PD_CC_NONE = 0, /* No port partner attached */
5483
5484 /* From DFP perspective */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005485 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005486 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5487 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5488 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
5489
5490 /* From UFP perspective */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005491 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005492 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005493};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005494
Jett Rinkba2edaf2020-01-14 11:49:06 -07005495/* Active/Passive Cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005496#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005497/* Optical/Non-optical cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005498#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005499/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005500#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
5501/* Active Link Uni-Direction */
5502#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005503
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005504struct ec_response_usb_pd_control_v2 {
5505 uint8_t enabled;
5506 uint8_t role;
5507 uint8_t polarity;
5508 char state[32];
Jett Rinkba2edaf2020-01-14 11:49:06 -07005509 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5510 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005511 uint8_t reserved; /* Reserved for future use */
5512 uint8_t control_flags; /* USB_PD_CTRL_*flags */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005513 uint8_t cable_speed; /* TBT_SS_* cable speed */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005514 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005515} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005516
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005517#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005518
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005519/* Maximum number of PD ports on a device, num_ports will be <= this */
5520#define EC_USB_PD_MAX_PORTS 8
5521
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005522struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005523 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005524} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005525
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005526#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005527
5528#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005529struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005530 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005531} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005532
5533enum usb_chg_type {
5534 USB_CHG_TYPE_NONE,
5535 USB_CHG_TYPE_PD,
5536 USB_CHG_TYPE_C,
5537 USB_CHG_TYPE_PROPRIETARY,
5538 USB_CHG_TYPE_BC12_DCP,
5539 USB_CHG_TYPE_BC12_CDP,
5540 USB_CHG_TYPE_BC12_SDP,
5541 USB_CHG_TYPE_OTHER,
5542 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005543 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005544 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005545};
5546enum usb_power_roles {
5547 USB_PD_PORT_POWER_DISCONNECTED,
5548 USB_PD_PORT_POWER_SOURCE,
5549 USB_PD_PORT_POWER_SINK,
5550 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5551};
5552
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005553struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005554 uint16_t voltage_max;
5555 uint16_t voltage_now;
5556 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005557 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005558} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005559
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005560struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005561 uint8_t role;
5562 uint8_t type;
5563 uint8_t dualrole;
5564 uint8_t reserved1;
5565 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005566 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005567} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005568
Yidi Lin42f79592020-09-21 18:04:10 +08005569
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005570/*
5571 * This command will return the number of USB PD charge port + the number
5572 * of dedicated port present.
5573 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5574 */
5575#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005576struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005577 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005578} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005579
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005580/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005581#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005582
5583enum usb_pd_fw_update_cmds {
5584 USB_PD_FW_REBOOT,
5585 USB_PD_FW_FLASH_ERASE,
5586 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005587 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005588};
5589
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005590struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005591 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005592 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005593 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005594 uint32_t size; /* Size to write in bytes */
5595 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005596} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005597
5598/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005599#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005600/* RW hash is first 20 bytes of SHA-256 of RW section */
5601#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005602struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005603 uint16_t dev_id;
5604 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005605 uint8_t reserved; /*
5606 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005607 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005608 * Should have been reserved[2].
5609 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005610 uint32_t current_image; /* One of ec_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005611} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005612
5613/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005614#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005615
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005616struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005617 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005618} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005619
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005620/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005621#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005622struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005623 uint16_t vid; /* USB-IF VID */
5624 uint16_t pid; /* USB-IF PID */
5625 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005626} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005627
5628/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005629#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005630
5631/* Negative port parameters have special meaning */
5632enum usb_pd_override_ports {
5633 OVERRIDE_DONT_CHARGE = -2,
5634 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005635 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005636};
5637
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005638struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005639 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005640} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005641
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005642/*
5643 * Read (and delete) one entry of PD event log.
5644 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5645 * future non-PD logs that use the same internal EC event_log.
5646 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005647#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005648
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005649struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005650 uint32_t timestamp; /* relative timestamp in milliseconds */
5651 uint8_t type; /* event type : see PD_EVENT_xx below */
5652 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5653 uint16_t data; /* type-defined data payload */
5654 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005655} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005656
5657/* The timestamp is the microsecond counter shifted to get about a ms. */
5658#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5659
Duncan Laurieeb316852015-12-01 18:51:18 -08005660#define PD_LOG_SIZE_MASK 0x1f
5661#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005662#define PD_LOG_PORT_SHIFT 5
5663#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5664 ((size) & PD_LOG_SIZE_MASK))
5665#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5666#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5667
5668/* PD event log : entry types */
5669/* PD MCU events */
5670#define PD_EVENT_MCU_BASE 0x00
5671#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5672#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5673/* Reserved for custom board event */
5674#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5675/* PD generic accessory events */
5676#define PD_EVENT_ACC_BASE 0x20
5677#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5678#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5679/* PD power supply events */
5680#define PD_EVENT_PS_BASE 0x40
5681#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5682/* PD video dongles events */
5683#define PD_EVENT_VIDEO_BASE 0x60
5684#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5685#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5686/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005687#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005688
5689/*
5690 * PD_EVENT_MCU_CHARGE event definition :
5691 * the payload is "struct usb_chg_measures"
5692 * the data field contains the port state flags as defined below :
5693 */
5694/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005695#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005696/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005697#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005698/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005699#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005700/* Charger type */
5701#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005702#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005703/* Power delivery role */
5704#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5705
5706/*
5707 * PD_EVENT_PS_FAULT data field flags definition :
5708 */
5709#define PS_FAULT_OCP 1
5710#define PS_FAULT_FAST_OCP 2
5711#define PS_FAULT_OVP 3
5712#define PS_FAULT_DISCH 4
5713
5714/*
5715 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5716 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005717struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005718 uint8_t major;
5719 uint8_t minor;
5720 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005721} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005722
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005723struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005724 uint8_t family[2];
5725 uint8_t chipid[2];
5726 struct mcdp_version irom;
5727 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005728} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005729
5730/* struct mcdp_info field decoding */
5731#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5732#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5733
5734/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005735#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005736struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005737 uint16_t svid_idx; /* SVID index to get */
5738 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005739} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005740
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005741struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005742 uint16_t svid; /* SVID */
5743 uint16_t opos; /* Object Position */
5744 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005745} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005746
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005747#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005748
5749enum pd_mode_cmd {
5750 PD_EXIT_MODE = 0,
5751 PD_ENTER_MODE = 1,
5752 /* Not a command. Do NOT remove. */
5753 PD_MODE_CMD_COUNT,
5754};
5755
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005756struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005757 uint32_t cmd; /* enum pd_mode_cmd */
5758 uint16_t svid; /* SVID to set */
5759 uint8_t opos; /* Object Position */
5760 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005761} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005762
5763/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005764#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005765
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005766struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005767 uint8_t type; /* event type : see PD_EVENT_xx above */
5768 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005769} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005770
Yidi Lin42f79592020-09-21 18:04:10 +08005771
Gwendal Grignou880b4582016-06-20 08:49:25 -07005772/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005773#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005774
5775enum ec_pd_control_cmd {
5776 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5777 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5778 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005779 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5780 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005781};
5782
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005783struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005784 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005785 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005786} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005787
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005788/* Get info about USB-C SS muxes */
5789#define EC_CMD_USB_PD_MUX_INFO 0x011A
5790
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005791struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005792 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005793} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005794
5795/* Flags representing mux state */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005796#define USB_PD_MUX_NONE 0 /* Open switch */
5797#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5798#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5799#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5800#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5801#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
5802#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
5803#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005804#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
5805
5806/* USB-C Dock connected */
5807#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005808
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005809struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005810 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005811} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005812
5813#define EC_CMD_PD_CHIP_INFO 0x011B
5814
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005815struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005816 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005817 /*
5818 * Fetch the live chip info or hard-coded + cached chip info
5819 * 0: hardcoded value for VID/PID, cached value for FW version
5820 * 1: live chip value for VID/PID/FW Version
5821 */
5822 uint8_t live;
5823} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005824
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005825struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005826 uint16_t vendor_id;
5827 uint16_t product_id;
5828 uint16_t device_id;
5829 union {
5830 uint8_t fw_version_string[8];
5831 uint64_t fw_version_number;
5832 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005833} __ec_align2;
5834
5835struct ec_response_pd_chip_info_v1 {
5836 uint16_t vendor_id;
5837 uint16_t product_id;
5838 uint16_t device_id;
5839 union {
5840 uint8_t fw_version_string[8];
5841 uint64_t fw_version_number;
5842 };
5843 union {
5844 uint8_t min_req_fw_version_string[8];
5845 uint64_t min_req_fw_version_number;
5846 };
5847} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005848
5849/* Run RW signature verification and get status */
5850#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005852struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005853 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005854} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005855
5856/* For controlling RWSIG task */
5857#define EC_CMD_RWSIG_ACTION 0x011D
5858
5859enum rwsig_action {
5860 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5861 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5862};
5863
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005864struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005865 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005866} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005867
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005868/* Run verification on a slot */
5869#define EC_CMD_EFS_VERIFY 0x011E
5870
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005871struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005872 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005873} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005874
5875/*
5876 * Retrieve info from Cros Board Info store. Response is based on the data
5877 * type. Integers return a uint32. Strings return a string, using the response
5878 * size to determine how big it is.
5879 */
5880#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5881/*
5882 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5883 * hardware write-protect enabled.
5884 */
5885#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5886
Daisuke Nojirif984a052018-02-15 12:38:15 -08005887enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005888 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5889 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5890 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005891 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005892 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005893 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005894 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005895 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08005896 /* Second Source Factory Cache */
5897 CBI_TAG_SSFC = 8, /* uint32_t bit field */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06005898 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005899 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005900};
5901
5902/*
5903 * Flags to control read operation
5904 *
5905 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5906 * write was successful without reboot.
5907 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005908#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005909
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005910struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005911 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005912 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005913} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005914
5915/*
5916 * Flags to control write behavior.
5917 *
5918 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5919 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005920 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005921 * will be initialized to zero first.
5922 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005923#define CBI_SET_NO_SYNC BIT(0)
5924#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005925
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005926struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08005927 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005928 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005929 uint32_t size; /* Data size */
5930 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005931} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005932
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005933/*
5934 * Information about resets of the AP by the EC and the EC's own uptime.
5935 */
5936#define EC_CMD_GET_UPTIME_INFO 0x0121
5937
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005938/* EC reset causes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005939#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
5940#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
5941#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
5942#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
5943#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
5944#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
5945#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
5946#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
5947#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
5948#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
5949#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
5950#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
5951#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
5952#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
5953 * previous boot
5954 */
5955#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
5956#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
5957#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
5958#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
5959#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005960#define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This
5961 * enables PD in RO for Chromebox.
5962 */
Yidi Lin42f79592020-09-21 18:04:10 +08005963#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
5964#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
5965#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005966
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005967/*
5968 * Reason codes used by the AP after a shutdown to figure out why it was reset
5969 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
5970 * compatibility:
5971 * - New entries must be inserted prior to the _COUNT field
5972 * - If an existing entry is no longer in service, it must be replaced with a
5973 * RESERVED entry instead.
5974 * - The semantic meaning of an entry should not change.
5975 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
5976 */
5977enum chipset_reset_reason {
5978 CHIPSET_RESET_BEGIN = 0,
5979 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
5980 /* Custom reason defined by a board.c or baseboard.c file */
5981 CHIPSET_RESET_BOARD_CUSTOM,
5982 /* Believe that the AP has hung */
5983 CHIPSET_RESET_HANG_REBOOT,
5984 /* Reset by EC console command */
5985 CHIPSET_RESET_CONSOLE_CMD,
5986 /* Reset by EC host command */
5987 CHIPSET_RESET_HOST_CMD,
5988 /* Keyboard module reset key combination */
5989 CHIPSET_RESET_KB_SYSRESET,
5990 /* Keyboard module warm reboot */
5991 CHIPSET_RESET_KB_WARM_REBOOT,
5992 /* Debug module warm reboot */
5993 CHIPSET_RESET_DBG_WARM_REBOOT,
5994 /* I cannot self-terminate. You must lower me into the steel. */
5995 CHIPSET_RESET_AP_REQ,
5996 /* Reset as side-effect of startup sequence */
5997 CHIPSET_RESET_INIT,
5998 /* EC detected an AP watchdog event. */
5999 CHIPSET_RESET_AP_WATCHDOG,
6000
6001 CHIPSET_RESET_COUNT,
6002};
6003
6004/*
6005 * AP hard shutdowns are logged on the same path as resets.
6006 */
6007enum chipset_shutdown_reason {
6008 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6009 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6010 /* Forcing a shutdown as part of EC initialization */
6011 CHIPSET_SHUTDOWN_INIT,
6012 /* Custom reason on a per-board basis. */
6013 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6014 /* This is a reason to inhibit startup, not cause shut down. */
6015 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6016 /* A power_wait_signal is being asserted */
6017 CHIPSET_SHUTDOWN_WAIT,
6018 /* Critical battery level. */
6019 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6020 /* Because you told me to. */
6021 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6022 /* Forcing a shutdown to effect entry to G3. */
6023 CHIPSET_SHUTDOWN_G3,
6024 /* Force shutdown due to over-temperature. */
6025 CHIPSET_SHUTDOWN_THERMAL,
6026 /* Force a chipset shutdown from the power button through EC */
6027 CHIPSET_SHUTDOWN_BUTTON,
6028
6029 CHIPSET_SHUTDOWN_COUNT,
6030};
6031
6032
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006033struct ec_response_uptime_info {
6034 /*
6035 * Number of milliseconds since the last EC boot. Sysjump resets
6036 * typically do not restart the EC's time_since_boot epoch.
6037 *
6038 * WARNING: The EC's sense of time is much less accurate than the AP's
6039 * sense of time, in both phase and frequency. This timebase is similar
6040 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6041 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006042 uint32_t time_since_ec_boot_ms;
6043
6044 /*
6045 * Number of times the AP was reset by the EC since the last EC boot.
6046 * Note that the AP may be held in reset by the EC during the initial
6047 * boot sequence, such that the very first AP boot may count as more
6048 * than one here.
6049 */
6050 uint32_t ap_resets_since_ec_boot;
6051
6052 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006053 * The set of flags which describe the EC's most recent reset.
6054 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006055 */
6056 uint32_t ec_reset_flags;
6057
6058 /* Empty log entries have both the cause and timestamp set to zero. */
6059 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006060 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006061 uint16_t reset_cause;
6062
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006063 /* Reserved for protocol growth. */
6064 uint16_t reserved;
6065
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006066 /*
6067 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006068 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6069 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006070 */
6071 uint32_t reset_time_ms;
6072 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006073} __ec_align4;
6074
6075/*
6076 * Add entropy to the device secret (stored in the rollback region).
6077 *
6078 * Depending on the chip, the operation may take a long time (e.g. to erase
6079 * flash), so the commands are asynchronous.
6080 */
6081#define EC_CMD_ADD_ENTROPY 0x0122
6082
6083enum add_entropy_action {
6084 /* Add entropy to the current secret. */
6085 ADD_ENTROPY_ASYNC = 0,
6086 /*
6087 * Add entropy, and also make sure that the previous secret is erased.
6088 * (this can be implemented by adding entropy multiple times until
6089 * all rolback blocks have been overwritten).
6090 */
6091 ADD_ENTROPY_RESET_ASYNC = 1,
6092 /* Read back result from the previous operation. */
6093 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006094};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006095
6096struct ec_params_rollback_add_entropy {
6097 uint8_t action;
6098} __ec_align1;
6099
6100/*
6101 * Perform a single read of a given ADC channel.
6102 */
6103#define EC_CMD_ADC_READ 0x0123
6104
6105struct ec_params_adc_read {
6106 uint8_t adc_channel;
6107} __ec_align1;
6108
6109struct ec_response_adc_read {
6110 int32_t adc_value;
6111} __ec_align4;
6112
6113/*
6114 * Read back rollback info
6115 */
6116#define EC_CMD_ROLLBACK_INFO 0x0124
6117
6118struct ec_response_rollback_info {
6119 int32_t id; /* Incrementing number to indicate which region to use. */
6120 int32_t rollback_min_version;
6121 int32_t rw_rollback_version;
6122} __ec_align4;
6123
Yidi Lin42f79592020-09-21 18:04:10 +08006124
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006125/* Issue AP reset */
6126#define EC_CMD_AP_RESET 0x0125
6127
6128/*****************************************************************************/
6129/* Locate peripheral chips
6130 *
6131 * Return values:
6132 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6133 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6134 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6135 */
6136#define EC_CMD_LOCATE_CHIP 0x0126
6137
6138enum ec_chip_type {
6139 EC_CHIP_TYPE_CBI_EEPROM = 0,
6140 EC_CHIP_TYPE_TCPC = 1,
6141 EC_CHIP_TYPE_COUNT,
6142 EC_CHIP_TYPE_MAX = 0xFF,
6143};
6144
6145enum ec_bus_type {
6146 EC_BUS_TYPE_I2C = 0,
6147 EC_BUS_TYPE_EMBEDDED = 1,
6148 EC_BUS_TYPE_COUNT,
6149 EC_BUS_TYPE_MAX = 0xFF,
6150};
6151
6152struct ec_i2c_info {
6153 uint16_t port; /* Physical port for device */
6154 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
6155};
6156
6157struct ec_params_locate_chip {
6158 uint8_t type; /* enum ec_chip_type */
6159 uint8_t index; /* Specifies one instance of chip type */
6160 /* Used for type specific parameters in future */
6161 union {
6162 uint16_t reserved;
6163 };
6164} __ec_align2;
6165
Yidi Lin42f79592020-09-21 18:04:10 +08006166
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006167struct ec_response_locate_chip {
6168 uint8_t bus_type; /* enum ec_bus_type */
6169 uint8_t reserved; /* Aligning the following union to 2 bytes */
6170 union {
6171 struct ec_i2c_info i2c_info;
6172 };
6173} __ec_align2;
6174
Jett Rinkba2edaf2020-01-14 11:49:06 -07006175/*
6176 * Reboot AP on G3
6177 *
6178 * This command is used for validation purpose, where the AP needs to be
6179 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006180 * wake events.
6181 * - With command version 0:
6182 * AP reboots immediately from G3
6183 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6184 * - With command version 1:
6185 * AP reboots after the user specified delay
6186 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006187 */
6188#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6189
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006190struct ec_params_reboot_ap_on_g3_v1 {
6191 /* configurable delay in seconds in G3 state */
6192 uint32_t reboot_ap_at_g3_delay;
6193} __ec_align4;
6194
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006195/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006196/* Get PD port capabilities
6197 *
6198 * Returns the following static *capabilities* of the given port:
6199 * 1) Power role: source, sink, or dual. It is not anticipated that
6200 * future CrOS devices would ever be only a source, so the options are
6201 * sink or dual.
6202 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6203 * believe any CrOS device would support Try.SNK, so this would be source
6204 * or none).
6205 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6206 * for CrOS devices.
6207 */
6208#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6209
6210enum ec_pd_power_role_caps {
6211 EC_PD_POWER_ROLE_SOURCE = 0,
6212 EC_PD_POWER_ROLE_SINK = 1,
6213 EC_PD_POWER_ROLE_DUAL = 2,
6214};
6215
6216enum ec_pd_try_power_role_caps {
6217 EC_PD_TRY_POWER_ROLE_NONE = 0,
6218 EC_PD_TRY_POWER_ROLE_SINK = 1,
6219 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6220};
6221
6222enum ec_pd_data_role_caps {
6223 EC_PD_DATA_ROLE_DFP = 0,
6224 EC_PD_DATA_ROLE_UFP = 1,
6225 EC_PD_DATA_ROLE_DUAL = 2,
6226};
6227
6228/* From: power_manager/power_supply_properties.proto */
6229enum ec_pd_port_location {
6230 /* The location of the port is unknown, or there's only one port. */
6231 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6232
6233 /*
6234 * Various positions on the device. The first word describes the side of
6235 * the device where the port is located while the second clarifies the
6236 * position. For example, LEFT_BACK means the farthest-back port on the
6237 * left side, while BACK_LEFT means the leftmost port on the back of the
6238 * device.
6239 */
6240 EC_PD_PORT_LOCATION_LEFT = 1,
6241 EC_PD_PORT_LOCATION_RIGHT = 2,
6242 EC_PD_PORT_LOCATION_BACK = 3,
6243 EC_PD_PORT_LOCATION_FRONT = 4,
6244 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6245 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
6246 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
6247 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6248 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6249 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
6250};
6251
6252struct ec_params_get_pd_port_caps {
6253 uint8_t port; /* Which port to interrogate */
6254} __ec_align1;
6255
6256struct ec_response_get_pd_port_caps {
6257 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6258 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6259 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6260 uint8_t pd_port_location; /* enum ec_pd_port_location */
6261} __ec_align1;
6262
6263/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006264/*
6265 * Button press simulation
6266 *
6267 * This command is used to simulate a button press.
6268 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6269 * Time duration for which button needs to be pressed is an optional parameter.
6270 *
6271 * NOTE: This is only available on unlocked devices for testing purposes only.
6272 */
6273#define EC_CMD_BUTTON 0x0129
6274
6275struct ec_params_button {
6276 /* Button mask aligned to enum keyboard_button_type */
6277 uint32_t btn_mask;
6278
6279 /* Duration in milliseconds button needs to be pressed */
6280 uint32_t press_ms;
6281} __ec_align1;
6282
6283enum keyboard_button_type {
6284 KEYBOARD_BUTTON_POWER = 0,
6285 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
6286 KEYBOARD_BUTTON_VOLUME_UP = 2,
6287 KEYBOARD_BUTTON_RECOVERY = 3,
6288 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6289 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6290 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6291 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6292 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6293 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6294 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6295 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
6296
6297 KEYBOARD_BUTTON_COUNT
6298};
Yidi Lin42f79592020-09-21 18:04:10 +08006299
Rajat Jainc0495722020-04-02 23:58:35 -07006300/*****************************************************************************/
6301/*
6302 * "Get the Keyboard Config". An EC implementing this command is expected to be
6303 * vivaldi capable, i.e. can send action codes for the top row keys.
6304 * Additionally, capability to send function codes for the same keys is
6305 * optional and acceptable.
6306 *
6307 * Note: If the top row can generate both function and action codes by
6308 * using a dedicated Fn key, it does not matter whether the key sends
6309 * "function" or "action" codes by default. In both cases, the response
6310 * for this command will look the same.
6311 */
6312#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6313
6314/* Possible values for the top row keys */
6315enum action_key {
6316 TK_ABSENT = 0,
6317 TK_BACK = 1,
6318 TK_FORWARD = 2,
6319 TK_REFRESH = 3,
6320 TK_FULLSCREEN = 4,
6321 TK_OVERVIEW = 5,
6322 TK_BRIGHTNESS_DOWN = 6,
6323 TK_BRIGHTNESS_UP = 7,
6324 TK_VOL_MUTE = 8,
6325 TK_VOL_DOWN = 9,
6326 TK_VOL_UP = 10,
6327 TK_SNAPSHOT = 11,
6328 TK_PRIVACY_SCRN_TOGGLE = 12,
6329 TK_KBD_BKLIGHT_DOWN = 13,
6330 TK_KBD_BKLIGHT_UP = 14,
6331 TK_PLAY_PAUSE = 15,
6332 TK_NEXT_TRACK = 16,
6333 TK_PREV_TRACK = 17,
6334};
6335
6336/*
6337 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6338 * If this needs to change, please create a new version of the command.
6339 */
6340#define MAX_TOP_ROW_KEYS 15
6341#define MIN_TOP_ROW_KEYS 10
6342
6343/*
6344 * Is the keyboard capable of sending function keys *in addition to*
6345 * action keys. This is possible for e.g. if the keyboard has a
6346 * dedicated Fn key.
6347 */
6348#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
6349/*
6350 * Whether the keyboard has a dedicated numeric keyboard.
6351 */
6352#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
6353/*
6354 * Whether the keyboard has a screenlock key.
6355 */
6356#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
6357
6358struct ec_response_keybd_config {
6359 /*
6360 * Number of top row keys, excluding Esc and Screenlock.
6361 * If this is 0, all Vivaldi keyboard code is disabled.
6362 * (i.e. does not expose any tables to the kernel).
6363 */
6364 uint8_t num_top_row_keys;
6365
6366 /*
6367 * The action keys in the top row, in order from left to right.
6368 * The values are filled from enum action_key. Esc and Screenlock
6369 * keys are not considered part of top row keys.
6370 */
6371 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6372
6373 /* Capability flags */
6374 uint8_t capabilities;
6375
6376} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006377
Yidi Lin42f79592020-09-21 18:04:10 +08006378/*
6379 * Configure smart discharge
6380 */
6381#define EC_CMD_SMART_DISCHARGE 0x012B
6382
6383#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
6384
6385/* Discharge rates when the system is in cutoff or hibernation. */
6386struct discharge_rate {
6387 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6388 uint16_t hibern; /* Discharge rate (uA) in hibernation */
6389};
6390
6391struct smart_discharge_zone {
6392 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6393 int cutoff;
6394 /* When the capacity (mAh) is below this, EC stays up. */
6395 int stayup;
6396};
6397
6398struct ec_params_smart_discharge {
6399 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
6400 /*
6401 * Desired hours for the battery to survive before reaching 0%. Set to
6402 * zero to disable smart discharging. That is, the system hibernates as
6403 * soon as the G3 idle timer expires.
6404 */
6405 uint16_t hours_to_zero;
6406 /* Set both to zero to keep the current rates. */
6407 struct discharge_rate drate;
6408};
6409
6410struct ec_response_smart_discharge {
6411 uint16_t hours_to_zero;
6412 struct discharge_rate drate;
6413 struct smart_discharge_zone dzone;
6414};
6415
6416/*****************************************************************************/
6417/* Voltage regulator controls */
6418
6419/*
6420 * Get basic info of voltage regulator for given index.
6421 *
6422 * Returns the regulator name and supported voltage list in mV.
6423 */
6424#define EC_CMD_REGULATOR_GET_INFO 0x012C
6425
6426/* Maximum length of regulator name */
6427#define EC_REGULATOR_NAME_MAX_LEN 16
6428
6429/* Maximum length of the supported voltage list. */
6430#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6431
6432struct ec_params_regulator_get_info {
6433 uint32_t index;
6434} __ec_align4;
6435
6436struct ec_response_regulator_get_info {
6437 char name[EC_REGULATOR_NAME_MAX_LEN];
6438 uint16_t num_voltages;
6439 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6440} __ec_align2;
6441
6442/*
6443 * Configure the regulator as enabled / disabled.
6444 */
6445#define EC_CMD_REGULATOR_ENABLE 0x012D
6446
6447struct ec_params_regulator_enable {
6448 uint32_t index;
6449 uint8_t enable;
6450} __ec_align4;
6451
6452/*
6453 * Query if the regulator is enabled.
6454 *
6455 * Returns 1 if the regulator is enabled, 0 if not.
6456 */
6457#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6458
6459struct ec_params_regulator_is_enabled {
6460 uint32_t index;
6461} __ec_align4;
6462
6463struct ec_response_regulator_is_enabled {
6464 uint8_t enabled;
6465} __ec_align1;
6466
6467/*
6468 * Set voltage for the voltage regulator within the range specified.
6469 *
6470 * The driver should select the voltage in range closest to min_mv.
6471 *
6472 * Also note that this might be called before the regulator is enabled, and the
6473 * setting should be in effect after the regulator is enabled.
6474 */
6475#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6476
6477struct ec_params_regulator_set_voltage {
6478 uint32_t index;
6479 uint32_t min_mv;
6480 uint32_t max_mv;
6481} __ec_align4;
6482
6483/*
6484 * Get the currently configured voltage for the voltage regulator.
6485 *
6486 * Note that this might be called before the regulator is enabled, and this
6487 * should return the configured output voltage if the regulator is enabled.
6488 */
6489#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6490
6491struct ec_params_regulator_get_voltage {
6492 uint32_t index;
6493} __ec_align4;
6494
6495struct ec_response_regulator_get_voltage {
6496 uint32_t voltage_mv;
6497} __ec_align4;
6498
6499/*
6500 * Gather all discovery information for the given port and partner type.
6501 *
6502 * Note that if discovery has not yet completed, only the currently completed
6503 * responses will be filled in. If the discovery data structures are changed
6504 * in the process of the command running, BUSY will be returned.
6505 *
6506 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6507 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6508 * maximum parameter size.
6509 */
6510#define EC_CMD_TYPEC_DISCOVERY 0x0131
6511
6512enum typec_partner_type {
6513 TYPEC_PARTNER_SOP = 0,
6514 TYPEC_PARTNER_SOP_PRIME = 1,
6515};
6516
6517struct ec_params_typec_discovery {
6518 uint8_t port;
6519 uint8_t partner_type; /* enum typec_partner_type */
6520} __ec_align1;
6521
6522struct svid_mode_info {
6523 uint16_t svid;
6524 uint16_t mode_count; /* Number of modes partner sent */
6525 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6526};
6527
6528struct ec_response_typec_discovery {
6529 uint8_t identity_count; /* Number of identity VDOs partner sent */
6530 uint8_t svid_count; /* Number of SVIDs partner sent */
6531 uint16_t reserved;
6532 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6533 struct svid_mode_info svids[0];
6534} __ec_align1;
6535
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006536/* USB Type-C commands for AP-controlled device policy. */
6537#define EC_CMD_TYPEC_CONTROL 0x0132
6538
6539enum typec_control_command {
6540 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6541 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006542 TYPEC_CONTROL_COMMAND_ENTER_MODE,
6543};
6544
6545/* Modes (USB or alternate) that a type-C port may enter. */
6546enum typec_mode {
6547 TYPEC_MODE_DP,
6548 TYPEC_MODE_TBT,
6549 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006550};
6551
6552struct ec_params_typec_control {
6553 uint8_t port;
6554 uint8_t command; /* enum typec_control_command */
6555 uint16_t reserved;
6556
6557 /*
6558 * This section will be interpreted based on |command|. Define a
6559 * placeholder structure to avoid having to increase the size and bump
6560 * the command version when adding new sub-commands.
6561 */
6562 union {
6563 uint32_t clear_events_mask;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006564 uint8_t mode_to_enter; /* enum typec_mode */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006565 uint8_t placeholder[128];
6566 };
6567} __ec_align1;
6568
6569/*
6570 * Gather all status information for a port.
6571 *
6572 * Note: this covers many of the return fields from the deprecated
6573 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6574 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6575 * EC_CMD_USB_PD_CONTROL command.
6576 *
6577 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006578 */
6579#define EC_CMD_TYPEC_STATUS 0x0133
6580
6581/*
6582 * Power role.
6583 *
6584 * Note this is also used for PD header creation, and values align to those in
6585 * the Power Delivery Specification Revision 3.0 (See
6586 * 6.2.1.1.4 Port Power Role).
6587 */
6588enum pd_power_role {
6589 PD_ROLE_SINK = 0,
6590 PD_ROLE_SOURCE = 1
6591};
6592
6593/*
6594 * Data role.
6595 *
6596 * Note this is also used for PD header creation, and the first two values
6597 * align to those in the Power Delivery Specification Revision 3.0 (See
6598 * 6.2.1.1.6 Port Data Role).
6599 */
6600enum pd_data_role {
6601 PD_ROLE_UFP = 0,
6602 PD_ROLE_DFP = 1,
6603 PD_ROLE_DISCONNECTED = 2,
6604};
6605
6606enum pd_vconn_role {
6607 PD_ROLE_VCONN_OFF = 0,
6608 PD_ROLE_VCONN_SRC = 1,
6609};
6610
6611/*
6612 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6613 * regardless of whether a debug accessory is connected.
6614 */
6615enum tcpc_cc_polarity {
6616 /*
6617 * _CCx: is used to indicate the polarity while not connected to
6618 * a Debug Accessory. Only one CC line will assert a resistor and
6619 * the other will be open.
6620 */
6621 POLARITY_CC1 = 0,
6622 POLARITY_CC2 = 1,
6623
6624 /*
6625 * _CCx_DTS is used to indicate the polarity while connected to a
6626 * SRC Debug Accessory. Assert resistors on both lines.
6627 */
6628 POLARITY_CC1_DTS = 2,
6629 POLARITY_CC2_DTS = 3,
6630
6631 /*
6632 * The current TCPC code relies on these specific POLARITY values.
6633 * Adding in a check to verify if the list grows for any reason
6634 * that this will give a hint that other places need to be
6635 * adjusted.
6636 */
6637 POLARITY_COUNT
6638};
6639
6640#define MODE_DP_PIN_A BIT(0)
6641#define MODE_DP_PIN_B BIT(1)
6642#define MODE_DP_PIN_C BIT(2)
6643#define MODE_DP_PIN_D BIT(3)
6644#define MODE_DP_PIN_E BIT(4)
6645#define MODE_DP_PIN_F BIT(5)
6646#define MODE_DP_PIN_ALL GENMASK(5, 0)
6647
6648#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6649#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006650#define PD_STATUS_EVENT_HARD_RESET BIT(2)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006651
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006652/*
6653 * Encode and decode for BCD revision response
6654 *
6655 * Note: the major revision set is written assuming that the value given is the
6656 * Specification Revision from the PD header, which currently only maps to PD
6657 * 1.0-3.0 with the major revision being one greater than the binary value.
6658 */
6659#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6660#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6661#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
6662
6663/*
6664 * Decode helpers for Source and Sink Capability PDOs
6665 *
6666 * Note: The Power Delivery Specification should be considered the ultimate
6667 * source of truth on the decoding of these PDOs
6668 */
6669#define PDO_TYPE_FIXED (0 << 30)
6670#define PDO_TYPE_BATTERY (1 << 30)
6671#define PDO_TYPE_VARIABLE (2 << 30)
6672#define PDO_TYPE_AUGMENTED (3 << 30)
6673#define PDO_TYPE_MASK (3 << 30)
6674
6675/*
6676 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6677 *
6678 * <31:30> : Fixed Supply
6679 * <29> : Dual-Role Power
6680 * <28> : SNK/SRC dependent
6681 * <27> : Unconstrained Power
6682 * <26> : USB Communications Capable
6683 * <25> : Dual-Role Data
6684 * <24:20> : SNK/SRC dependent
6685 * <19:10> : Voltage in 50mV Units
6686 * <9:0> : Maximum Current in 10mA units
6687 */
6688#define PDO_FIXED_DUAL_ROLE BIT(29)
6689#define PDO_FIXED_UNCONSTRAINED BIT(27)
6690#define PDO_FIXED_COMM_CAP BIT(26)
6691#define PDO_FIXED_DATA_SWAP BIT(25)
6692#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
6693#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6694#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
6695
6696/*
6697 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
6698 *
6699 * <31:30> : Battery
6700 * <29:20> : Maximum Voltage in 50mV units
6701 * <19:10> : Minimum Voltage in 50mV units
6702 * <9:0> : Maximum Allowable Power in 250mW units
6703 */
6704#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6705#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6706#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
6707
6708/*
6709 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
6710 *
6711 * <31:30> : Variable Supply (non-Battery)
6712 * <29:20> : Maximum Voltage in 50mV units
6713 * <19:10> : Minimum Voltage in 50mV units
6714 * <9:0> : Operational Current in 10mA units
6715 */
6716#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6717#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6718#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
6719
6720/*
6721 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
6722 *
6723 * Note this type is reserved in PD 2.0, and only one type of APDO is
6724 * supported as of the cited version.
6725 *
6726 * <31:30> : Augmented Power Data Object
6727 * <29:28> : Programmable Power Supply
6728 * <27> : PPS Power Limited
6729 * <26:25> : Reserved
6730 * <24:17> : Maximum Voltage in 100mV increments
6731 * <16> : Reserved
6732 * <15:8> : Minimum Voltage in 100mV increments
6733 * <7> : Reserved
6734 * <6:0> : Maximum Current in 50mA increments
6735 */
6736#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
6737#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
6738#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
6739
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006740struct ec_params_typec_status {
6741 uint8_t port;
6742} __ec_align1;
6743
6744struct ec_response_typec_status {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006745 uint8_t pd_enabled; /* PD communication enabled - bool */
6746 uint8_t dev_connected; /* Device connected - bool */
6747 uint8_t sop_connected; /* Device is SOP PD capable - bool */
6748 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006749
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006750 uint8_t power_role; /* enum pd_power_role */
6751 uint8_t data_role; /* enum pd_data_role */
6752 uint8_t vconn_role; /* enum pd_vconn_role */
6753 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006754
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006755 uint8_t polarity; /* enum tcpc_cc_polarity */
6756 uint8_t cc_state; /* enum pd_cc_states */
6757 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
6758 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006759
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006760 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006761
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006762 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006763
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006764 /*
6765 * BCD PD revisions for partners
6766 *
6767 * The format has the PD major reversion in the upper nibble, and PD
6768 * minor version in the next nibble. Following two nibbles are
6769 * currently 0.
6770 * ex. PD 3.2 would map to 0x3200
6771 *
6772 * PD major/minor will be 0 if no PD device is connected.
6773 */
6774 uint16_t sop_revision;
6775 uint16_t sop_prime_revision;
6776
6777 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
6778
6779 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006780} __ec_align1;
6781
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006782/**
6783 * Get the number of peripheral charge ports
6784 */
6785#define EC_CMD_PCHG_COUNT 0x0134
6786
6787#define EC_PCHG_MAX_PORTS 8
6788
6789struct ec_response_pchg_count {
6790 uint8_t port_count;
6791} __ec_align1;
6792
6793/**
6794 * Get the status of a peripheral charge port
6795 */
6796#define EC_CMD_PCHG 0x0135
6797
6798struct ec_params_pchg {
6799 uint8_t port;
6800} __ec_align1;
6801
6802struct ec_response_pchg {
6803 uint32_t error; /* enum pchg_error */
6804 uint8_t state; /* enum pchg_state state */
6805 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006806 uint8_t unused0;
6807 uint8_t unused1;
6808 /* Fields added in version 1 */
6809 uint32_t fw_version;
6810 uint32_t dropped_event_count;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006811} __ec_align2;
6812
6813enum pchg_state {
6814 /* Charger is reset and not initialized. */
6815 PCHG_STATE_RESET = 0,
6816 /* Charger is initialized or disabled. */
6817 PCHG_STATE_INITIALIZED,
6818 /* Charger is enabled and ready to detect a device. */
6819 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006820 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006821 PCHG_STATE_DETECTED,
6822 /* Device is being charged. */
6823 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006824 /* Device is fully charged. It implies DETECTED (& not charging). */
6825 PCHG_STATE_FULL,
6826 /* In download (a.k.a. firmware update) mode */
6827 PCHG_STATE_DOWNLOAD,
6828 /* In download mode. Ready for receiving data. */
6829 PCHG_STATE_DOWNLOADING,
6830 /* Device is ready for data communication. */
6831 PCHG_STATE_CONNECTED,
6832 /* Put no more entry below */
6833 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006834};
6835
6836#define EC_PCHG_STATE_TEXT { \
6837 [PCHG_STATE_RESET] = "RESET", \
6838 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
6839 [PCHG_STATE_ENABLED] = "ENABLED", \
6840 [PCHG_STATE_DETECTED] = "DETECTED", \
6841 [PCHG_STATE_CHARGING] = "CHARGING", \
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006842 [PCHG_STATE_FULL] = "FULL", \
6843 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
6844 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
6845 [PCHG_STATE_CONNECTED] = "CONNECTED", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006846 }
6847
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006848/**
6849 * Update firmware of peripheral chip
6850 */
6851#define EC_CMD_PCHG_UPDATE 0x0136
6852
6853/* Port number is encoded in bit[28:31]. */
6854#define EC_MKBP_PCHG_PORT_SHIFT 28
6855/* Utility macro for converting MKBP event to port number. */
6856#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
6857/* Utility macro for extracting event bits. */
6858#define EC_MKBP_PCHG_EVENT_MASK(e) ((e) \
6859 & GENMASK(EC_MKBP_PCHG_PORT_SHIFT-1, 0))
6860
6861#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
6862#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
6863#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
6864#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
6865
6866enum ec_pchg_update_cmd {
6867 /* Reset chip to normal mode. */
6868 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
6869 /* Reset and put a chip in update (a.k.a. download) mode. */
6870 EC_PCHG_UPDATE_CMD_OPEN,
6871 /* Write a block of data containing FW image. */
6872 EC_PCHG_UPDATE_CMD_WRITE,
6873 /* Close update session. */
6874 EC_PCHG_UPDATE_CMD_CLOSE,
6875 /* End of commands */
6876 EC_PCHG_UPDATE_CMD_COUNT,
6877};
6878
6879struct ec_params_pchg_update {
6880 /* PCHG port number */
6881 uint8_t port;
6882 /* enum ec_pchg_update_cmd */
6883 uint8_t cmd;
6884 /* Padding */
6885 uint8_t reserved0;
6886 uint8_t reserved1;
6887 /* Version of new firmware */
6888 uint32_t version;
6889 /* CRC32 of new firmware */
6890 uint32_t crc32;
6891 /* Address in chip memory where <data> is written to */
6892 uint32_t addr;
6893 /* Size of <data> */
6894 uint32_t size;
6895 /* Partial data of new firmware */
6896 uint8_t data[];
6897} __ec_align4;
6898
6899BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT
6900 < BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd)*8));
6901
6902struct ec_response_pchg_update {
6903 /* Block size */
6904 uint32_t block_size;
6905} __ec_align4;
6906
6907
6908#define EC_CMD_DISPLAY_SOC 0x0137
6909
6910struct ec_response_display_soc {
6911 int16_t display_soc; /* Display charge in 10ths of a % (1000=100.0%) */
6912 int16_t full_factor; /* Full factor in 10ths of a % (1000=100.0%) */
6913 int16_t shutdown_soc; /* Shutdown SoC in 10ths of a % (1000=100.0%) */
6914} __ec_align2;
6915
6916
6917#define EC_CMD_SET_BASE_STATE 0x0138
6918
6919struct ec_params_set_base_state {
6920 uint8_t cmd; /* enum ec_set_base_state_cmd */
6921} __ec_align1;
6922
6923enum ec_set_base_state_cmd {
6924 EC_SET_BASE_STATE_DETACH = 0,
6925 EC_SET_BASE_STATE_ATTACH,
6926 EC_SET_BASE_STATE_RESET,
6927};
6928
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006929/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006930/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08006931
6932/*****************************************************************************/
6933/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006934 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08006935 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006936#define EC_CMD_CR51_BASE 0x0300
6937#define EC_CMD_CR51_LAST 0x03FF
6938
6939/*****************************************************************************/
6940/* Fingerprint MCU commands: range 0x0400-0x040x */
6941
6942/* Fingerprint SPI sensor passthru command: prototyping ONLY */
6943#define EC_CMD_FP_PASSTHRU 0x0400
6944
6945#define EC_FP_FLAG_NOT_COMPLETE 0x1
6946
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006947struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006948 uint16_t len; /* Number of bytes to write then read */
6949 uint16_t flags; /* EC_FP_FLAG_xxx */
6950 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006951} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006952
6953/* Configure the Fingerprint MCU behavior */
6954#define EC_CMD_FP_MODE 0x0402
6955
6956/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006957#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006958/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006959#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006960/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006961#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006962/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006963#define FP_MODE_CAPTURE BIT(3)
6964/* Finger enrollment session on-going */
6965#define FP_MODE_ENROLL_SESSION BIT(4)
6966/* Enroll the current finger image */
6967#define FP_MODE_ENROLL_IMAGE BIT(5)
6968/* Try to match the current finger image */
6969#define FP_MODE_MATCH BIT(6)
6970/* Reset and re-initialize the sensor. */
6971#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08006972/* Sensor maintenance for dead pixels. */
6973#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006974/* special value: don't change anything just read back current mode */
6975#define FP_MODE_DONT_CHANGE BIT(31)
6976
6977#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
6978 FP_MODE_FINGER_DOWN | \
6979 FP_MODE_FINGER_UP | \
6980 FP_MODE_CAPTURE | \
6981 FP_MODE_ENROLL_SESSION | \
6982 FP_MODE_ENROLL_IMAGE | \
6983 FP_MODE_MATCH | \
6984 FP_MODE_RESET_SENSOR | \
Yidi Lin42f79592020-09-21 18:04:10 +08006985 FP_MODE_SENSOR_MAINTENANCE | \
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006986 FP_MODE_DONT_CHANGE)
6987
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006988/* Capture types defined in bits [30..28] */
6989#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006990#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
6991/*
6992 * This enum must remain ordered, if you add new values you must ensure that
6993 * FP_CAPTURE_TYPE_MAX is still the last one.
6994 */
6995enum fp_capture_type {
6996 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
6997 FP_CAPTURE_VENDOR_FORMAT = 0,
6998 /* Simple raw image capture (produces width x height x bpp bits) */
6999 FP_CAPTURE_SIMPLE_IMAGE = 1,
7000 /* Self test pattern (e.g. checkerboard) */
7001 FP_CAPTURE_PATTERN0 = 2,
7002 /* Self test pattern (e.g. inverted checkerboard) */
7003 FP_CAPTURE_PATTERN1 = 3,
7004 /* Capture for Quality test with fixed contrast */
7005 FP_CAPTURE_QUALITY_TEST = 4,
7006 /* Capture for pixel reset value test */
7007 FP_CAPTURE_RESET_TEST = 5,
7008 FP_CAPTURE_TYPE_MAX,
7009};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007010/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007011#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
7012 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007013
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007014struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007015 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007016} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007017
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007018struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007019 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007020} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007021
7022/* Retrieve Fingerprint sensor information */
7023#define EC_CMD_FP_INFO 0x0403
7024
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007025/* Number of dead pixels detected on the last maintenance */
7026#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007027/* Unknown number of dead pixels detected on the last maintenance */
7028#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007029/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007030#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007031/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007032#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007033/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007034#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007035/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007036#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007037
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007038struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007039 /* Sensor identification */
7040 uint32_t vendor_id;
7041 uint32_t product_id;
7042 uint32_t model_id;
7043 uint32_t version;
7044 /* Image frame characteristics */
7045 uint32_t frame_size;
7046 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7047 uint16_t width;
7048 uint16_t height;
7049 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007050 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007051} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007053struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007054 /* Sensor identification */
7055 uint32_t vendor_id;
7056 uint32_t product_id;
7057 uint32_t model_id;
7058 uint32_t version;
7059 /* Image frame characteristics */
7060 uint32_t frame_size;
7061 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7062 uint16_t width;
7063 uint16_t height;
7064 uint16_t bpp;
7065 uint16_t errors; /* see FP_ERROR_ flags above */
7066 /* Template/finger current information */
7067 uint32_t template_size; /* max template size in bytes */
7068 uint16_t template_max; /* maximum number of fingers/templates */
7069 uint16_t template_valid; /* number of valid fingers/templates */
7070 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007071 uint32_t template_version; /* version of the template format */
7072} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007073
7074/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007075#define EC_CMD_FP_FRAME 0x0404
7076
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007077/* constants defining the 'offset' field which also contains the frame index */
7078#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007079/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007080#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007081/* First frame buffer holding a template */
7082#define FP_FRAME_INDEX_TEMPLATE 1
7083#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007084#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
7085
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007086/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007087#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007088
7089/* Constants for encryption parameters */
7090#define FP_CONTEXT_NONCE_BYTES 12
7091#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7092#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007093#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007094#define FP_CONTEXT_TPM_BYTES 32
7095
Jett Rinkba2edaf2020-01-14 11:49:06 -07007096/* Constants for positive match parameters. */
7097#define FP_POSITIVE_MATCH_SALT_BYTES 16
7098
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007099struct ec_fp_template_encryption_metadata {
7100 /*
7101 * Version of the structure format (N=3).
7102 */
7103 uint16_t struct_version;
7104 /* Reserved bytes, set to 0. */
7105 uint16_t reserved;
7106 /*
7107 * The salt is *only* ever used for key derivation. The nonce is unique,
7108 * a different one is used for every message.
7109 */
7110 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007111 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007112 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7113};
7114
7115struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007116 /*
7117 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7118 * in the high nibble, and the real offset within the frame in
7119 * FP_FRAME_OFFSET_MASK.
7120 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007121 uint32_t offset;
7122 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007123} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007124
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007125/* Load a template into the MCU */
7126#define EC_CMD_FP_TEMPLATE 0x0405
7127
7128/* Flag in the 'size' field indicating that the full template has been sent */
7129#define FP_TEMPLATE_COMMIT 0x80000000
7130
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007131struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007132 uint32_t offset;
7133 uint32_t size;
7134 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007135} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007136
7137/* Clear the current fingerprint user context and set a new one */
7138#define EC_CMD_FP_CONTEXT 0x0406
7139
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007140struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007141 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007142} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007143
Jett Rinkba2edaf2020-01-14 11:49:06 -07007144enum fp_context_action {
7145 FP_CONTEXT_ASYNC = 0,
7146 FP_CONTEXT_GET_RESULT = 1,
7147};
7148
7149/* Version 1 of the command is "asynchronous". */
7150struct ec_params_fp_context_v1 {
7151 uint8_t action; /**< enum fp_context_action */
7152 uint8_t reserved[3]; /**< padding for alignment */
7153 uint32_t userid[FP_CONTEXT_USERID_WORDS];
7154} __ec_align4;
7155
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007156#define EC_CMD_FP_STATS 0x0407
7157
7158#define FPSTATS_CAPTURE_INV BIT(0)
7159#define FPSTATS_MATCHING_INV BIT(1)
7160
7161struct ec_response_fp_stats {
7162 uint32_t capture_time_us;
7163 uint32_t matching_time_us;
7164 uint32_t overall_time_us;
7165 struct {
7166 uint32_t lo;
7167 uint32_t hi;
7168 } overall_t0;
7169 uint8_t timestamps_invalid;
7170 int8_t template_matched;
7171} __ec_align2;
7172
7173#define EC_CMD_FP_SEED 0x0408
7174struct ec_params_fp_seed {
7175 /*
7176 * Version of the structure format (N=3).
7177 */
7178 uint16_t struct_version;
7179 /* Reserved bytes, set to 0. */
7180 uint16_t reserved;
7181 /* Seed from the TPM. */
7182 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7183} __ec_align4;
7184
7185#define EC_CMD_FP_ENC_STATUS 0x0409
7186
7187/* FP TPM seed has been set or not */
7188#define FP_ENC_STATUS_SEED_SET BIT(0)
7189
7190struct ec_response_fp_encryption_status {
7191 /* Used bits in encryption engine status */
7192 uint32_t valid_flags;
7193 /* Encryption engine status */
7194 uint32_t status;
7195} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007196
Jett Rinkba2edaf2020-01-14 11:49:06 -07007197#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7198struct ec_params_fp_read_match_secret {
7199 uint16_t fgr;
7200} __ec_align4;
7201
7202/* The positive match secret has the length of the SHA256 digest. */
7203#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7204struct ec_response_fp_read_match_secret {
7205 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7206} __ec_align4;
7207
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007208/*****************************************************************************/
7209/* Touchpad MCU commands: range 0x0500-0x05FF */
7210
7211/* Perform touchpad self test */
7212#define EC_CMD_TP_SELF_TEST 0x0500
7213
7214/* Get number of frame types, and the size of each type */
7215#define EC_CMD_TP_FRAME_INFO 0x0501
7216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007217struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007218 uint32_t n_frames;
7219 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007220} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007221
7222/* Create a snapshot of current frame readings */
7223#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7224
7225/* Read the frame */
7226#define EC_CMD_TP_FRAME_GET 0x0503
7227
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007228struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007229 uint32_t frame_index;
7230 uint32_t offset;
7231 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007232} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007233
7234/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007235/* EC-EC communication commands: range 0x0600-0x06FF */
7236
7237#define EC_COMM_TEXT_MAX 8
7238
7239/*
7240 * Get battery static information, i.e. information that never changes, or
7241 * very infrequently.
7242 */
7243#define EC_CMD_BATTERY_GET_STATIC 0x0600
7244
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007245/**
7246 * struct ec_params_battery_static_info - Battery static info parameters
7247 * @index: Battery index.
7248 */
7249struct ec_params_battery_static_info {
7250 uint8_t index;
7251} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007252
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007253/**
7254 * struct ec_response_battery_static_info - Battery static info response
7255 * @design_capacity: Battery Design Capacity (mAh)
7256 * @design_voltage: Battery Design Voltage (mV)
7257 * @manufacturer: Battery Manufacturer String
7258 * @model: Battery Model Number String
7259 * @serial: Battery Serial Number String
7260 * @type: Battery Type String
7261 * @cycle_count: Battery Cycle Count
7262 */
7263struct ec_response_battery_static_info {
7264 uint16_t design_capacity;
7265 uint16_t design_voltage;
7266 char manufacturer[EC_COMM_TEXT_MAX];
7267 char model[EC_COMM_TEXT_MAX];
7268 char serial[EC_COMM_TEXT_MAX];
7269 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007270 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007271 uint32_t cycle_count;
7272} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007273
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007274/**
7275 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7276 * Equivalent to struct ec_response_battery_static_info, but with longer
7277 * strings.
7278 * @design_capacity: battery design capacity (in mAh)
7279 * @design_voltage: battery design voltage (in mV)
7280 * @cycle_count: battery cycle count
7281 * @manufacturer_ext: battery manufacturer string
7282 * @model_ext: battery model string
7283 * @serial_ext: battery serial number string
7284 * @type_ext: battery type string
7285 */
7286struct ec_response_battery_static_info_v1 {
7287 uint16_t design_capacity;
7288 uint16_t design_voltage;
7289 uint32_t cycle_count;
7290 char manufacturer_ext[12];
7291 char model_ext[12];
7292 char serial_ext[12];
7293 char type_ext[12];
7294} __ec_align4;
7295
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007296/*
7297 * Get battery dynamic information, i.e. information that is likely to change
7298 * every time it is read.
7299 */
7300#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7301
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007302/**
7303 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7304 * @index: Battery index.
7305 */
7306struct ec_params_battery_dynamic_info {
7307 uint8_t index;
7308} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007309
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007310/**
7311 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7312 * @actual_voltage: Battery voltage (mV)
7313 * @actual_current: Battery current (mA); negative=discharging
7314 * @remaining_capacity: Remaining capacity (mAh)
7315 * @full_capacity: Capacity (mAh, might change occasionally)
7316 * @flags: Flags, see EC_BATT_FLAG_*
7317 * @desired_voltage: Charging voltage desired by battery (mV)
7318 * @desired_current: Charging current desired by battery (mA)
7319 */
7320struct ec_response_battery_dynamic_info {
7321 int16_t actual_voltage;
7322 int16_t actual_current;
7323 int16_t remaining_capacity;
7324 int16_t full_capacity;
7325 int16_t flags;
7326 int16_t desired_voltage;
7327 int16_t desired_current;
7328} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007329
7330/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007331 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007332 */
7333#define EC_CMD_CHARGER_CONTROL 0x0602
7334
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007335/**
7336 * struct ec_params_charger_control - Charger control parameters
7337 * @max_current: Charger current (mA). Positive to allow base to draw up to
7338 * max_current and (possibly) charge battery, negative to request current
7339 * from base (OTG).
7340 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7341 * >= 0.
7342 * @allow_charging: Allow base battery charging (only makes sense if
7343 * max_current > 0).
7344 */
7345struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007346 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007347 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007348 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007349} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007350
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007351/* Get ACK from the USB-C SS muxes */
7352#define EC_CMD_USB_PD_MUX_ACK 0x0603
7353
7354struct ec_params_usb_pd_mux_ack {
7355 uint8_t port; /* USB-C port number */
7356} __ec_align1;
7357
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007358/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007359/*
7360 * Reserve a range of host commands for board-specific, experimental, or
7361 * special purpose features. These can be (re)used without updating this file.
7362 *
7363 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7364 * their EC commands for easier development, testing, debugging, and support.
7365 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007366 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7367 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7368 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007369 * In your experimental code, you may want to do something like this:
7370 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007371 * #define EC_CMD_MAGIC_FOO 0x0000
7372 * #define EC_CMD_MAGIC_BAR 0x0001
7373 * #define EC_CMD_MAGIC_HEY 0x0002
7374 *
7375 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7376 * EC_VER_MASK(0);
7377 *
7378 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7379 * EC_VER_MASK(0);
7380 *
7381 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7382 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007383 */
7384#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7385#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7386
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007387/*
7388 * Given the private host command offset, calculate the true private host
7389 * command value.
7390 */
7391#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7392 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7393
Duncan Laurie93e24442014-01-06 12:30:52 -08007394/*****************************************************************************/
7395/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007396 * Passthru commands
7397 *
7398 * Some platforms have sub-processors chained to each other. For example.
7399 *
7400 * AP <--> EC <--> PD MCU
7401 *
7402 * The top 2 bits of the command number are used to indicate which device the
7403 * command is intended for. Device 0 is always the device receiving the
7404 * command; other device mapping is board-specific.
7405 *
7406 * When a device receives a command to be passed to a sub-processor, it passes
7407 * it on with the device number set back to 0. This allows the sub-processor
7408 * to remain blissfully unaware of whether the command originated on the next
7409 * device up the chain, or was passed through from the AP.
7410 *
7411 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7412 * AP sends command 0x4002 to the EC
7413 * EC sends command 0x0002 to the PD MCU
7414 * EC forwards PD MCU response back to the AP
7415 */
7416
7417/* Offset and max command number for sub-device n */
7418#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7419#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7420
7421/*****************************************************************************/
7422/*
Duncan Laurie93e24442014-01-06 12:30:52 -08007423 * Deprecated constants. These constants have been renamed for clarity. The
7424 * meaning and size has not changed. Programs that use the old names should
7425 * switch to the new names soon, as the old names may not be carried forward
7426 * forever.
7427 */
7428#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
7429#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
7430#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
7431
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007432#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007433
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007434#ifdef __cplusplus
7435}
7436#endif
7437
Duncan Laurieeb316852015-12-01 18:51:18 -08007438#endif /* __CROS_EC_EC_COMMANDS_H */