blob: 33045cf97aed04364ae6895a04addeb97d79487f [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 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -0800180#define EC_TEMP_SENSOR_ENTRIES 16
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800181/*
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
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -0800188/* Max temp sensor entries for host commands */
189#define EC_MAX_TEMP_SENSOR_ENTRIES (EC_TEMP_SENSOR_ENTRIES + \
190 EC_TEMP_SENSOR_B_ENTRIES)
191
Duncan Laurie93e24442014-01-06 12:30:52 -0800192/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700193#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
194#define EC_TEMP_SENSOR_ERROR 0xfe
195#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
196#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800197/*
198 * The offset of temperature value stored in mapped memory. This allows
199 * reporting a temperature range of 200K to 454K = -73C to 181C.
200 */
201#define EC_TEMP_SENSOR_OFFSET 200
202
Duncan Laurie93e24442014-01-06 12:30:52 -0800203/*
204 * Number of ALS readings at EC_MEMMAP_ALS
205 */
206#define EC_ALS_ENTRIES 2
207
208/*
209 * The default value a temperature sensor will return when it is present but
210 * has not been read this boot. This is a reasonable number to avoid
211 * triggering alarms on the host.
212 */
213#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
214
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800215#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
216#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
217#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
218
219/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
220#define EC_BATT_FLAG_AC_PRESENT 0x01
221#define EC_BATT_FLAG_BATT_PRESENT 0x02
222#define EC_BATT_FLAG_DISCHARGING 0x04
223#define EC_BATT_FLAG_CHARGING 0x08
224#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600225/* Set if some of the static/dynamic data is invalid (or outdated). */
226#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800227
228/* Switch flags at EC_MEMMAP_SWITCHES */
229#define EC_SWITCH_LID_OPEN 0x01
230#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
231#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700232/* Was recovery requested via keyboard; now unused. */
233#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800234/* Recovery requested via dedicated signal (from servo board) */
235#define EC_SWITCH_DEDICATED_RECOVERY 0x10
236/* Was fake developer mode switch; now unused. Remove in next refactor. */
237#define EC_SWITCH_IGNORE0 0x20
238
239/* Host command interface flags */
240/* Host command interface supports LPC args (LPC interface only) */
241#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800242/* Host command interface supports version 3 protocol */
243#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800244
245/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800246#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
247#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
248#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
249#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
250#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800251
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700252/*****************************************************************************/
253/*
254 * ACPI commands
255 *
256 * These are valid ONLY on the ACPI command/data port.
257 */
258
259/*
260 * ACPI Read Embedded Controller
261 *
262 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
263 *
264 * Use the following sequence:
265 *
266 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
267 * - Wait for EC_LPC_CMDR_PENDING bit to clear
268 * - Write address to EC_LPC_ADDR_ACPI_DATA
269 * - Wait for EC_LPC_CMDR_DATA bit to set
270 * - Read value from EC_LPC_ADDR_ACPI_DATA
271 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700272#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700273
274/*
275 * ACPI Write Embedded Controller
276 *
277 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
278 *
279 * Use the following sequence:
280 *
281 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
282 * - Wait for EC_LPC_CMDR_PENDING bit to clear
283 * - Write address to EC_LPC_ADDR_ACPI_DATA
284 * - Wait for EC_LPC_CMDR_PENDING bit to clear
285 * - Write value to EC_LPC_ADDR_ACPI_DATA
286 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700287#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700288
289/*
290 * ACPI Burst Enable Embedded Controller
291 *
292 * This enables burst mode on the EC to allow the host to issue several
293 * commands back-to-back. While in this mode, writes to mapped multi-byte
294 * data are locked out to ensure data consistency.
295 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700296#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700297
298/*
299 * ACPI Burst Disable Embedded Controller
300 *
301 * This disables burst mode on the EC and stops preventing EC writes to mapped
302 * multi-byte data.
303 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700304#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700305
306/*
307 * ACPI Query Embedded Controller
308 *
309 * This clears the lowest-order bit in the currently pending host events, and
310 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
311 * event 0x80000000 = 32), or 0 if no event was pending.
312 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700313#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700314
315/* Valid addresses in ACPI memory space, for read/write commands */
316
317/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
318#define EC_ACPI_MEM_VERSION 0x00
319/*
320 * Test location; writing value here updates test compliment byte to (0xff -
321 * value).
322 */
323#define EC_ACPI_MEM_TEST 0x01
324/* Test compliment; writes here are ignored. */
325#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
326
327/* Keyboard backlight brightness percent (0 - 100) */
328#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
329/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
330#define EC_ACPI_MEM_FAN_DUTY 0x04
331
332/*
333 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
334 * independent thresholds attached to them. The current value of the ID
335 * register determines which sensor is affected by the THRESHOLD and COMMIT
336 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
337 * as the memory-mapped sensors. The COMMIT register applies those settings.
338 *
339 * The spec does not mandate any way to read back the threshold settings
340 * themselves, but when a threshold is crossed the AP needs a way to determine
341 * which sensor(s) are responsible. Each reading of the ID register clears and
342 * returns one sensor ID that has crossed one of its threshold (in either
343 * direction) since the last read. A value of 0xFF means "no new thresholds
344 * have tripped". Setting or enabling the thresholds for a sensor will clear
345 * the unread event count for that sensor.
346 */
347#define EC_ACPI_MEM_TEMP_ID 0x05
348#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
349#define EC_ACPI_MEM_TEMP_COMMIT 0x07
350/*
351 * Here are the bits for the COMMIT register:
352 * bit 0 selects the threshold index for the chosen sensor (0/1)
353 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
354 * Each write to the commit register affects one threshold.
355 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800356#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
357#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700358/*
359 * Example:
360 *
361 * Set the thresholds for sensor 2 to 50 C and 60 C:
362 * write 2 to [0x05] -- select temp sensor 2
363 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
364 * write 0x2 to [0x07] -- enable threshold 0 with this value
365 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
366 * write 0x3 to [0x07] -- enable threshold 1 with this value
367 *
368 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
369 * write 2 to [0x05] -- select temp sensor 2
370 * write 0x1 to [0x07] -- disable threshold 1
371 */
372
373/* DPTF battery charging current limit */
374#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
375
376/* Charging limit is specified in 64 mA steps */
377#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
378/* Value to disable DPTF battery charging limit */
379#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700380
jiazi Yang51fc93f2016-07-28 05:15:01 -0400381/*
382 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800383 * Bits Definition
384 * 3:1 Device DPTF Profile Number (DDPN)
385 * 0 = Reserved for backward compatibility (indicates no valid
386 * profile number. Host should fall back to using TBMD).
387 * 1..7 = DPTF Profile number to indicate to host which table needs
388 * to be loaded.
389 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400390 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700391#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800392#define EC_ACPI_MEM_TBMD_SHIFT 0
393#define EC_ACPI_MEM_TBMD_MASK 0x1
394#define EC_ACPI_MEM_DDPN_SHIFT 1
395#define EC_ACPI_MEM_DDPN_MASK 0x7
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700396
397/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600398 * Report device features. Uses the same format as the host command, except:
399 *
400 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
401 * of features", which is of limited interest when the system is already
402 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
403 * these are supported, it defaults to 0.
404 * This allows detecting the presence of this field since older versions of
405 * the EC codebase would simply return 0xff to that unknown address. Check
406 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
407 * are valid.
408 */
409#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
410#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
411#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
412#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
413#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
414#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
415#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
416#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
417
418#define EC_ACPI_MEM_BATTERY_INDEX 0x12
419
420/*
421 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
422 * is enabled (1) or disabled (0).
423 * bit 0 USB port ID 0
424 * ...
425 * bit 7 USB port ID 7
426 */
427#define EC_ACPI_MEM_USB_PORT_POWER 0x13
428
429/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600430 * USB Retimer firmware update.
431 * Read:
432 * Result of last operation AP requested
433 * Write:
434 * bits[3:0]: USB-C port number
435 * bits[7:4]: Operation requested by AP
436 *
437 * NDA (no device attached) case:
438 * To update retimer firmware, AP needs set up TBT Alt mode.
439 * AP requests operations in this sequence:
440 * 1. Get port information about which ports support retimer firmware update.
441 * In the query result, each bit represents one port.
442 * 2. Get current MUX mode, it's NDA.
443 * 3. Suspend specified PD port's task.
444 * 4. AP requests EC to enter USB mode -> enter Safe mode -> enter TBT mode ->
445 * update firmware -> disconnect MUX -> resume PD task.
446 *
447 * DA (device attached) cases:
448 * Retimer firmware update is not supported in DA cases.
449 * 1. Get port information about which ports support retimer firmware update
450 * 2. Get current MUX mode, it's DA.
451 * 3. AP continues. No more retimer firmware update activities.
452 *
453 */
454#define EC_ACPI_MEM_USB_RETIMER_FW_UPDATE 0x14
455
456#define USB_RETIMER_FW_UPDATE_OP_SHIFT 4
457#define USB_RETIMER_FW_UPDATE_ERR 0xfe
458#define USB_RETIMER_FW_UPDATE_INVALID_MUX 0xff
Scott Chao18141d8c2021-07-30 10:40:57 +0800459/* Mask to clear unused MUX bits in retimer firmware update */
460#define USB_RETIMER_FW_UPDATE_MUX_MASK (USB_PD_MUX_USB_ENABLED | \
461 USB_PD_MUX_DP_ENABLED | \
462 USB_PD_MUX_SAFE_MODE | \
463 USB_PD_MUX_TBT_COMPAT_ENABLED | \
464 USB_PD_MUX_USB4_ENABLED)
465
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600466/* Retimer firmware update operations */
467#define USB_RETIMER_FW_UPDATE_QUERY_PORT 0 /* Which ports has retimer */
468#define USB_RETIMER_FW_UPDATE_SUSPEND_PD 1 /* Suspend PD port */
469#define USB_RETIMER_FW_UPDATE_RESUME_PD 2 /* Resume PD port */
470#define USB_RETIMER_FW_UPDATE_GET_MUX 3 /* Read current USB MUX */
471#define USB_RETIMER_FW_UPDATE_SET_USB 4 /* Set MUX to USB mode */
472#define USB_RETIMER_FW_UPDATE_SET_SAFE 5 /* Set MUX to Safe mode */
473#define USB_RETIMER_FW_UPDATE_SET_TBT 6 /* Set MUX to TBT mode */
474#define USB_RETIMER_FW_UPDATE_DISCONNECT 7 /* Set MUX to disconnect */
475
476#define EC_ACPI_MEM_USB_RETIMER_PORT(x) ((x) & 0x0f)
477#define EC_ACPI_MEM_USB_RETIMER_OP(x) \
478 (((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)
479
480/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700481 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
482 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
483 */
484#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
485#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
486
487/* Current version of ACPI memory address space */
488#define EC_ACPI_MEM_VERSION_CURRENT 2
489
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -0600490
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800491/*
492 * This header file is used in coreboot both in C and ACPI code. The ACPI code
493 * is pre-processed to handle constants but the ASL compiler is unable to
494 * handle actual C code so keep it separate.
495 */
496#ifndef __ACPI__
497
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800498#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800499/*
500 * Define __packed if someone hasn't beat us to it. Linux kernel style
501 * checking prefers __packed over __attribute__((packed)).
502 */
503#ifndef __packed
504#define __packed __attribute__((packed))
505#endif
506
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700507#ifndef __aligned
508#define __aligned(x) __attribute__((aligned(x)))
509#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800510#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700511
512/*
513 * Attributes for EC request and response packets. Just defining __packed
514 * results in inefficient assembly code on ARM, if the structure is actually
515 * 32-bit aligned, as it should be for all buffers.
516 *
517 * Be very careful when adding these to existing structures. They will round
518 * up the structure size to the specified boundary.
519 *
520 * Also be very careful to make that if a structure is included in some other
521 * parent structure that the alignment will still be true given the packing of
522 * the parent structure. This is particularly important if the sub-structure
523 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200524 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700525 *
526 * Also be very careful using __packed - particularly when nesting non-packed
527 * structures inside packed ones. In fact, DO NOT use __packed directly;
528 * always use one of these attributes.
529 *
530 * Once everything is annotated properly, the following search strings should
531 * not return ANY matches in this file other than right here:
532 *
533 * "__packed" - generates inefficient code; all sub-structs must also be packed
534 *
535 * "struct [^_]" - all structs should be annotated, except for structs that are
536 * members of other structs/unions (and their original declarations should be
537 * annotated).
538 */
539#ifdef CONFIG_HOSTCMD_ALIGNED
540
541/*
542 * Packed structures where offset and size are always aligned to 1, 2, or 4
543 * byte boundary.
544 */
545#define __ec_align1 __packed
546#define __ec_align2 __packed __aligned(2)
547#define __ec_align4 __packed __aligned(4)
548
549/*
550 * Packed structure which must be under-aligned, because its size is not a
551 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
552 * of all multi-byte fields in it, even though they are themselves aligned.
553 *
554 * In theory, we could duplicate the structure with __aligned(4) for accessing
555 * its members, but use the __packed version for sizeof().
556 */
557#define __ec_align_size1 __packed
558
559/*
560 * Packed structure which must be under-aligned, because its offset inside a
561 * parent structure is not a 4-byte multiple.
562 */
563#define __ec_align_offset1 __packed
564#define __ec_align_offset2 __packed __aligned(2)
565
566/*
567 * Structures which are complicated enough that I'm skipping them on the first
568 * pass. They are effectively unchanged from their previous definitions.
569 *
570 * TODO(rspangler): Figure out what to do with these. It's likely necessary
571 * to work out the size and offset of each member and add explicit padding to
572 * maintain those.
573 */
574#define __ec_todo_packed __packed
575#define __ec_todo_unpacked
576
577#else /* !CONFIG_HOSTCMD_ALIGNED */
578
579/*
580 * Packed structures make no assumption about alignment, so they do inefficient
581 * byte-wise reads.
582 */
583#define __ec_align1 __packed
584#define __ec_align2 __packed
585#define __ec_align4 __packed
586#define __ec_align_size1 __packed
587#define __ec_align_offset1 __packed
588#define __ec_align_offset2 __packed
589#define __ec_todo_packed __packed
590#define __ec_todo_unpacked
591
592#endif /* !CONFIG_HOSTCMD_ALIGNED */
593
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800594/* LPC command status byte masks */
595/* EC has written a byte in the data register and host hasn't read it yet */
596#define EC_LPC_STATUS_TO_HOST 0x01
597/* Host has written a command/data byte and the EC hasn't read it yet */
598#define EC_LPC_STATUS_FROM_HOST 0x02
599/* EC is processing a command */
600#define EC_LPC_STATUS_PROCESSING 0x04
601/* Last write to EC was a command, not data */
602#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700603/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800604#define EC_LPC_STATUS_BURST_MODE 0x10
605/* SCI event is pending (requesting SCI query) */
606#define EC_LPC_STATUS_SCI_PENDING 0x20
607/* SMI event is pending (requesting SMI query) */
608#define EC_LPC_STATUS_SMI_PENDING 0x40
609/* (reserved) */
610#define EC_LPC_STATUS_RESERVED 0x80
611
612/*
613 * EC is busy. This covers both the EC processing a command, and the host has
614 * written a new command but the EC hasn't picked it up yet.
615 */
616#define EC_LPC_STATUS_BUSY_MASK \
617 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
618
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800619/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700620 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700621 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800622enum ec_status {
623 EC_RES_SUCCESS = 0,
624 EC_RES_INVALID_COMMAND = 1,
625 EC_RES_ERROR = 2,
626 EC_RES_INVALID_PARAM = 3,
627 EC_RES_ACCESS_DENIED = 4,
628 EC_RES_INVALID_RESPONSE = 5,
629 EC_RES_INVALID_VERSION = 6,
630 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700631 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
632 EC_RES_UNAVAILABLE = 9, /* No response available */
633 EC_RES_TIMEOUT = 10, /* We got a timeout */
634 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800635 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
636 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700637 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700638 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600639 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
640 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
641 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
642 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
643 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700644
645 EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */
646} __packed;
647BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800648
649/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600650 * Host event codes. ACPI query EC command uses code 0 to mean "no event
651 * pending". We explicitly specify each value in the enum listing so they won't
652 * change if we delete/insert an item or rearrange the list (it needs to be
653 * stable across platforms, not just within a single compiled instance).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800654 */
655enum host_event_code {
Rob Barnes8bc5fa92021-06-28 09:32:28 -0600656 EC_HOST_EVENT_NONE = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800657 EC_HOST_EVENT_LID_CLOSED = 1,
658 EC_HOST_EVENT_LID_OPEN = 2,
659 EC_HOST_EVENT_POWER_BUTTON = 3,
660 EC_HOST_EVENT_AC_CONNECTED = 4,
661 EC_HOST_EVENT_AC_DISCONNECTED = 5,
662 EC_HOST_EVENT_BATTERY_LOW = 6,
663 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
664 EC_HOST_EVENT_BATTERY = 8,
665 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700666 /* Event generated by a device attached to the EC */
667 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800668 EC_HOST_EVENT_THERMAL = 11,
669 EC_HOST_EVENT_USB_CHARGER = 12,
670 EC_HOST_EVENT_KEY_PRESSED = 13,
671 /*
672 * EC has finished initializing the host interface. The host can check
673 * for this event following sending a EC_CMD_REBOOT_EC command to
674 * determine when the EC is ready to accept subsequent commands.
675 */
676 EC_HOST_EVENT_INTERFACE_READY = 14,
677 /* Keyboard recovery combo has been pressed */
678 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
679
680 /* Shutdown due to thermal overload */
681 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
682 /* Shutdown due to battery level too low */
683 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
684
Duncan Laurie93e24442014-01-06 12:30:52 -0800685 /* Suggest that the AP throttle itself */
686 EC_HOST_EVENT_THROTTLE_START = 18,
687 /* Suggest that the AP resume normal speed */
688 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700689
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800690 /* Hang detect logic detected a hang and host event timeout expired */
691 EC_HOST_EVENT_HANG_DETECT = 20,
692 /* Hang detect logic detected a hang and warm rebooted the AP */
693 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700694
695 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700696 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800697
Duncan Lauried8401182014-09-29 08:32:19 -0700698 /* Battery Status flags have changed */
699 EC_HOST_EVENT_BATTERY_STATUS = 23,
700
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700701 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800702 EC_HOST_EVENT_PANIC = 24,
703
Furquan Shaikh066cc852015-06-20 15:53:03 -0700704 /* Keyboard fastboot combo has been pressed */
705 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
706
Gwendal Grignou880b4582016-06-20 08:49:25 -0700707 /* EC RTC event occurred */
708 EC_HOST_EVENT_RTC = 26,
709
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700710 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700711 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700712
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700713 /* EC desires to change state of host-controlled USB mux */
714 EC_HOST_EVENT_USB_MUX = 28,
715
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800716 /*
717 * The device has changed "modes". This can be one of the following:
718 *
719 * - TABLET/LAPTOP mode
720 * - detachable base attach/detach event
721 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400722 EC_HOST_EVENT_MODE_CHANGE = 29,
723
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700724 /* Keyboard recovery combo with hardware reinitialization */
725 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
726
Jett Rinkba2edaf2020-01-14 11:49:06 -0700727 /* WoV */
728 EC_HOST_EVENT_WOV = 31,
729
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700730 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800731 * The high bit of the event mask is not used as a host event code. If
732 * it reads back as set, then the entire event mask should be
733 * considered invalid by the host. This can happen when reading the
734 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
735 * not initialized on the EC, or improperly configured on the host.
736 */
737 EC_HOST_EVENT_INVALID = 32
738};
739/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800740#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800741
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800742/**
743 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
744 * @flags: The host argument flags.
745 * @command_version: Command version.
746 * @data_size: The length of data.
747 * @checksum: Checksum; sum of command + flags + command_version + data_size +
748 * all params/response data bytes.
749 */
750struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800751 uint8_t flags;
752 uint8_t command_version;
753 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800754 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800755} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800756
757/* Flags for ec_lpc_host_args.flags */
758/*
759 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
760 * params.
761 *
762 * If EC gets a command and this flag is not set, this is an old-style command.
763 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
764 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700765 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800766 */
767#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
768/*
769 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
770 *
771 * If EC responds to a command and this flag is not set, this is an old-style
772 * response. Command version is 0 and response data from EC is at
773 * EC_LPC_ADDR_OLD_PARAM with unknown length.
774 */
775#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
776
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800777/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800778/*
779 * Byte codes returned by EC over SPI interface.
780 *
781 * These can be used by the AP to debug the EC interface, and to determine
782 * when the EC is not in a state where it will ever get around to responding
783 * to the AP.
784 *
785 * Example of sequence of bytes read from EC for a current good transfer:
786 * 1. - - AP asserts chip select (CS#)
787 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
788 * 3. - - EC starts handling CS# interrupt
789 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
790 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
791 * bytes looking for EC_SPI_FRAME_START
792 * 6. - - EC finishes processing and sets up response
793 * 7. EC_SPI_FRAME_START - AP reads frame byte
794 * 8. (response packet) - AP reads response packet
795 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
796 * 10 - - AP deasserts chip select
797 * 11 - - EC processes CS# interrupt and sets up DMA for
798 * next request
799 *
800 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
801 * the following byte values:
802 * EC_SPI_OLD_READY
803 * EC_SPI_RX_READY
804 * EC_SPI_RECEIVING
805 * EC_SPI_PROCESSING
806 *
807 * Then the EC found an error in the request, or was not ready for the request
808 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
809 * because the EC is unable to tell when the AP is done sending its request.
810 */
811
812/*
813 * Framing byte which precedes a response packet from the EC. After sending a
814 * request, the AP will clock in bytes until it sees the framing byte, then
815 * clock in the response packet.
816 */
817#define EC_SPI_FRAME_START 0xec
818
819/*
820 * Padding bytes which are clocked out after the end of a response packet.
821 */
822#define EC_SPI_PAST_END 0xed
823
824/*
825 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
826 * that the AP will send a valid packet header (starting with
827 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
828 */
829#define EC_SPI_RX_READY 0xf8
830
831/*
832 * EC has started receiving the request from the AP, but hasn't started
833 * processing it yet.
834 */
835#define EC_SPI_RECEIVING 0xf9
836
837/* EC has received the entire request from the AP and is processing it. */
838#define EC_SPI_PROCESSING 0xfa
839
840/*
841 * EC received bad data from the AP, such as a packet header with an invalid
842 * length. EC will ignore all data until chip select deasserts.
843 */
844#define EC_SPI_RX_BAD_DATA 0xfb
845
846/*
847 * EC received data from the AP before it was ready. That is, the AP asserted
848 * chip select and started clocking data before the EC was ready to receive it.
849 * EC will ignore all data until chip select deasserts.
850 */
851#define EC_SPI_NOT_READY 0xfc
852
853/*
854 * EC was ready to receive a request from the AP. EC has treated the byte sent
855 * by the AP as part of a request packet, or (for old-style ECs) is processing
856 * a fully received packet but is not ready to respond yet.
857 */
858#define EC_SPI_OLD_READY 0xfd
859
860/*****************************************************************************/
861
862/*
863 * Protocol version 2 for I2C and SPI send a request this way:
864 *
865 * 0 EC_CMD_VERSION0 + (command version)
866 * 1 Command number
867 * 2 Length of params = N
868 * 3..N+2 Params, if any
869 * N+3 8-bit checksum of bytes 0..N+2
870 *
871 * The corresponding response is:
872 *
873 * 0 Result code (EC_RES_*)
874 * 1 Length of params = M
875 * 2..M+1 Params, if any
876 * M+2 8-bit checksum of bytes 0..M+1
877 */
878#define EC_PROTO2_REQUEST_HEADER_BYTES 3
879#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
880#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
881 EC_PROTO2_REQUEST_TRAILER_BYTES)
882
883#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
884#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
885#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
886 EC_PROTO2_RESPONSE_TRAILER_BYTES)
887
888/* Parameter length was limited by the LPC interface */
889#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
890
891/* Maximum request and response packet sizes for protocol version 2 */
892#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
893 EC_PROTO2_MAX_PARAM_SIZE)
894#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
895 EC_PROTO2_MAX_PARAM_SIZE)
896
897/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800898
899/*
900 * Value written to legacy command port / prefix byte to indicate protocol
901 * 3+ structs are being used. Usage is bus-dependent.
902 */
903#define EC_COMMAND_PROTOCOL_3 0xda
904
905#define EC_HOST_REQUEST_VERSION 3
906
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800907/**
908 * struct ec_host_request - Version 3 request from host.
909 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
910 * receives a header with a version it doesn't know how to
911 * parse.
912 * @checksum: Checksum of request and data; sum of all bytes including checksum
913 * should total to 0.
914 * @command: Command to send (EC_CMD_...)
915 * @command_version: Command version.
916 * @reserved: Unused byte in current protocol version; set to 0.
917 * @data_len: Length of data which follows this header.
918 */
919struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800920 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800921 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800922 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800923 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800924 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800925 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800926} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800927
928#define EC_HOST_RESPONSE_VERSION 3
929
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800930/**
931 * struct ec_host_response - Version 3 response from EC.
932 * @struct_version: Struct version (=3).
933 * @checksum: Checksum of response and data; sum of all bytes including
934 * checksum should total to 0.
935 * @result: EC's response to the command (separate from communication failure)
936 * @data_len: Length of data which follows this header.
937 * @reserved: Unused bytes in current protocol version; set to 0.
938 */
939struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800940 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800941 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800942 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800943 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800944 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800945} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800946
947/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600948
949/*
950 * Host command protocol V4.
951 *
952 * Packets always start with a request or response header. They are followed
953 * by data_len bytes of data. If the data_crc_present flag is set, the data
Elyes HAOUAS15504692021-01-16 15:01:33 +0100954 * bytes are followed by a CRC-8 of that data, using x^8 + x^2 + x + 1
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600955 * polynomial.
956 *
957 * Host algorithm when sending a request q:
958 *
959 * 101) tries_left=(some value, e.g. 3);
960 * 102) q.seq_num++
961 * 103) q.seq_dup=0
962 * 104) Calculate q.header_crc.
963 * 105) Send request q to EC.
964 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
965 *
966 * 201) If r.struct_version != 4, go to 301.
967 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
968 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
969 * 204) If r.seq_num != q.seq_num, go to 301.
970 * 205) If r.seq_dup == q.seq_dup, return success.
971 * 207) If r.seq_dup == 1, go to 301.
972 * 208) Return error.
973 *
974 * 301) If --tries_left <= 0, return error.
975 * 302) If q.seq_dup == 1, go to 105.
976 * 303) q.seq_dup = 1
977 * 304) Go to 104.
978 *
979 * EC algorithm when receiving a request q.
980 * EC has response buffer r, error buffer e.
981 *
982 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
983 * and go to 301
984 * 102) If q.header_crc mismatches calculated CRC, set e.result =
985 * EC_RES_INVALID_HEADER_CRC and go to 301
986 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
987 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
988 * and go to 301.
989 * 104) If q.seq_dup == 0, go to 201.
990 * 105) If q.seq_num != r.seq_num, go to 201.
991 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
992 *
993 * 201) Process request q into response r.
994 * 202) r.seq_num = q.seq_num
995 * 203) r.seq_dup = q.seq_dup
996 * 204) Calculate r.header_crc
997 * 205) If r.data_len > 0 and data is no longer available, set e.result =
998 * EC_RES_DUP_UNAVAILABLE and go to 301.
999 * 206) Send response r.
1000 *
1001 * 301) e.seq_num = q.seq_num
1002 * 302) e.seq_dup = q.seq_dup
1003 * 303) Calculate e.header_crc.
1004 * 304) Send error response e.
1005 */
1006
1007/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001008struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001009 /*
1010 * bits 0-3: struct_version: Structure version (=4)
1011 * bit 4: is_response: Is response (=0)
1012 * bits 5-6: seq_num: Sequence number
1013 * bit 7: seq_dup: Sequence duplicate flag
1014 */
1015 uint8_t fields0;
1016
1017 /*
1018 * bits 0-4: command_version: Command version
1019 * bits 5-6: Reserved (set 0, ignore on read)
1020 * bit 7: data_crc_present: Is data CRC present after data
1021 */
1022 uint8_t fields1;
1023
1024 /* Command code (EC_CMD_*) */
1025 uint16_t command;
1026
1027 /* Length of data which follows this header (not including data CRC) */
1028 uint16_t data_len;
1029
1030 /* Reserved (set 0, ignore on read) */
1031 uint8_t reserved;
1032
1033 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1034 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001035} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001036
1037/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001038struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001039 /*
1040 * bits 0-3: struct_version: Structure version (=4)
1041 * bit 4: is_response: Is response (=1)
1042 * bits 5-6: seq_num: Sequence number
1043 * bit 7: seq_dup: Sequence duplicate flag
1044 */
1045 uint8_t fields0;
1046
1047 /*
1048 * bits 0-6: Reserved (set 0, ignore on read)
1049 * bit 7: data_crc_present: Is data CRC present after data
1050 */
1051 uint8_t fields1;
1052
1053 /* Result code (EC_RES_*) */
1054 uint16_t result;
1055
1056 /* Length of data which follows this header (not including data CRC) */
1057 uint16_t data_len;
1058
1059 /* Reserved (set 0, ignore on read) */
1060 uint8_t reserved;
1061
1062 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1063 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001064} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001065
1066/* Fields in fields0 byte */
1067#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1068#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1069#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1070#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1071#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1072
1073/* Fields in fields1 byte */
1074#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1075#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1076
1077/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001078/*
1079 * Notes on commands:
1080 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001081 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001082 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001083 * specified, the command does not input or output data, respectively.
1084 * Parameter/response length is implicit in the structs. Some underlying
1085 * communication protocols (I2C, SPI) may add length or checksum headers, but
1086 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001087 *
1088 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1089 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001090 */
1091
1092/*****************************************************************************/
1093/* General / test commands */
1094
1095/*
1096 * Get protocol version, used to deal with non-backward compatible protocol
1097 * changes.
1098 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001099#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001100
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001101/**
1102 * struct ec_response_proto_version - Response to the proto version command.
1103 * @version: The protocol version.
1104 */
1105struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001106 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001107} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001108
1109/*
1110 * Hello. This is a simple command to test the EC is responsive to
1111 * commands.
1112 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001113#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001114
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001115/**
1116 * struct ec_params_hello - Parameters to the hello command.
1117 * @in_data: Pass anything here.
1118 */
1119struct ec_params_hello {
1120 uint32_t in_data;
1121} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001123/**
1124 * struct ec_response_hello - Response to the hello command.
1125 * @out_data: Output will be in_data + 0x01020304.
1126 */
1127struct ec_response_hello {
1128 uint32_t out_data;
1129} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001130
1131/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001132#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001133
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001134#if !defined(CHROMIUM_EC) && !defined(__KERNEL__)
1135/*
1136 * enum ec_current_image is deprecated and replaced by enum ec_image. This
1137 * macro exists for backwards compatibility of external projects until they
1138 * have been updated: b/149987779.
1139 */
1140#define ec_current_image ec_image
1141#endif
1142
1143enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001144 EC_IMAGE_UNKNOWN = 0,
1145 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001146 EC_IMAGE_RW,
1147 EC_IMAGE_RW_A = EC_IMAGE_RW,
1148 EC_IMAGE_RO_B,
1149 EC_IMAGE_RW_B
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001150};
1151
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001152/**
Rob Barnes5ab14662021-09-17 10:24:45 -06001153 * struct ec_response_get_version - Response to the v0 get version command.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001154 * @version_string_ro: Null-terminated RO firmware version string.
1155 * @version_string_rw: Null-terminated RW firmware version string.
1156 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001157 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001158 */
1159struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001160 char version_string_ro[32];
1161 char version_string_rw[32];
Rob Barnes5ab14662021-09-17 10:24:45 -06001162 char reserved[32]; /* Changed to cros_fwid_ro in version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001163 uint32_t current_image;
1164} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001165
Rob Barnes5ab14662021-09-17 10:24:45 -06001166/**
1167 * struct ec_response_get_version_v1 - Response to the v1 get version command.
1168 *
1169 * ec_response_get_version_v1 is a strict superset of ec_response_get_version.
1170 * The v1 response changes the semantics of one field (reserved to cros_fwid_ro)
1171 * and adds one additional field (cros_fwid_rw).
1172 *
1173 * @version_string_ro: Null-terminated RO firmware version string.
1174 * @version_string_rw: Null-terminated RW firmware version string.
1175 * @cros_fwid_ro: Null-terminated RO CrOS FWID string.
1176 * @current_image: One of ec_image.
1177 * @cros_fwid_rw: Null-terminated RW CrOS FWID string.
1178 */
1179struct ec_response_get_version_v1 {
1180 char version_string_ro[32];
1181 char version_string_rw[32];
1182 char cros_fwid_ro[32]; /* Added in version 1 (Used to be reserved) */
1183 uint32_t current_image;
1184 char cros_fwid_rw[32]; /* Added in version 1 */
1185} __ec_align4;
1186
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001187/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001188#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001189
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001190/**
1191 * struct ec_params_read_test - Parameters for the read test command.
1192 * @offset: Starting value for read buffer.
1193 * @size: Size to read in bytes.
1194 */
1195struct ec_params_read_test {
1196 uint32_t offset;
1197 uint32_t size;
1198} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001199
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001200/**
1201 * struct ec_response_read_test - Response to the read test command.
1202 * @data: Data returned by the read test command.
1203 */
1204struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001205 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001206} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001207
1208/*
1209 * Get build information
1210 *
1211 * Response is null-terminated string.
1212 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001213#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001214
1215/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001216#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001218/**
1219 * struct ec_response_get_chip_info - Response to the get chip info command.
1220 * @vendor: Null-terminated string for chip vendor.
1221 * @name: Null-terminated string for chip name.
1222 * @revision: Null-terminated string for chip mask version.
1223 */
1224struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001225 char vendor[32];
1226 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001227 char revision[32];
1228} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001229
1230/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001231#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001232
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001233/**
1234 * struct ec_response_board_version - Response to the board version command.
1235 * @board_version: A monotonously incrementing number.
1236 */
1237struct ec_response_board_version {
1238 uint16_t board_version;
1239} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001240
1241/*
1242 * Read memory-mapped data.
1243 *
1244 * This is an alternate interface to memory-mapped data for bus protocols
1245 * which don't support direct-mapped memory - I2C, SPI, etc.
1246 *
1247 * Response is params.size bytes of data.
1248 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001249#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001250
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001251/**
1252 * struct ec_params_read_memmap - Parameters for the read memory map command.
1253 * @offset: Offset in memmap (EC_MEMMAP_*).
1254 * @size: Size to read in bytes.
1255 */
1256struct ec_params_read_memmap {
1257 uint8_t offset;
1258 uint8_t size;
1259} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001260
1261/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001262#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001263
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001264/**
1265 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1266 * @cmd: Command to check.
1267 */
1268struct ec_params_get_cmd_versions {
1269 uint8_t cmd;
1270} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001272/**
1273 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1274 * versions (v1)
1275 * @cmd: Command to check.
1276 */
1277struct ec_params_get_cmd_versions_v1 {
1278 uint16_t cmd;
1279} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001280
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001281/**
1282 * struct ec_response_get_cmd_version - Response to the get command versions.
1283 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1284 * a desired version.
1285 */
1286struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001287 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001288} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001289
Duncan Laurie433432b2013-06-03 10:38:22 -07001290/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001291 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001292 * on lpc since it has its own out-of-band busy indicator.
1293 *
1294 * lpc must read the status from the command register. Attempting this on
1295 * lpc will overwrite the args/parameter space and corrupt its data.
1296 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001297#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001298
1299/* Avoid using ec_status which is for return values */
1300enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001301 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001302};
1303
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001304/**
1305 * struct ec_response_get_comms_status - Response to the get comms status
1306 * command.
1307 * @flags: Mask of enum ec_comms_status.
1308 */
1309struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001310 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001311} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001312
Duncan Laurie93e24442014-01-06 12:30:52 -08001313/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001314#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001315
1316/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001317struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001318 uint32_t ec_result;
1319 uint32_t ret_len;
1320 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001321} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001322
1323/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001324struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001325 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001326} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001327
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001328/* Get protocol information */
1329#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001330
1331/* Flags for ec_response_get_protocol_info.flags */
1332/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001333#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001334
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001335/**
1336 * struct ec_response_get_protocol_info - Response to the get protocol info.
1337 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1338 * version n).
1339 * @max_request_packet_size: Maximum request packet size in bytes.
1340 * @max_response_packet_size: Maximum response packet size in bytes.
1341 * @flags: see EC_PROTOCOL_INFO_*
1342 */
1343struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001344 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001345 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001346 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001347 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001348 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001349} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001350
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001351
Duncan Laurie93e24442014-01-06 12:30:52 -08001352/*****************************************************************************/
1353/* Get/Set miscellaneous values */
1354
1355/* The upper byte of .flags tells what to do (nothing means "get") */
1356#define EC_GSV_SET 0x80000000
1357
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001358/*
1359 * The lower three bytes of .flags identifies the parameter, if that has
1360 * meaning for an individual command.
1361 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001362#define EC_GSV_PARAM_MASK 0x00ffffff
1363
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001364struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001365 uint32_t flags;
1366 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001367} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001368
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001369struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001370 uint32_t flags;
1371 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001372} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001373
Duncan Laurieeb316852015-12-01 18:51:18 -08001374/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001375#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001376
Duncan Laurieeb316852015-12-01 18:51:18 -08001377/*****************************************************************************/
1378/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001379#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001380
1381/* Supported features */
1382enum ec_feature_code {
1383 /*
1384 * This image contains a limited set of features. Another image
1385 * in RW partition may support more features.
1386 */
1387 EC_FEATURE_LIMITED = 0,
1388 /*
1389 * Commands for probing/reading/writing/erasing the flash in the
1390 * EC are present.
1391 */
1392 EC_FEATURE_FLASH = 1,
1393 /*
1394 * Can control the fan speed directly.
1395 */
1396 EC_FEATURE_PWM_FAN = 2,
1397 /*
1398 * Can control the intensity of the keyboard backlight.
1399 */
1400 EC_FEATURE_PWM_KEYB = 3,
1401 /*
1402 * Support Google lightbar, introduced on Pixel.
1403 */
1404 EC_FEATURE_LIGHTBAR = 4,
1405 /* Control of LEDs */
1406 EC_FEATURE_LED = 5,
1407 /* Exposes an interface to control gyro and sensors.
1408 * The host goes through the EC to access these sensors.
1409 * In addition, the EC may provide composite sensors, like lid angle.
1410 */
1411 EC_FEATURE_MOTION_SENSE = 6,
1412 /* The keyboard is controlled by the EC */
1413 EC_FEATURE_KEYB = 7,
1414 /* The AP can use part of the EC flash as persistent storage. */
1415 EC_FEATURE_PSTORE = 8,
1416 /* The EC monitors BIOS port 80h, and can return POST codes. */
1417 EC_FEATURE_PORT80 = 9,
1418 /*
1419 * Thermal management: include TMP specific commands.
1420 * Higher level than direct fan control.
1421 */
1422 EC_FEATURE_THERMAL = 10,
1423 /* Can switch the screen backlight on/off */
1424 EC_FEATURE_BKLIGHT_SWITCH = 11,
1425 /* Can switch the wifi module on/off */
1426 EC_FEATURE_WIFI_SWITCH = 12,
1427 /* Monitor host events, through for example SMI or SCI */
1428 EC_FEATURE_HOST_EVENTS = 13,
1429 /* The EC exposes GPIO commands to control/monitor connected devices. */
1430 EC_FEATURE_GPIO = 14,
1431 /* The EC can send i2c messages to downstream devices. */
1432 EC_FEATURE_I2C = 15,
1433 /* Command to control charger are included */
1434 EC_FEATURE_CHARGER = 16,
1435 /* Simple battery support. */
1436 EC_FEATURE_BATTERY = 17,
1437 /*
1438 * Support Smart battery protocol
1439 * (Common Smart Battery System Interface Specification)
1440 */
1441 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001442 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001443 EC_FEATURE_HANG_DETECT = 19,
1444 /* Report power information, for pit only */
1445 EC_FEATURE_PMU = 20,
1446 /* Another Cros EC device is present downstream of this one */
1447 EC_FEATURE_SUB_MCU = 21,
1448 /* Support USB Power delivery (PD) commands */
1449 EC_FEATURE_USB_PD = 22,
1450 /* Control USB multiplexer, for audio through USB port for instance. */
1451 EC_FEATURE_USB_MUX = 23,
1452 /* Motion Sensor code has an internal software FIFO */
1453 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1454 /* Support temporary secure vstore */
1455 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001456 /* EC decides on USB-C SS mux state, muxes configured by host */
1457 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1458 /* EC has RTC feature that can be controlled by host commands */
1459 EC_FEATURE_RTC = 27,
1460 /* The MCU exposes a Fingerprint sensor */
1461 EC_FEATURE_FINGERPRINT = 28,
1462 /* The MCU exposes a Touchpad */
1463 EC_FEATURE_TOUCHPAD = 29,
1464 /* The MCU has RWSIG task enabled */
1465 EC_FEATURE_RWSIG = 30,
1466 /* EC has device events support */
1467 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001468 /* EC supports the unified wake masks for LPC/eSPI systems */
1469 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001470 /* EC supports 64-bit host events */
1471 EC_FEATURE_HOST_EVENT64 = 33,
1472 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1473 EC_FEATURE_EXEC_IN_RAM = 34,
1474 /* EC supports CEC commands */
1475 EC_FEATURE_CEC = 35,
1476 /* EC supports tight sensor timestamping. */
1477 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001478 /*
1479 * EC supports tablet mode detection aligned to Chrome and allows
1480 * setting of threshold by host command using
1481 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1482 */
1483 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001484 /*
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001485 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001486 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1487 * be sent to RO to be precise.
1488 */
1489 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001490 /* The MCU is a System Companion Processor (SCP). */
1491 EC_FEATURE_SCP = 39,
1492 /* The MCU is an Integrated Sensor Hub */
1493 EC_FEATURE_ISH = 40,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08001494 /* New TCPMv2 TYPEC_ prefaced commands supported */
1495 EC_FEATURE_TYPEC_CMD = 41,
1496 /*
1497 * The EC will wait for direction from the AP to enter Type-C alternate
1498 * modes or USB4.
1499 */
1500 EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY = 42,
1501 /*
1502 * The EC will wait for an acknowledge from the AP after setting the
1503 * mux.
1504 */
1505 EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK = 43,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001506 /*
1507 * The EC supports entering and residing in S4.
1508 */
1509 EC_FEATURE_S4_RESIDENCY = 44,
Duncan Laurieeb316852015-12-01 18:51:18 -08001510};
1511
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001512#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1513#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1514
1515struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001516 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001517} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001518
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001519/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001520/* Get the board's SKU ID from EC */
1521#define EC_CMD_GET_SKU_ID 0x000E
1522
Kevin Chiue2bb0592017-09-12 09:13:41 +08001523/* Set SKU ID from AP */
1524#define EC_CMD_SET_SKU_ID 0x000F
1525
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001526struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001527 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001528} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001529
1530/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001531/* Flash commands */
1532
1533/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001534#define EC_CMD_FLASH_INFO 0x0010
1535#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001536
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001537/**
1538 * struct ec_response_flash_info - Response to the flash info command.
1539 * @flash_size: Usable flash size in bytes.
1540 * @write_block_size: Write block size. Write offset and size must be a
1541 * multiple of this.
1542 * @erase_block_size: Erase block size. Erase offset and size must be a
1543 * multiple of this.
1544 * @protect_block_size: Protection block size. Protection offset and size
1545 * must be a multiple of this.
1546 *
1547 * Version 0 returns these fields.
1548 */
1549struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001550 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001551 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001552 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001553 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001554} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001555
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001556/*
1557 * Flags for version 1+ flash info command
1558 * EC flash erases bits to 0 instead of 1.
1559 */
1560#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001561
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001562/*
1563 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001564 * be necessary on a chip where write/erase can be corrupted by other board
1565 * activity, or where the chip needs to enable some sort of programming voltage,
1566 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001567 * chip functionality.
1568 */
1569#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001570
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001571/**
1572 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1573 * @flash_size: Usable flash size in bytes.
1574 * @write_block_size: Write block size. Write offset and size must be a
1575 * multiple of this.
1576 * @erase_block_size: Erase block size. Erase offset and size must be a
1577 * multiple of this.
1578 * @protect_block_size: Protection block size. Protection offset and size
1579 * must be a multiple of this.
1580 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1581 * size is exactly this and offset is a multiple of this.
1582 * For example, an EC may have a write buffer which can do
1583 * half-page operations if data is aligned, and a slower
1584 * word-at-a-time write mode.
1585 * @flags: Flags; see EC_FLASH_INFO_*
1586 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001587 * Version 1 returns the same initial fields as version 0, with additional
1588 * fields following.
1589 *
1590 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001591 * if they did we'd define the version 0 structure as a sub-structure of this
1592 * one.
1593 *
1594 * Version 2 supports flash banks of different sizes:
1595 * The caller specified the number of banks it has preallocated
1596 * (num_banks_desc)
1597 * The EC returns the number of banks describing the flash memory.
1598 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001599 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001600struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001601 /* Version 0 fields; see above for description */
1602 uint32_t flash_size;
1603 uint32_t write_block_size;
1604 uint32_t erase_block_size;
1605 uint32_t protect_block_size;
1606
1607 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001608 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001609 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001610} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001611
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001612struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001613 /* Number of banks to describe */
1614 uint16_t num_banks_desc;
1615 /* Reserved; set 0; ignore on read */
1616 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001617} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001618
1619struct ec_flash_bank {
1620 /* Number of sector is in this bank. */
1621 uint16_t count;
1622 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1623 uint8_t size_exp;
1624 /* Minimal write size for the sectors in this bank */
1625 uint8_t write_size_exp;
1626 /* Erase size for the sectors in this bank */
1627 uint8_t erase_size_exp;
1628 /* Size for write protection, usually identical to erase size. */
1629 uint8_t protect_size_exp;
1630 /* Reserved; set 0; ignore on read */
1631 uint8_t reserved[2];
1632};
1633
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001634struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001635 /* Total flash in the EC. */
1636 uint32_t flash_size;
1637 /* Flags; see EC_FLASH_INFO_* */
1638 uint32_t flags;
1639 /* Maximum size to use to send data to write to the EC. */
1640 uint32_t write_ideal_size;
1641 /* Number of banks present in the EC. */
1642 uint16_t num_banks_total;
1643 /* Number of banks described in banks array. */
1644 uint16_t num_banks_desc;
1645 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001646} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001647
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001648/*
1649 * Read flash
1650 *
1651 * Response is params.size bytes of data.
1652 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001653#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001654
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001655/**
1656 * struct ec_params_flash_read - Parameters for the flash read command.
1657 * @offset: Byte offset to read.
1658 * @size: Size to read in bytes.
1659 */
1660struct ec_params_flash_read {
1661 uint32_t offset;
1662 uint32_t size;
1663} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001664
1665/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001666#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001667#define EC_VER_FLASH_WRITE 1
1668
1669/* Version 0 of the flash command supported only 64 bytes of data */
1670#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001671
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001672/**
1673 * struct ec_params_flash_write - Parameters for the flash write command.
1674 * @offset: Byte offset to write.
1675 * @size: Size to write in bytes.
1676 */
1677struct ec_params_flash_write {
1678 uint32_t offset;
1679 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001680 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001681} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001682
1683/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001684#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001685
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001686/**
1687 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1688 * @offset: Byte offset to erase.
1689 * @size: Size to erase in bytes.
1690 */
1691struct ec_params_flash_erase {
1692 uint32_t offset;
1693 uint32_t size;
1694} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001695
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001696/*
1697 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001698 * subcommands can returns:
1699 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1700 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1701 * EC_RES_ERROR : other errors.
1702 * EC_RES_BUSY : an existing erase operation is in progress.
1703 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1704 *
1705 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1706 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1707 * the proper result.
1708 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1709 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1710 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1711 * permitted while erasing. (For instance, STM32F4).
1712 */
1713enum ec_flash_erase_cmd {
1714 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1715 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1716 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1717};
1718
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001719/**
1720 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1721 * @cmd: One of ec_flash_erase_cmd.
1722 * @reserved: Pad byte; currently always contains 0.
1723 * @flag: No flags defined yet; set to 0.
1724 * @params: Same as v0 parameters.
1725 */
1726struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001727 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001728 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001729 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001730 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001731} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001732
1733/*
1734 * Get/set flash protection.
1735 *
1736 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1737 * firmware write protect GPIO, not all flags will take effect immediately;
1738 * some flags require a subsequent hard reset to take effect. Check the
1739 * returned flags bits to see what actually happened.
1740 *
1741 * If mask=0, simply returns the current flags state.
1742 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001743#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001744#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1745
1746/* Flags for flash protection */
1747/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001748#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001749/*
1750 * RO flash code protected now. If this bit is set, at-boot status cannot
1751 * be changed.
1752 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001753#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001754/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001755#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001756/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001757#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001758/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001759#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001760/*
1761 * Error - flash protection is in inconsistent state. At least one bank of
1762 * flash which should be protected is not protected. Usually fixed by
1763 * re-requesting the desired flags, or by a hard reset if that fails.
1764 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001765#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001766/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001767#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001768/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001769#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001770/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001771#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001772/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001773#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001774/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001775#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08001776/* Error - Unknown error */
1777#define EC_FLASH_PROTECT_ERROR_UNKNOWN BIT(11)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001778
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001779
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001780/**
1781 * struct ec_params_flash_protect - Parameters for the flash protect command.
1782 * @mask: Bits in flags to apply.
1783 * @flags: New flags to apply.
1784 */
1785struct ec_params_flash_protect {
1786 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001787 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001788} __ec_align4;
1789
1790/**
1791 * struct ec_response_flash_protect - Response to the flash protect command.
1792 * @flags: Current value of flash protect flags.
1793 * @valid_flags: Flags which are valid on this platform. This allows the
1794 * caller to distinguish between flags which aren't set vs. flags
1795 * which can't be set on this platform.
1796 * @writable_flags: Flags which can be changed given the current protection
1797 * state.
1798 */
1799struct ec_response_flash_protect {
1800 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001801 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001802 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001803} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001804
1805/*
1806 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1807 * write protect. These commands may be reused with version > 0.
1808 */
1809
1810/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001811#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001812#define EC_VER_FLASH_REGION_INFO 1
1813
1814enum ec_flash_region {
1815 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001816 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001817 /*
1818 * Region which holds active RW image. 'Active' is different from
1819 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1820 * scheduled to run, active/non-active applies only to RW images (for
1821 * the same reason 'update' applies only to RW images. It's a state of
1822 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1823 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1824 * doesn't enter 'running' state but it's still active on a flash.
1825 */
1826 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001827 /*
1828 * Region which should be write-protected in the factory (a superset of
1829 * EC_FLASH_REGION_RO)
1830 */
1831 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001832 /* Region which holds updatable (non-active) RW image */
1833 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001834 /* Number of regions */
1835 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001836};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001837/*
1838 * 'RW' is vague if there are multiple RW images; we mean the active one,
1839 * so the old constant is deprecated.
1840 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001841#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001842
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001843/**
1844 * struct ec_params_flash_region_info - Parameters for the flash region info
1845 * command.
1846 * @region: Flash region; see EC_FLASH_REGION_*
1847 */
1848struct ec_params_flash_region_info {
1849 uint32_t region;
1850} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001852struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001853 uint32_t offset;
1854 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001855} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001856
Rob Barnes8bc5fa92021-06-28 09:32:28 -06001857/*
1858 * Read/write VbNvContext
1859 *
1860 * Deprecated as of February 2021. No current devices use VBNV in EC
1861 * BBRAM anymore, so this is guaranteed to fail.
1862 *
1863 * TODO(b/178689388): remove from this header once no external
1864 * dependencies reference these constants.
1865 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001866#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001867#define EC_VER_VBNV_CONTEXT 1
1868#define EC_VBNV_BLOCK_SIZE 16
1869
1870enum ec_vbnvcontext_op {
1871 EC_VBNV_CONTEXT_OP_READ,
1872 EC_VBNV_CONTEXT_OP_WRITE,
1873};
1874
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001875struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001876 uint32_t op;
1877 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001878} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001879
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001880struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001881 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001882} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001883
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001884
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001885/* Get SPI flash information */
1886#define EC_CMD_FLASH_SPI_INFO 0x0018
1887
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001888struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001889 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1890 uint8_t jedec[3];
1891
1892 /* Pad byte; currently always contains 0 */
1893 uint8_t reserved0;
1894
1895 /* Manufacturer / device ID from command 0x90 */
1896 uint8_t mfr_dev_id[2];
1897
1898 /* Status registers from command 0x05 and 0x35 */
1899 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001900} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001901
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001902
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001903/* Select flash during flash operations */
1904#define EC_CMD_FLASH_SELECT 0x0019
1905
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001906/**
1907 * struct ec_params_flash_select - Parameters for the flash select command.
1908 * @select: 1 to select flash, 0 to deselect flash
1909 */
1910struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001911 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001912} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001913
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06001914
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001915/**
1916 * Request random numbers to be generated and returned.
1917 * Can be used to test the random number generator is truly random.
1918 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1919 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1920 */
1921#define EC_CMD_RAND_NUM 0x001A
1922#define EC_VER_RAND_NUM 0
1923
1924struct ec_params_rand_num {
1925 uint16_t num_rand_bytes; /**< num random bytes to generate */
1926} __ec_align4;
1927
1928struct ec_response_rand_num {
1929 uint8_t rand[0]; /**< generated random numbers */
1930} __ec_align4;
1931
1932BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1933
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001934/**
1935 * Get information about the key used to sign the RW firmware.
1936 * For more details on the fields, see "struct vb21_packed_key".
1937 */
1938#define EC_CMD_RWSIG_INFO 0x001B
1939#define EC_VER_RWSIG_INFO 0
1940
1941#define VBOOT2_KEY_ID_BYTES 20
1942
1943#ifdef CHROMIUM_EC
1944/* Don't force external projects to depend on the vboot headers. */
1945#include "vb21_struct.h"
1946BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1947#endif
1948
1949struct ec_response_rwsig_info {
1950 /**
1951 * Signature algorithm used by the key
1952 * (enum vb2_signature_algorithm).
1953 */
1954 uint16_t sig_alg;
1955
1956 /**
1957 * Hash digest algorithm used with the key
1958 * (enum vb2_hash_algorithm).
1959 */
1960 uint16_t hash_alg;
1961
1962 /** Key version. */
1963 uint32_t key_version;
1964
1965 /** Key ID (struct vb2_id). */
1966 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
1967
1968 uint8_t key_is_valid;
1969
1970 /** Alignment padding. */
1971 uint8_t reserved[3];
1972} __ec_align4;
1973
1974BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
1975
1976/**
1977 * Get information about the system, such as reset flags, locked state, etc.
1978 */
1979#define EC_CMD_SYSINFO 0x001C
1980#define EC_VER_SYSINFO 0
1981
1982enum sysinfo_flags {
1983 SYSTEM_IS_LOCKED = BIT(0),
1984 SYSTEM_IS_FORCE_LOCKED = BIT(1),
1985 SYSTEM_JUMP_ENABLED = BIT(2),
1986 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
Scott Chao18141d8c2021-07-30 10:40:57 +08001987 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4),
1988 /*
1989 * Used internally. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is
1990 * set and cleared when the system shuts down (not when the host event
1991 * flag is cleared).
1992 */
1993 SYSTEM_IN_MANUAL_RECOVERY = BIT(5),
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001994};
1995
1996struct ec_response_sysinfo {
1997 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
1998 uint32_t current_image; /**< enum ec_current_image */
1999 uint32_t flags; /**< enum sysinfo_flags */
2000} __ec_align4;
2001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002002/*****************************************************************************/
2003/* PWM commands */
2004
2005/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002006#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002007
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002008struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002009 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002010} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002011
2012/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002013#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002014
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002015/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002016struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002017 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002018} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002019
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002020/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002021struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002022 uint32_t rpm;
2023 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002024} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002025
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002026/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002027/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002028#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002029
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002030struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002031 uint8_t percent;
2032 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002033} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002034
2035/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07002036/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002037#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002038
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002039struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002040 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002041} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002042
2043/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002044#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002045
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002046/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002047struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002048 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002049} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002050
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002051/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002052struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002053 uint32_t percent;
2054 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002055} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002056
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002057#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07002058/* 16 bit duty cycle, 0xffff = 100% */
2059#define EC_PWM_MAX_DUTY 0xffff
2060
2061enum ec_pwm_type {
2062 /* All types, indexed by board-specific enum pwm_channel */
2063 EC_PWM_TYPE_GENERIC = 0,
2064 /* Keyboard backlight */
2065 EC_PWM_TYPE_KB_LIGHT,
2066 /* Display backlight */
2067 EC_PWM_TYPE_DISPLAY_LIGHT,
2068 EC_PWM_TYPE_COUNT,
2069};
2070
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002071struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002072 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
2073 uint8_t pwm_type; /* ec_pwm_type */
2074 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002075} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002076
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002077#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07002078
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002079struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002080 uint8_t pwm_type; /* ec_pwm_type */
2081 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002082} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002083
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002084struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07002085 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002086} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07002087
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002088/*****************************************************************************/
2089/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002090 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002091 * command to say "talk to the lightbar", we put the "and tell it to do X" part
2092 * into a subcommand. We'll make separate structs for subcommands with
2093 * different input args, so that we know how much to expect.
2094 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002095#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002096
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002097struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07002098 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002099} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002100
Duncan Laurie433432b2013-06-03 10:38:22 -07002101#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002102
2103/*
2104 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002105 * host command, but the alignment is the same regardless. Keep it that way.
2106 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002107struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002108 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002109 int32_t google_ramp_up;
2110 int32_t google_ramp_down;
2111 int32_t s3s0_ramp_up;
2112 int32_t s0_tick_delay[2]; /* AC=0/1 */
2113 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2114 int32_t s0s3_ramp_down;
2115 int32_t s3_sleep_for;
2116 int32_t s3_ramp_up;
2117 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002118
2119 /* Oscillation */
2120 uint8_t new_s0;
2121 uint8_t osc_min[2]; /* AC=0/1 */
2122 uint8_t osc_max[2]; /* AC=0/1 */
2123 uint8_t w_ofs[2]; /* AC=0/1 */
2124
2125 /* Brightness limits based on the backlight and AC. */
2126 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2127 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2128 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2129
2130 /* Battery level thresholds */
2131 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2132
2133 /* Map [AC][battery_level] to color index */
2134 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2135 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2136
2137 /* Color palette */
2138 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002139} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002140
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002141struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002142 /* Timing */
2143 int32_t google_ramp_up;
2144 int32_t google_ramp_down;
2145 int32_t s3s0_ramp_up;
2146 int32_t s0_tick_delay[2]; /* AC=0/1 */
2147 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2148 int32_t s0s3_ramp_down;
2149 int32_t s3_sleep_for;
2150 int32_t s3_ramp_up;
2151 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002152 int32_t s5_ramp_up;
2153 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002154 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002155 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002156 int32_t tap_display_time;
2157
2158 /* Tap-for-battery params */
2159 uint8_t tap_pct_red;
2160 uint8_t tap_pct_green;
2161 uint8_t tap_seg_min_on;
2162 uint8_t tap_seg_max_on;
2163 uint8_t tap_seg_osc;
2164 uint8_t tap_idx[3];
2165
2166 /* Oscillation */
2167 uint8_t osc_min[2]; /* AC=0/1 */
2168 uint8_t osc_max[2]; /* AC=0/1 */
2169 uint8_t w_ofs[2]; /* AC=0/1 */
2170
2171 /* Brightness limits based on the backlight and AC. */
2172 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2173 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2174 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2175
2176 /* Battery level thresholds */
2177 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2178
2179 /* Map [AC][battery_level] to color index */
2180 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2181 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2182
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002183 /* s5: single color pulse on inhibited power-up */
2184 uint8_t s5_idx;
2185
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002186 /* Color palette */
2187 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002188} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002189
Duncan Laurieeb316852015-12-01 18:51:18 -08002190/* Lightbar command params v2
2191 * crbug.com/467716
2192 *
2193 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2194 * logical groups to make it more manageable ( < 120 bytes).
2195 *
2196 * NOTE: Each of these groups must be less than 120 bytes.
2197 */
2198
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002199struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002200 /* Timing */
2201 int32_t google_ramp_up;
2202 int32_t google_ramp_down;
2203 int32_t s3s0_ramp_up;
2204 int32_t s0_tick_delay[2]; /* AC=0/1 */
2205 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2206 int32_t s0s3_ramp_down;
2207 int32_t s3_sleep_for;
2208 int32_t s3_ramp_up;
2209 int32_t s3_ramp_down;
2210 int32_t s5_ramp_up;
2211 int32_t s5_ramp_down;
2212 int32_t tap_tick_delay;
2213 int32_t tap_gate_delay;
2214 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002215} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002216
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002217struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002218 /* Tap-for-battery params */
2219 uint8_t tap_pct_red;
2220 uint8_t tap_pct_green;
2221 uint8_t tap_seg_min_on;
2222 uint8_t tap_seg_max_on;
2223 uint8_t tap_seg_osc;
2224 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002225} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002226
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002227struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002228 /* Oscillation */
2229 uint8_t osc_min[2]; /* AC=0/1 */
2230 uint8_t osc_max[2]; /* AC=0/1 */
2231 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002232} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002233
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002234struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002235 /* Brightness limits based on the backlight and AC. */
2236 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2237 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2238 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002239} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002240
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002241struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002242 /* Battery level thresholds */
2243 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002244} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002245
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002246struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002247 /* Map [AC][battery_level] to color index */
2248 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2249 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2250
2251 /* s5: single color pulse on inhibited power-up */
2252 uint8_t s5_idx;
2253
2254 /* Color palette */
2255 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002256} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002257
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002258/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002259#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002260struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002261 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002262 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002263} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002264
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002265struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002266 uint8_t cmd; /* Command (see enum lightbar_command) */
2267 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002268 /*
2269 * The following commands have no args:
2270 *
2271 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2272 * version, get_brightness, get_demo, suspend, resume,
2273 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2274 * get_params_v2_bright, get_params_v2_thlds,
2275 * get_params_v2_colors
2276 *
2277 * Don't use an empty struct, because C++ hates that.
2278 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002279
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 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002283
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002284 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002285 uint8_t ctrl, reg, value;
2286 } reg;
2287
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002288 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002289 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002290 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002291
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002292 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002293 uint8_t led;
2294 } get_rgb;
2295
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002296 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002297 uint8_t enable;
2298 } manual_suspend_ctrl;
2299
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002300 struct lightbar_params_v0 set_params_v0;
2301 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002302
2303 struct lightbar_params_v2_timing set_v2par_timing;
2304 struct lightbar_params_v2_tap set_v2par_tap;
2305 struct lightbar_params_v2_oscillation set_v2par_osc;
2306 struct lightbar_params_v2_brightness set_v2par_bright;
2307 struct lightbar_params_v2_thresholds set_v2par_thlds;
2308 struct lightbar_params_v2_colors set_v2par_colors;
2309
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002310 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002311 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002312} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002313
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002314struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002315 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002316 struct __ec_todo_unpacked {
2317 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002318 uint8_t reg;
2319 uint8_t ic0;
2320 uint8_t ic1;
2321 } vals[23];
2322 } dump;
2323
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002324 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002325 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002326 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002327
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002328 struct lightbar_params_v0 get_params_v0;
2329 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002330
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002331
Duncan Laurieeb316852015-12-01 18:51:18 -08002332 struct lightbar_params_v2_timing get_params_v2_timing;
2333 struct lightbar_params_v2_tap get_params_v2_tap;
2334 struct lightbar_params_v2_oscillation get_params_v2_osc;
2335 struct lightbar_params_v2_brightness get_params_v2_bright;
2336 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2337 struct lightbar_params_v2_colors get_params_v2_colors;
2338
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002339 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002340 uint32_t num;
2341 uint32_t flags;
2342 } version;
2343
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002344 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002345 uint8_t red, green, blue;
2346 } get_rgb;
2347
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002348 /*
2349 * The following commands have no response:
2350 *
2351 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2352 * set_params_v0, set_params_v1, set_program,
2353 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2354 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2355 * set_v2par_thlds, set_v2par_colors
2356 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002357 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002358} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002359
2360/* Lightbar commands */
2361enum lightbar_command {
2362 LIGHTBAR_CMD_DUMP = 0,
2363 LIGHTBAR_CMD_OFF = 1,
2364 LIGHTBAR_CMD_ON = 2,
2365 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002366 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002367 LIGHTBAR_CMD_SEQ = 5,
2368 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002369 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002370 LIGHTBAR_CMD_GET_SEQ = 8,
2371 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002372 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2373 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002374 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002375 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2376 LIGHTBAR_CMD_GET_RGB = 14,
2377 LIGHTBAR_CMD_GET_DEMO = 15,
2378 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2379 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002380 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002381 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2382 LIGHTBAR_CMD_SUSPEND = 20,
2383 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002384 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2385 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2386 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2387 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2388 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2389 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2390 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2391 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2392 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2393 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2394 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2395 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002396 LIGHTBAR_NUM_CMDS
2397};
2398
2399/*****************************************************************************/
2400/* LED control commands */
2401
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002402#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002403
Bill Richardsone221aad2013-06-12 10:50:41 -07002404enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002405 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002406 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002407 /*
2408 * LED to indicate system power state (on or in suspend).
2409 * May be on power button or on C-panel.
2410 */
2411 EC_LED_ID_POWER_LED,
2412 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002413 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002414 /* LED to indicate left side */
2415 EC_LED_ID_LEFT_LED,
2416 /* LED to indicate right side */
2417 EC_LED_ID_RIGHT_LED,
2418 /* LED to indicate recovery mode with HW_REINIT */
2419 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2420 /* LED to indicate sysrq debug mode. */
2421 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002422
2423 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002424};
Duncan Laurie433432b2013-06-03 10:38:22 -07002425
Bill Richardsone221aad2013-06-12 10:50:41 -07002426/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002427#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2428#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002429
2430enum ec_led_colors {
2431 EC_LED_COLOR_RED = 0,
2432 EC_LED_COLOR_GREEN,
2433 EC_LED_COLOR_BLUE,
2434 EC_LED_COLOR_YELLOW,
2435 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002436 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002437
2438 EC_LED_COLOR_COUNT
2439};
2440
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002441struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002442 uint8_t led_id; /* Which LED to control */
2443 uint8_t flags; /* Control flags */
2444
2445 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002446} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002447
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002448struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002449 /*
2450 * Available brightness value range.
2451 *
2452 * Range 0 means color channel not present.
2453 * Range 1 means on/off control.
2454 * Other values means the LED is control by PWM.
2455 */
2456 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002457} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002458
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002459/*****************************************************************************/
2460/* Verified boot commands */
2461
2462/*
2463 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2464 * reused for other purposes with version > 0.
2465 */
2466
2467/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002468#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002469
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002470struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002471 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2472 uint8_t hash_type; /* enum ec_vboot_hash_type */
2473 uint8_t nonce_size; /* Nonce size; may be 0 */
2474 uint8_t reserved0; /* Reserved; set 0 */
2475 uint32_t offset; /* Offset in flash to hash */
2476 uint32_t size; /* Number of bytes to hash */
2477 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002478} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002479
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002480struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002481 uint8_t status; /* enum ec_vboot_hash_status */
2482 uint8_t hash_type; /* enum ec_vboot_hash_type */
2483 uint8_t digest_size; /* Size of hash digest in bytes */
2484 uint8_t reserved0; /* Ignore; will be 0 */
2485 uint32_t offset; /* Offset in flash which was hashed */
2486 uint32_t size; /* Number of bytes hashed */
2487 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002488} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002489
2490enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002491 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2492 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2493 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2494 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002495};
2496
2497enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002498 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002499};
2500
2501enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002502 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2503 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2504 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002505};
2506
Duncan Laurie433432b2013-06-03 10:38:22 -07002507/*
2508 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2509 * If one of these is specified, the EC will automatically update offset and
2510 * size to the correct values for the specified image (RO or RW).
2511 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002512#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2513#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2514#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002516/*
2517 * 'RW' is vague if there are multiple RW images; we mean the active one,
2518 * so the old constant is deprecated.
2519 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002520#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002521
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002522/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002523/*
2524 * Motion sense commands. We'll make separate structs for sub-commands with
2525 * different input args, so that we know how much to expect.
2526 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002527#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002528
2529/* Motion sense commands */
2530enum motionsense_command {
2531 /*
2532 * Dump command returns all motion sensor data including motion sense
2533 * module flags and individual sensor flags.
2534 */
2535 MOTIONSENSE_CMD_DUMP = 0,
2536
2537 /*
2538 * Info command returns data describing the details of a given sensor,
2539 * including enum motionsensor_type, enum motionsensor_location, and
2540 * enum motionsensor_chip.
2541 */
2542 MOTIONSENSE_CMD_INFO = 1,
2543
2544 /*
2545 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002546 * in milliseconds.
2547 * It is per sensor, the EC run sample task at the minimum of all
2548 * sensors EC_RATE.
2549 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2550 * to collect all the sensor samples.
2551 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2552 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002553 */
2554 MOTIONSENSE_CMD_EC_RATE = 2,
2555
2556 /*
2557 * Sensor ODR command is a setter/getter command for the output data
2558 * rate of a specific motion sensor in millihertz.
2559 */
2560 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2561
2562 /*
2563 * Sensor range command is a setter/getter command for the range of
2564 * a specified motion sensor in +/-G's or +/- deg/s.
2565 */
2566 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2567
2568 /*
2569 * Setter/getter command for the keyboard wake angle. When the lid
2570 * angle is greater than this value, keyboard wake is disabled in S3,
2571 * and when the lid angle goes less than this value, keyboard wake is
2572 * enabled. Note, the lid angle measurement is an approximate,
2573 * un-calibrated value, hence the wake angle isn't exact.
2574 */
2575 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2576
Duncan Laurieeb316852015-12-01 18:51:18 -08002577 /*
2578 * Returns a single sensor data.
2579 */
2580 MOTIONSENSE_CMD_DATA = 6,
2581
2582 /*
2583 * Return sensor fifo info.
2584 */
2585 MOTIONSENSE_CMD_FIFO_INFO = 7,
2586
2587 /*
2588 * Insert a flush element in the fifo and return sensor fifo info.
2589 * The host can use that element to synchronize its operation.
2590 */
2591 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2592
2593 /*
2594 * Return a portion of the fifo.
2595 */
2596 MOTIONSENSE_CMD_FIFO_READ = 9,
2597
2598 /*
2599 * Perform low level calibration.
2600 * On sensors that support it, ask to do offset calibration.
2601 */
2602 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2603
2604 /*
2605 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002606 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002607 * The offsets can be calculated by the host, or via
2608 * PERFORM_CALIB command.
2609 */
2610 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2611
2612 /*
2613 * List available activities for a MOTION sensor.
2614 * Indicates if they are enabled or disabled.
2615 */
2616 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2617
2618 /*
2619 * Activity management
2620 * Enable/Disable activity recognition.
2621 */
2622 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2623
2624 /*
2625 * Lid Angle
2626 */
2627 MOTIONSENSE_CMD_LID_ANGLE = 14,
2628
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002629 /*
2630 * Allow the FIFO to trigger interrupt via MKBP events.
2631 * By default the FIFO does not send interrupt to process the FIFO
2632 * until the AP is ready or it is coming from a wakeup sensor.
2633 */
2634 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2635
2636 /*
2637 * Spoof the readings of the sensors. The spoofed readings can be set
2638 * to arbitrary values, or will lock to the last read actual values.
2639 */
2640 MOTIONSENSE_CMD_SPOOF = 16,
2641
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002642 /* Set lid angle for tablet mode detection. */
2643 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2644
2645 /*
2646 * Sensor Scale command is a setter/getter command for the calibration
2647 * scale.
2648 */
2649 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2650
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002651 /*
2652 * Read the current online calibration values (if available).
2653 */
2654 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2655
Yidi Lin42f79592020-09-21 18:04:10 +08002656 /*
2657 * Activity management
2658 * Retrieve current status of given activity.
2659 */
2660 MOTIONSENSE_CMD_GET_ACTIVITY = 20,
2661
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002662 /* Number of motionsense sub-commands. */
2663 MOTIONSENSE_NUM_CMDS
2664};
2665
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002666/* List of motion sensor types. */
2667enum motionsensor_type {
2668 MOTIONSENSE_TYPE_ACCEL = 0,
2669 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002670 MOTIONSENSE_TYPE_MAG = 2,
2671 MOTIONSENSE_TYPE_PROX = 3,
2672 MOTIONSENSE_TYPE_LIGHT = 4,
2673 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002674 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002675 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002676 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002677 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002678};
2679
2680/* List of motion sensor locations. */
2681enum motionsensor_location {
2682 MOTIONSENSE_LOC_BASE = 0,
2683 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002684 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002685 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002686};
2687
2688/* List of motion sensor chips. */
2689enum motionsensor_chip {
2690 MOTIONSENSE_CHIP_KXCJ9 = 0,
2691 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002692 MOTIONSENSE_CHIP_BMI160 = 2,
2693 MOTIONSENSE_CHIP_SI1141 = 3,
2694 MOTIONSENSE_CHIP_SI1142 = 4,
2695 MOTIONSENSE_CHIP_SI1143 = 5,
2696 MOTIONSENSE_CHIP_KX022 = 6,
2697 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002698 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002699 MOTIONSENSE_CHIP_BMP280 = 9,
2700 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002701 MOTIONSENSE_CHIP_BH1730 = 11,
2702 MOTIONSENSE_CHIP_GPIO = 12,
2703 MOTIONSENSE_CHIP_LIS2DH = 13,
2704 MOTIONSENSE_CHIP_LSM6DSM = 14,
2705 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002706 MOTIONSENSE_CHIP_LIS2MDL = 16,
2707 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2708 MOTIONSENSE_CHIP_LSM6DSO = 18,
2709 MOTIONSENSE_CHIP_LNG2DM = 19,
2710 MOTIONSENSE_CHIP_TCS3400 = 20,
2711 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2712 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002713 MOTIONSENSE_CHIP_LIS2DS = 23,
Yidi Lin42f79592020-09-21 18:04:10 +08002714 MOTIONSENSE_CHIP_BMI260 = 24,
2715 MOTIONSENSE_CHIP_ICM426XX = 25,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002716 MOTIONSENSE_CHIP_ICM42607 = 26,
Scott Chao18141d8c2021-07-30 10:40:57 +08002717 MOTIONSENSE_CHIP_BMA422 = 27,
2718 MOTIONSENSE_CHIP_BMI323 = 28,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002719 MOTIONSENSE_CHIP_BMI220 = 29,
2720 MOTIONSENSE_CHIP_CM32183 = 30,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002721 MOTIONSENSE_CHIP_MAX,
2722};
2723
2724/* List of orientation positions */
2725enum motionsensor_orientation {
2726 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2727 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2728 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2729 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2730 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002731};
2732
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002733struct ec_response_activity_data {
2734 uint8_t activity; /* motionsensor_activity */
2735 uint8_t state;
2736} __ec_todo_packed;
2737
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002738struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002739 /* Flags for each sensor. */
2740 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002741 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002742 uint8_t sensor_num;
2743 /* Each sensor is up to 3-axis. */
2744 union {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002745 int16_t data[3];
Yidi Lin42f79592020-09-21 18:04:10 +08002746 /* for sensors using unsigned data */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002747 uint16_t udata[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002748 struct __ec_todo_packed {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002749 uint16_t reserved;
2750 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002751 };
2752 struct __ec_todo_unpacked {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08002753 struct ec_response_activity_data activity_data;
2754 int16_t add_info[2];
Duncan Laurieeb316852015-12-01 18:51:18 -08002755 };
2756 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002757} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002758
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002759/* Response to AP reporting calibration data for a given sensor. */
2760struct ec_response_online_calibration_data {
2761 /** The calibration values. */
2762 int16_t data[3];
2763};
2764
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002765/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002766struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002767 /* Size of the fifo */
2768 uint16_t size;
2769 /* Amount of space used in the fifo */
2770 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002771 /* Timestamp recorded in us.
2772 * aka accurate timestamp when host event was triggered.
2773 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002774 uint32_t timestamp;
2775 /* Total amount of vector lost */
2776 uint16_t total_lost;
2777 /* Lost events since the last fifo_info, per sensors */
2778 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002779} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002780
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002781struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002782 uint32_t number_data;
2783 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002784} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002785
2786/* List supported activity recognition */
2787enum motionsensor_activity {
2788 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2789 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2790 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002791 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Yidi Lin42f79592020-09-21 18:04:10 +08002792 MOTIONSENSE_ACTIVITY_BODY_DETECTION = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002793};
2794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002795struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002796 uint8_t sensor_num;
2797 uint8_t activity; /* one of enum motionsensor_activity */
2798 uint8_t enable; /* 1: enable, 0: disable */
2799 uint8_t reserved;
2800 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002801} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002802
2803/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002804#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002805
2806/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002807#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002808
2809/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002810 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002811 * data contains time stamp
2812 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002813#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2814#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2815#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2816#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2817#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002818
Rob Barnes8bc5fa92021-06-28 09:32:28 -06002819#define MOTIONSENSE_SENSOR_FLAG_BYPASS_FIFO BIT(7)
2820
Duncan Laurieeb316852015-12-01 18:51:18 -08002821/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002822 * Send this value for the data element to only perform a read. If you
2823 * send any other value, the EC will interpret it as data to set and will
2824 * return the actual value set.
2825 */
2826#define EC_MOTION_SENSE_NO_VALUE -1
2827
Duncan Laurieeb316852015-12-01 18:51:18 -08002828#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2829
2830/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2831/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002832#define MOTION_SENSE_SET_OFFSET BIT(0)
2833
2834/* Default Scale value, factor 1. */
2835#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002836
2837#define LID_ANGLE_UNRELIABLE 500
2838
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002839enum motionsense_spoof_mode {
2840 /* Disable spoof mode. */
2841 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2842
2843 /* Enable spoof mode, but use provided component values. */
2844 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2845
2846 /* Enable spoof mode, but use the current sensor values. */
2847 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2848
2849 /* Query the current spoof mode status for the sensor. */
2850 MOTIONSENSE_SPOOF_MODE_QUERY,
2851};
2852
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002853struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002854 uint8_t cmd;
2855 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002856 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002857 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002858 /*
2859 * Maximal number of sensor the host is expecting.
2860 * 0 means the host is only interested in the number
2861 * of sensors controlled by the EC.
2862 */
2863 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002864 } dump;
2865
2866 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002867 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002868 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002869 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002870 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08002871 * kb_wake_angle: angle to wakup AP.
Duncan Laurieeb316852015-12-01 18:51:18 -08002872 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002873 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002874 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002875
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002876 /*
2877 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2878 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002879 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002880 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002881 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002882
2883 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002884 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2885 * Allow entering/exiting the calibration mode.
2886 */
2887 struct __ec_todo_unpacked {
2888 uint8_t sensor_num;
2889 uint8_t enable;
2890 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002891
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002892 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002893 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2894 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002895 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002896 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002897 uint8_t sensor_num;
2898
2899 /* Rounding flag, true for round-up, false for down. */
2900 uint8_t roundup;
2901
2902 uint16_t reserved;
2903
2904 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2905 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002906 } ec_rate, sensor_odr, sensor_range;
2907
2908 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002909 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002910 uint8_t sensor_num;
2911
2912 /*
2913 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2914 * the calibration information in the EC.
2915 * If unset, just retrieve calibration information.
2916 */
2917 uint16_t flags;
2918
2919 /*
2920 * Temperature at calibration, in units of 0.01 C
2921 * 0x8000: invalid / unknown.
2922 * 0x0: 0C
2923 * 0x7fff: +327.67C
2924 */
2925 int16_t temp;
2926
2927 /*
2928 * Offset for calibration.
2929 * Unit:
2930 * Accelerometer: 1/1024 g
2931 * Gyro: 1/1024 deg/s
2932 * Compass: 1/16 uT
2933 */
2934 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002935 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002936
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002937 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2938 struct __ec_todo_packed {
2939 uint8_t sensor_num;
2940
2941 /*
2942 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2943 * the calibration information in the EC.
2944 * If unset, just retrieve calibration information.
2945 */
2946 uint16_t flags;
2947
2948 /*
2949 * Temperature at calibration, in units of 0.01 C
2950 * 0x8000: invalid / unknown.
2951 * 0x0: 0C
2952 * 0x7fff: +327.67C
2953 */
2954 int16_t temp;
2955
2956 /*
2957 * Scale for calibration:
2958 * By default scale is 1, it is encoded on 16bits:
2959 * 1 = BIT(15)
2960 * ~2 = 0xFFFF
2961 * ~0 = 0.
2962 */
2963 uint16_t scale[3];
2964 } sensor_scale;
2965
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06002966
Duncan Laurieeb316852015-12-01 18:51:18 -08002967 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002968 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002969
2970 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002971 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002972 /*
2973 * Number of expected vector to return.
2974 * EC may return less or 0 if none available.
2975 */
2976 uint32_t max_data_vector;
2977 } fifo_read;
2978
Yidi Lin42f79592020-09-21 18:04:10 +08002979 /* Used for MOTIONSENSE_CMD_SET_ACTIVITY */
Duncan Laurieeb316852015-12-01 18:51:18 -08002980 struct ec_motion_sense_activity set_activity;
2981
2982 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002983 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002984
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002985 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2986 struct __ec_todo_unpacked {
2987 /*
2988 * 1: enable, 0 disable fifo,
2989 * EC_MOTION_SENSE_NO_VALUE return value.
2990 */
2991 int8_t enable;
2992 } fifo_int_enable;
2993
2994 /* Used for MOTIONSENSE_CMD_SPOOF */
2995 struct __ec_todo_packed {
2996 uint8_t sensor_id;
2997
2998 /* See enum motionsense_spoof_mode. */
2999 uint8_t spoof_enable;
3000
3001 /* Ignored, used for alignment. */
3002 uint8_t reserved;
3003
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003004 union {
3005 /* Individual component values to spoof. */
3006 int16_t components[3];
3007
3008 /* Used when spoofing an activity */
3009 struct {
3010 /* enum motionsensor_activity */
3011 uint8_t activity_num;
3012
3013 /* spoof activity state */
3014 uint8_t activity_state;
3015 };
3016 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003017 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003018
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003019 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3020 struct __ec_todo_unpacked {
3021 /*
3022 * Lid angle threshold for switching between tablet and
3023 * clamshell mode.
3024 */
3025 int16_t lid_angle;
3026
3027 /*
3028 * Hysteresis degree to prevent fluctuations between
3029 * clamshell and tablet mode if lid angle keeps
3030 * changing around the threshold. Lid motion driver will
3031 * use lid_angle + hys_degree to trigger tablet mode and
3032 * lid_angle - hys_degree to trigger clamshell mode.
3033 */
3034 int16_t hys_degree;
3035 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003036
3037 /*
3038 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
3039 * Allow reading a single sensor's online calibration value.
3040 */
3041 struct __ec_todo_unpacked {
3042 uint8_t sensor_num;
3043 } online_calib_read;
3044
Yidi Lin42f79592020-09-21 18:04:10 +08003045 /*
3046 * Used for MOTIONSENSE_CMD_GET_ACTIVITY.
3047 */
3048 struct __ec_todo_unpacked {
3049 uint8_t sensor_num;
3050 uint8_t activity; /* enum motionsensor_activity */
3051 } get_activity;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003052 };
3053} __ec_todo_packed;
3054
Jett Rinkba2edaf2020-01-14 11:49:06 -07003055enum motion_sense_cmd_info_flags {
3056 /* The sensor supports online calibration */
3057 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
3058};
3059
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003060struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003061 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003062 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003063 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003064 /* Flags representing the motion sensor module. */
3065 uint8_t module_flags;
3066
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003067 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003068 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003069
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003070 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003071 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003072 * for holding all the data.
3073 */
3074 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003075 } dump;
3076
3077 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003078 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003079 /* Should be element of enum motionsensor_type. */
3080 uint8_t type;
3081
3082 /* Should be element of enum motionsensor_location. */
3083 uint8_t location;
3084
3085 /* Should be element of enum motionsensor_chip. */
3086 uint8_t chip;
3087 } info;
3088
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003089 /* Used for MOTIONSENSE_CMD_INFO version 3 */
3090 struct __ec_todo_unpacked {
3091 /* Should be element of enum motionsensor_type. */
3092 uint8_t type;
3093
3094 /* Should be element of enum motionsensor_location. */
3095 uint8_t location;
3096
3097 /* Should be element of enum motionsensor_chip. */
3098 uint8_t chip;
3099
3100 /* Minimum sensor sampling frequency */
3101 uint32_t min_frequency;
3102
3103 /* Maximum sensor sampling frequency */
3104 uint32_t max_frequency;
3105
3106 /* Max number of sensor events that could be in fifo */
3107 uint32_t fifo_max_event_count;
3108 } info_3;
3109
Jett Rinkba2edaf2020-01-14 11:49:06 -07003110 /* Used for MOTIONSENSE_CMD_INFO version 4 */
3111 struct __ec_align4 {
3112 /* Should be element of enum motionsensor_type. */
3113 uint8_t type;
3114
3115 /* Should be element of enum motionsensor_location. */
3116 uint8_t location;
3117
3118 /* Should be element of enum motionsensor_chip. */
3119 uint8_t chip;
3120
3121 /* Minimum sensor sampling frequency */
3122 uint32_t min_frequency;
3123
3124 /* Maximum sensor sampling frequency */
3125 uint32_t max_frequency;
3126
3127 /* Max number of sensor events that could be in fifo */
3128 uint32_t fifo_max_event_count;
3129
3130 /*
3131 * Should be elements of
3132 * enum motion_sense_cmd_info_flags
3133 */
3134 uint32_t flags;
3135 } info_4;
3136
Duncan Laurieeb316852015-12-01 18:51:18 -08003137 /* Used for MOTIONSENSE_CMD_DATA */
3138 struct ec_response_motion_sensor_data data;
3139
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003140 /*
3141 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003142 * MOTIONSENSE_CMD_SENSOR_RANGE,
3143 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3144 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3145 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003146 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003147 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003148 /* Current value of the parameter queried. */
3149 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003150 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
3151 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003152
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003153 /*
3154 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3155 * PERFORM_CALIB.
3156 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003157 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003158 int16_t temp;
3159 int16_t offset[3];
3160 } sensor_offset, perform_calib;
3161
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003162 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3163 struct __ec_todo_unpacked {
3164 int16_t temp;
3165 uint16_t scale[3];
3166 } sensor_scale;
3167
Duncan Laurieeb316852015-12-01 18:51:18 -08003168 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3169
3170 struct ec_response_motion_sense_fifo_data fifo_read;
3171
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003172 struct ec_response_online_calibration_data online_calib_read;
3173
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003174 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003175 uint16_t reserved;
3176 uint32_t enabled;
3177 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003178 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003179
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003180 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003181
Duncan Laurieeb316852015-12-01 18:51:18 -08003182 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003183 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003184 /*
3185 * Angle between 0 and 360 degree if available,
3186 * LID_ANGLE_UNRELIABLE otherwise.
3187 */
3188 uint16_t value;
3189 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003190
3191 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3192 struct __ec_todo_unpacked {
3193 /*
3194 * Lid angle threshold for switching between tablet and
3195 * clamshell mode.
3196 */
3197 uint16_t lid_angle;
3198
3199 /* Hysteresis degree. */
3200 uint16_t hys_degree;
3201 } tablet_mode_threshold;
3202
Yidi Lin42f79592020-09-21 18:04:10 +08003203 /* USED for MOTIONSENSE_CMD_GET_ACTIVITY. */
3204 struct __ec_todo_unpacked {
3205 uint8_t state;
3206 } get_activity;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003207 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003208} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003209
3210/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003211/* Force lid open command */
3212
3213/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003214#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003215
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003216struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003217 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003218} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003219
3220/*****************************************************************************/
3221/* Configure the behavior of the power button */
3222#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3223
3224enum ec_config_power_button_flags {
3225 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003226 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003227};
3228
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003229struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003230 /* See enum ec_config_power_button_flags */
3231 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003232} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003233
3234/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003235/* USB charging control commands */
3236
3237/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003238#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003239
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003240enum usb_charge_mode {
3241 /* Disable USB port. */
3242 USB_CHARGE_MODE_DISABLED,
3243 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3244 USB_CHARGE_MODE_SDP2,
3245 /* Set USB port to Charging Downstream Port, BC 1.2. */
3246 USB_CHARGE_MODE_CDP,
3247 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3248 USB_CHARGE_MODE_DCP_SHORT,
3249 /* Enable USB port (for dumb ports). */
3250 USB_CHARGE_MODE_ENABLED,
3251 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3252 USB_CHARGE_MODE_DEFAULT,
3253
3254 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003255};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003256
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003257enum usb_suspend_charge {
3258 /* Enable charging in suspend */
3259 USB_ALLOW_SUSPEND_CHARGE,
3260 /* Disable charging in suspend */
3261 USB_DISALLOW_SUSPEND_CHARGE
3262};
3263
3264struct ec_params_usb_charge_set_mode {
3265 uint8_t usb_port_id;
3266 uint8_t mode:7; /* enum usb_charge_mode */
3267 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
3268} __ec_align1;
3269
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003270/*****************************************************************************/
3271/* Persistent storage for host */
3272
3273/* Maximum bytes that can be read/written in a single command */
3274#define EC_PSTORE_SIZE_MAX 64
3275
3276/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003277#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003278
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003279struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003280 /* Persistent storage size, in bytes */
3281 uint32_t pstore_size;
3282 /* Access size; read/write offset and size must be a multiple of this */
3283 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003284} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003285
3286/*
3287 * Read persistent storage
3288 *
3289 * Response is params.size bytes of data.
3290 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003291#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003292
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003293struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003294 uint32_t offset; /* Byte offset to read */
3295 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003296} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003297
3298/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003299#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003301struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003302 uint32_t offset; /* Byte offset to write */
3303 uint32_t size; /* Size to write in bytes */
3304 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003305} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003306
3307/*****************************************************************************/
3308/* Real-time clock */
3309
3310/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003311struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003312 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003313} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003314
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003315struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003316 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003317} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003318
3319/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003320#define EC_CMD_RTC_GET_VALUE 0x0044
3321#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003322
3323/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003324#define EC_CMD_RTC_SET_VALUE 0x0046
3325#define EC_CMD_RTC_SET_ALARM 0x0047
3326
3327/* Pass as time param to SET_ALARM to clear the current alarm */
3328#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003329
3330/*****************************************************************************/
3331/* Port80 log access */
3332
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003333/* Maximum entries that can be read/written in a single command */
3334#define EC_PORT80_SIZE_MAX 32
3335
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003336/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003337#define EC_CMD_PORT80_LAST_BOOT 0x0048
3338#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003339
3340enum ec_port80_subcmd {
3341 EC_PORT80_GET_INFO = 0,
3342 EC_PORT80_READ_BUFFER,
3343};
3344
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003345struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003346 uint16_t subcmd;
3347 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003348 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003349 uint32_t offset;
3350 uint32_t num_entries;
3351 } read_buffer;
3352 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003353} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003354
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003355struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003356 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003357 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003358 uint32_t writes;
3359 uint32_t history_size;
3360 uint32_t last_boot;
3361 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003362 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003363 uint16_t codes[EC_PORT80_SIZE_MAX];
3364 } data;
3365 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003366} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003367
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003368struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003369 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003370} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003371
3372/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003373/* Temporary secure storage for host verified boot use */
3374
3375/* Number of bytes in a vstore slot */
3376#define EC_VSTORE_SLOT_SIZE 64
3377
3378/* Maximum number of vstore slots */
3379#define EC_VSTORE_SLOT_MAX 32
3380
3381/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003382#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003383struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003384 /* Indicates which slots are locked */
3385 uint32_t slot_locked;
3386 /* Total number of slots available */
3387 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003388} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003389
3390/*
3391 * Read temporary secure storage
3392 *
3393 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3394 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003395#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003396
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003397struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003398 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003399} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003400
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003401struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003402 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003403} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003404
3405/*
3406 * Write temporary secure storage and lock it.
3407 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003408#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003409
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003410struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003411 uint8_t slot; /* Slot to write to */
3412 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003413} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003414
3415/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003416/* Thermal engine commands. Note that there are two implementations. We'll
3417 * reuse the command number, but the data and behavior is incompatible.
3418 * Version 0 is what originally shipped on Link.
3419 * Version 1 separates the CPU thermal limits from the fan control.
3420 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003421
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003422#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3423#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003424
Duncan Laurie93e24442014-01-06 12:30:52 -08003425/* The version 0 structs are opaque. You have to know what they are for
3426 * the get/set commands to make any sense.
3427 */
3428
3429/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003430struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003431 uint8_t sensor_type;
3432 uint8_t threshold_id;
3433 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003434} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003435
Duncan Laurie93e24442014-01-06 12:30:52 -08003436/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003437struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003438 uint8_t sensor_type;
3439 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003440} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003441
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003442struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003443 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003444} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003445
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003446
Duncan Laurie93e24442014-01-06 12:30:52 -08003447/* The version 1 structs are visible. */
3448enum ec_temp_thresholds {
3449 EC_TEMP_THRESH_WARN = 0,
3450 EC_TEMP_THRESH_HIGH,
3451 EC_TEMP_THRESH_HALT,
3452
3453 EC_TEMP_THRESH_COUNT
3454};
3455
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003456/*
3457 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003458 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003459 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003460 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3461 * hysteresis.
3462 * For example,
3463 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3464 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3465 * EC will throttle ap when temperature >= 301 K, and release throttling when
3466 * temperature <= 299 K.
3467 *
3468 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3469 * For example,
3470 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3471 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3472 * EC will throttle ap when temperature >= 301 K, and release throttling when
3473 * temperature <= 294 K.
3474 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003475 * Note that this structure is a sub-structure of
3476 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003477 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003478struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003479 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003480 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003481 uint32_t temp_fan_off; /* no active cooling needed */
3482 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003483} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003484
3485/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003486struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003487 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003488} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003489/* This returns a struct ec_thermal_config */
3490
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003491/*
3492 * Version 1 - set config for one sensor.
3493 * Use read-modify-write for best results!
3494 */
3495struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003496 uint32_t sensor_num;
3497 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003498} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003499/* This returns no data */
3500
3501/****************************************************************************/
3502
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003503/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003504#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003505
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003506/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003507struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003508 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003509} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003510
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003511/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003512#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3513#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003514
3515/*
3516 * The original TMP006 calibration only needed four params, but now we need
3517 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3518 * the params opaque. The v1 "get" response will include the algorithm number
3519 * and how many params it requires. That way we can change the EC code without
3520 * needing to update this file. We can also use a different algorithm on each
3521 * sensor.
3522 */
3523
3524/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003525struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003526 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003527} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003528
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003529/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003530struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003531 float s0;
3532 float b0;
3533 float b1;
3534 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003535} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003536
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003537struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003538 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003539 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003540 float s0;
3541 float b0;
3542 float b1;
3543 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003544} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003545
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003546/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003547struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003548 uint8_t algorithm;
3549 uint8_t num_params;
3550 uint8_t reserved[2];
3551 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003552} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003553
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003554struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003555 uint8_t index;
3556 uint8_t algorithm;
3557 uint8_t num_params;
3558 uint8_t reserved;
3559 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003560} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003561
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003562
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003563/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003564#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003565
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003566struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003567 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003568} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003569
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003570struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003571 int32_t t; /* In 1/100 K */
3572 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003573} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003574
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003575/*****************************************************************************/
3576/* MKBP - Matrix KeyBoard Protocol */
3577
3578/*
3579 * Read key state
3580 *
3581 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3582 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003583 *
3584 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3585 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3586 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003587 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003588#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003589
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003590/*
3591 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3592 */
3593#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003594
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003595struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003596 uint32_t rows;
3597 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003598 /* Formerly "switches", which was 0. */
3599 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003600} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003601
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003602struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003603 uint8_t info_type;
3604 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003605} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003606
3607enum ec_mkbp_info_type {
3608 /*
3609 * Info about the keyboard matrix: number of rows and columns.
3610 *
3611 * Returns struct ec_response_mkbp_info.
3612 */
3613 EC_MKBP_INFO_KBD = 0,
3614
3615 /*
3616 * For buttons and switches, info about which specifically are
3617 * supported. event_type must be set to one of the values in enum
3618 * ec_mkbp_event.
3619 *
3620 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3621 * bitmask indicating which buttons or switches are present. See the
3622 * bit inidices below.
3623 */
3624 EC_MKBP_INFO_SUPPORTED = 1,
3625
3626 /*
3627 * Instantaneous state of buttons and switches.
3628 *
3629 * event_type must be set to one of the values in enum ec_mkbp_event.
3630 *
3631 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3632 * indicating the current state of the keyboard matrix.
3633 *
3634 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3635 * event state.
3636 *
3637 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3638 * state of supported buttons.
3639 *
3640 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3641 * state of supported switches.
3642 */
3643 EC_MKBP_INFO_CURRENT = 2,
3644};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003645
3646/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003647#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003648
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003649struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003650 uint8_t col;
3651 uint8_t row;
3652 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003653} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003654
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003655#define EC_CMD_GET_KEYBOARD_ID 0x0063
3656
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003657struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003658 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003659} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003660
3661enum keyboard_id {
3662 KEYBOARD_ID_UNSUPPORTED = 0,
3663 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3664};
3665
Duncan Laurie433432b2013-06-03 10:38:22 -07003666/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003667#define EC_CMD_MKBP_SET_CONFIG 0x0064
3668#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003669
3670/* flags */
3671enum mkbp_config_flags {
3672 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3673};
3674
3675enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003676 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3677 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3678 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3679 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3680 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3681 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3682 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003683};
3684
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003685/*
3686 * Configuration for our key scanning algorithm.
3687 *
3688 * Note that this is used as a sub-structure of
3689 * ec_{params/response}_mkbp_get_config.
3690 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003691struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003692 uint32_t valid_mask; /* valid fields */
3693 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3694 uint8_t valid_flags; /* which flags are valid */
3695 uint16_t scan_period_us; /* period between start of scans */
3696 /* revert to interrupt mode after no activity for this long */
3697 uint32_t poll_timeout_us;
3698 /*
3699 * minimum post-scan relax time. Once we finish a scan we check
3700 * the time until we are due to start the next one. If this time is
3701 * shorter this field, we use this instead.
3702 */
3703 uint16_t min_post_scan_delay_us;
3704 /* delay between setting up output and waiting for it to settle */
3705 uint16_t output_settle_us;
3706 uint16_t debounce_down_us; /* time for debounce on key down */
3707 uint16_t debounce_up_us; /* time for debounce on key up */
3708 /* maximum depth to allow for fifo (0 = no keyscan output) */
3709 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003710} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003711
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003712struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003713 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003714} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003715
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003716struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003717 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003718} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003719
3720/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003721#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003722
3723enum ec_keyscan_seq_cmd {
3724 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3725 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3726 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3727 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3728 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3729};
3730
3731enum ec_collect_flags {
3732 /*
3733 * Indicates this scan was processed by the EC. Due to timing, some
3734 * scans may be skipped.
3735 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003736 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003737};
3738
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003739struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003740 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003741} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003742
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003743struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003744 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3745 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003746 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003747 uint8_t active; /* still active */
3748 uint8_t num_items; /* number of items */
3749 /* Current item being presented */
3750 uint8_t cur_item;
3751 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003752 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003753 /*
3754 * Absolute time for this scan, measured from the
3755 * start of the sequence.
3756 */
3757 uint32_t time_us;
3758 uint8_t scan[0]; /* keyscan data */
3759 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003760 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003761 uint8_t start_item; /* First item to return */
3762 uint8_t num_items; /* Number of items to return */
3763 } collect;
3764 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003765} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003766
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003767struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003768 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003769 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003770 uint8_t num_items; /* Number of items */
3771 /* Data for each item */
3772 struct ec_collect_item item[0];
3773 } collect;
3774 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003775} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003776
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003777/*
3778 * Get the next pending MKBP event.
3779 *
3780 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3781 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003782#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003783
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003784#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3785
3786/*
3787 * We use the most significant bit of the event type to indicate to the host
3788 * that the EC has more MKBP events available to provide.
3789 */
3790#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3791
3792/* The mask to apply to get the raw event type */
3793#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3794
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003795enum ec_mkbp_event {
3796 /* Keyboard matrix changed. The event data is the new matrix state. */
3797 EC_MKBP_EVENT_KEY_MATRIX = 0,
3798
3799 /* New host event. The event data is 4 bytes of host event flags. */
3800 EC_MKBP_EVENT_HOST_EVENT = 1,
3801
Duncan Laurieeb316852015-12-01 18:51:18 -08003802 /* New Sensor FIFO data. The event data is fifo_info structure. */
3803 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3804
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003805 /* The state of the non-matrixed buttons have changed. */
3806 EC_MKBP_EVENT_BUTTON = 3,
3807
3808 /* The state of the switches have changed. */
3809 EC_MKBP_EVENT_SWITCH = 4,
3810
3811 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3812 EC_MKBP_EVENT_FINGERPRINT = 5,
3813
3814 /*
3815 * Sysrq event: send emulated sysrq. The event data is sysrq,
3816 * corresponding to the key to be pressed.
3817 */
3818 EC_MKBP_EVENT_SYSRQ = 6,
3819
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003820 /*
3821 * New 64-bit host event.
3822 * The event data is 8 bytes of host event flags.
3823 */
3824 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3825
3826 /* Notify the AP that something happened on CEC */
3827 EC_MKBP_EVENT_CEC_EVENT = 8,
3828
3829 /* Send an incoming CEC message to the AP */
3830 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3831
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003832 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3833 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3834
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003835 /* New online calibration values are available. */
3836 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3837
Rob Barnes8bc5fa92021-06-28 09:32:28 -06003838 /* Peripheral device charger event */
3839 EC_MKBP_EVENT_PCHG = 12,
3840
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003841 /* Number of MKBP events */
3842 EC_MKBP_EVENT_COUNT,
3843};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003844BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003845
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003846union __ec_align_offset1 ec_response_get_next_data {
3847 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003848
3849 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003850 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003851 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003852
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003853 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003854 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003855 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003856 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003857 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003858
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003859 uint32_t buttons;
3860
3861 uint32_t switches;
3862
3863 uint32_t fp_events;
3864
3865 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003866
3867 /* CEC events from enum mkbp_cec_event */
3868 uint32_t cec_events;
3869};
3870
3871union __ec_align_offset1 ec_response_get_next_data_v1 {
3872 uint8_t key_matrix[16];
3873
3874 /* Unaligned */
3875 uint32_t host_event;
3876 uint64_t host_event64;
3877
3878 struct __ec_todo_unpacked {
3879 /* For aligning the fifo_info */
3880 uint8_t reserved[3];
3881 struct ec_response_motion_sense_fifo_info info;
3882 } sensor_fifo;
3883
3884 uint32_t buttons;
3885
3886 uint32_t switches;
3887
3888 uint32_t fp_events;
3889
3890 uint32_t sysrq;
3891
3892 /* CEC events from enum mkbp_cec_event */
3893 uint32_t cec_events;
3894
3895 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003896};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003897BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003898
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003899struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003900 uint8_t event_type;
3901 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003902 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003903} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003904
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003905struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003906 uint8_t event_type;
3907 /* Followed by event data if any */
3908 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003909} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003910
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003911/* Bit indices for buttons and switches.*/
3912/* Buttons */
3913#define EC_MKBP_POWER_BUTTON 0
3914#define EC_MKBP_VOL_UP 1
3915#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003916#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003917
3918/* Switches */
3919#define EC_MKBP_LID_OPEN 0
3920#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003921#define EC_MKBP_BASE_ATTACHED 2
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08003922#define EC_MKBP_FRONT_PROXIMITY 3
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003923
Gwendal Grignou880b4582016-06-20 08:49:25 -07003924/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003925#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003926
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003927struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003928 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003929} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003930
3931/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3932#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003933#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3934#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3935#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3936 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3937#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3938#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3939#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3940 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003941#define EC_MKBP_FP_ENROLL BIT(27)
3942#define EC_MKBP_FP_MATCH BIT(28)
3943#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3944#define EC_MKBP_FP_FINGER_UP BIT(30)
3945#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003946/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3947#define EC_MKBP_FP_ERR_ENROLL_OK 0
3948#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3949#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3950#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3951#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3952/* Can be used to detect if image was usable for enrollment or not. */
3953#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3954/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3955#define EC_MKBP_FP_ERR_MATCH_NO 0
3956#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003957#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003958#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3959#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3960#define EC_MKBP_FP_ERR_MATCH_YES 1
3961#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3962#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3963
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06003964
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003965#define EC_CMD_MKBP_WAKE_MASK 0x0069
3966enum ec_mkbp_event_mask_action {
3967 /* Retrieve the value of a wake mask. */
3968 GET_WAKE_MASK = 0,
3969
3970 /* Set the value of a wake mask. */
3971 SET_WAKE_MASK,
3972};
3973
3974enum ec_mkbp_mask_type {
3975 /*
3976 * These are host events sent via MKBP.
3977 *
3978 * Some examples are:
3979 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3980 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3981 *
3982 * The only things that should be in this mask are:
3983 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3984 */
3985 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3986
3987 /*
3988 * These are MKBP events. Some examples are:
3989 *
3990 * EC_MKBP_EVENT_KEY_MATRIX
3991 * EC_MKBP_EVENT_SWITCH
3992 *
3993 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3994 */
3995 EC_MKBP_EVENT_WAKE_MASK,
3996};
3997
3998struct ec_params_mkbp_event_wake_mask {
3999 /* One of enum ec_mkbp_event_mask_action */
4000 uint8_t action;
4001
4002 /*
4003 * Which MKBP mask are you interested in acting upon? This is one of
4004 * ec_mkbp_mask_type.
4005 */
4006 uint8_t mask_type;
4007
4008 /* If setting a new wake mask, this contains the mask to set. */
4009 uint32_t new_wake_mask;
4010};
4011
4012struct ec_response_mkbp_event_wake_mask {
4013 uint32_t wake_mask;
4014};
4015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004016/*****************************************************************************/
4017/* Temperature sensor commands */
4018
4019/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004020#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004021
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004022struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004023 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004024} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004025
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004026struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004027 char sensor_name[32];
4028 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004029} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004030
4031/*****************************************************************************/
4032
4033/*
4034 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
4035 * commands accidentally sent to the wrong interface. See the ACPI section
4036 * below.
4037 */
4038
4039/*****************************************************************************/
4040/* Host event commands */
4041
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004042
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004043/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004044/*
4045 * Host event mask params and response structures, shared by all of the host
4046 * event commands below.
4047 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004048struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004049 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004050} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004051
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004052struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004053 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004054} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004055
4056/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004057#define EC_CMD_HOST_EVENT_GET_B 0x0087
4058#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
4059#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
4060#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004061
4062/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004063#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
4064#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
4065#define EC_CMD_HOST_EVENT_CLEAR 0x008C
4066#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
4067#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004068
Jenny TC1dfc2c32017-12-14 14:24:39 +05304069/*
4070 * Unified host event programming interface - Should be used by newer versions
4071 * of BIOS/OS to program host events and masks
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004072 *
4073 * EC returns:
4074 * - EC_RES_INVALID_PARAM: Action or mask type is unknown.
4075 * - EC_RES_ACCESS_DENIED: Action is prohibited for specified mask type.
Jenny TC1dfc2c32017-12-14 14:24:39 +05304076 */
4077
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004078struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304079
4080 /* Action requested by host - one of enum ec_host_event_action. */
4081 uint8_t action;
4082
4083 /*
4084 * Mask type that the host requested the action on - one of
4085 * enum ec_host_event_mask_type.
4086 */
4087 uint8_t mask_type;
4088
4089 /* Set to 0, ignore on read */
4090 uint16_t reserved;
4091
4092 /* Value to be used in case of set operations. */
4093 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004094} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304095
4096/*
4097 * Response structure returned by EC_CMD_HOST_EVENT.
4098 * Update the value on a GET request. Set to 0 on GET/CLEAR
4099 */
4100
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004101struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05304102
4103 /* Mask value in case of get operation */
4104 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004105} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05304106
4107enum ec_host_event_action {
4108 /*
4109 * params.value is ignored. Value of mask_type populated
4110 * in response.value
4111 */
4112 EC_HOST_EVENT_GET,
4113
4114 /* Bits in params.value are set */
4115 EC_HOST_EVENT_SET,
4116
4117 /* Bits in params.value are cleared */
4118 EC_HOST_EVENT_CLEAR,
4119};
4120
4121enum ec_host_event_mask_type {
4122
4123 /* Main host event copy */
4124 EC_HOST_EVENT_MAIN,
4125
4126 /* Copy B of host events */
4127 EC_HOST_EVENT_B,
4128
4129 /* SCI Mask */
4130 EC_HOST_EVENT_SCI_MASK,
4131
4132 /* SMI Mask */
4133 EC_HOST_EVENT_SMI_MASK,
4134
4135 /* Mask of events that should be always reported in hostevents */
4136 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
4137
4138 /* Active wake mask */
4139 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
4140
4141 /* Lazy wake mask for S0ix */
4142 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
4143
4144 /* Lazy wake mask for S3 */
4145 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
4146
4147 /* Lazy wake mask for S5 */
4148 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
4149};
4150
4151#define EC_CMD_HOST_EVENT 0x00A4
4152
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004153/*****************************************************************************/
4154/* Switch commands */
4155
4156/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004157#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004158
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004159struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004160 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004161} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004162
4163/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004164#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004165#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004166
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004167/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004168struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004169 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004170} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004171
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004172/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004173struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004174 /* Flags to enable now */
4175 uint8_t now_flags;
4176
4177 /* Which flags to copy from now_flags */
4178 uint8_t now_mask;
4179
4180 /*
4181 * Flags to leave enabled in S3, if they're on at the S0->S3
4182 * transition. (Other flags will be disabled by the S0->S3
4183 * transition.)
4184 */
4185 uint8_t suspend_flags;
4186
4187 /* Which flags to copy from suspend_flags */
4188 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004189} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004190
4191/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004192struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004193 /* Flags to enable now */
4194 uint8_t now_flags;
4195
4196 /* Flags to leave enabled in S3 */
4197 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004198} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004199
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004200/*****************************************************************************/
4201/* GPIO commands. Only available on EC if write protect has been disabled. */
4202
4203/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004204#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004205
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004206struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004207 char name[32];
4208 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004209} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004210
4211/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004212#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004213
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004214/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004215struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004216 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004217} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004218
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004219struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004220 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004221} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004222
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004223/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004224struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004225 uint8_t subcmd;
4226 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004227 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004228 char name[32];
4229 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004230 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004231 uint8_t index;
4232 } get_info;
4233 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004234} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004235
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004236struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004237 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004238 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004239 uint8_t val;
4240 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004241 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004242 uint8_t val;
4243 char name[32];
4244 uint32_t flags;
4245 } get_info;
4246 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004247} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004248
4249enum gpio_get_subcmd {
4250 EC_GPIO_GET_BY_NAME = 0,
4251 EC_GPIO_GET_COUNT = 1,
4252 EC_GPIO_GET_INFO = 2,
4253};
4254
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004255/*****************************************************************************/
4256/* I2C commands. Only available when flash write protect is unlocked. */
4257
Duncan Laurie93e24442014-01-06 12:30:52 -08004258/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004259 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4260 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4261 *
4262 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004263 */
4264
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004265/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004266#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004267
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004268struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004269 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004270 uint8_t read_size; /* Either 8 or 16. */
4271 uint8_t port;
4272 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004273} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004274
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004275struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004276 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004277} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004278
4279/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004280#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004281
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004282struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004283 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004284 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004285 uint8_t write_size; /* Either 8 or 16. */
4286 uint8_t port;
4287 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004288} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004289
4290/*****************************************************************************/
4291/* Charge state commands. Only available when flash write protect unlocked. */
4292
Duncan Laurie93e24442014-01-06 12:30:52 -08004293/* Force charge state machine to stop charging the battery or force it to
4294 * discharge the battery.
4295 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004296#define EC_CMD_CHARGE_CONTROL 0x0096
Scott Chao18141d8c2021-07-30 10:40:57 +08004297#define EC_VER_CHARGE_CONTROL 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004298
Duncan Laurie93e24442014-01-06 12:30:52 -08004299enum ec_charge_control_mode {
4300 CHARGE_CONTROL_NORMAL = 0,
4301 CHARGE_CONTROL_IDLE,
4302 CHARGE_CONTROL_DISCHARGE,
Scott Chao18141d8c2021-07-30 10:40:57 +08004303 /* Add no more entry below. */
4304 CHARGE_CONTROL_COUNT,
4305};
4306
4307#define EC_CHARGE_MODE_TEXT { \
4308 [CHARGE_CONTROL_NORMAL] = "NORMAL", \
4309 [CHARGE_CONTROL_IDLE] = "IDLE", \
4310 [CHARGE_CONTROL_DISCHARGE] = "DISCHARGE", \
4311 }
4312
4313enum ec_charge_control_cmd {
4314 EC_CHARGE_CONTROL_CMD_SET = 0,
4315 EC_CHARGE_CONTROL_CMD_GET,
Duncan Laurie93e24442014-01-06 12:30:52 -08004316};
4317
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004318struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004319 uint32_t mode; /* enum charge_control_mode */
Scott Chao18141d8c2021-07-30 10:40:57 +08004320
4321 /* Below are the fields added in V2. */
4322 uint8_t cmd; /* enum ec_charge_control_cmd. */
4323 uint8_t reserved;
4324 /*
4325 * Lower and upper thresholds for battery sustainer. This struct isn't
4326 * named to avoid tainting foreign projects' name spaces.
4327 *
4328 * If charge mode is explicitly set (e.g. DISCHARGE), battery sustainer
4329 * will be disabled. To disable battery sustainer, set mode=NORMAL,
4330 * lower=-1, upper=-1.
4331 */
4332 struct {
4333 int8_t lower; /* Display SoC in percentage. */
4334 int8_t upper; /* Display SoC in percentage. */
4335 } sustain_soc;
4336} __ec_align4;
4337
4338/* Added in v2 */
4339struct ec_response_charge_control {
4340 uint32_t mode; /* enum charge_control_mode */
4341 struct { /* Battery sustainer thresholds */
4342 int8_t lower;
4343 int8_t upper;
4344 } sustain_soc;
4345 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004346} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004347
4348/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004349
4350/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004351#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004352
4353/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004354 * Read data from the saved snapshot. If the subcmd parameter is
4355 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4356 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4357 * end of the previous snapshot.
4358 *
4359 * The params are only looked at in version >= 1 of this command. Prior
4360 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004361 *
4362 * Response is null-terminated string. Empty string, if there is no more
4363 * remaining output.
4364 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004365#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004366
Duncan Laurieeb316852015-12-01 18:51:18 -08004367enum ec_console_read_subcmd {
4368 CONSOLE_READ_NEXT = 0,
4369 CONSOLE_READ_RECENT
4370};
4371
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004372struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004373 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004374} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004375
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004376/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004377
4378/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004379 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004380 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004381 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4382 * EC_RES_SUCCESS if the command was successful.
4383 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004384 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004385#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004386
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004387#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004388
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004389struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004390 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004391} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004392
Duncan Laurie433432b2013-06-03 10:38:22 -07004393/*****************************************************************************/
4394/* USB port mux control. */
4395
4396/*
4397 * Switch USB mux or return to automatic switching.
4398 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004399#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004400
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004401struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004402 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004403} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004404
4405/*****************************************************************************/
4406/* LDOs / FETs control. */
4407
4408enum ec_ldo_state {
4409 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4410 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4411};
4412
4413/*
4414 * Switch on/off a LDO.
4415 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004416#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004417
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004418struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004419 uint8_t index;
4420 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004421} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004422
4423/*
4424 * Get LDO state.
4425 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004426#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004427
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004428struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004429 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004430} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004431
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004432struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004433 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004434} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004435
4436/*****************************************************************************/
4437/* Power info. */
4438
4439/*
4440 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004441 *
4442 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004443 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004444#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004445
Jett Rinkba2edaf2020-01-14 11:49:06 -07004446/*
4447 * v1 of EC_CMD_POWER_INFO
4448 */
4449enum system_power_source {
4450 /*
4451 * Haven't established which power source is used yet,
4452 * or no presence signals are available
4453 */
4454 POWER_SOURCE_UNKNOWN = 0,
4455 /* System is running on battery alone */
4456 POWER_SOURCE_BATTERY = 1,
4457 /* System is running on A/C alone */
4458 POWER_SOURCE_AC = 2,
4459 /* System is running on A/C and battery */
4460 POWER_SOURCE_AC_BATTERY = 3,
4461};
4462
4463struct ec_response_power_info_v1 {
4464 /* enum system_power_source */
4465 uint8_t system_power_source;
4466 /* Battery state-of-charge, 0-100, 0 if not present */
4467 uint8_t battery_soc;
4468 /* AC Adapter 100% rating, Watts */
4469 uint8_t ac_adapter_100pct;
4470 /* AC Adapter 10ms rating, Watts */
4471 uint8_t ac_adapter_10ms;
4472 /* Battery 1C rating, derated */
4473 uint8_t battery_1cd;
4474 /* Rest of Platform average, Watts */
4475 uint8_t rop_avg;
4476 /* Rest of Platform peak, Watts */
4477 uint8_t rop_peak;
4478 /* Nominal charger efficiency, % */
4479 uint8_t nominal_charger_eff;
4480 /* Rest of Platform VR Average Efficiency, % */
4481 uint8_t rop_avg_eff;
4482 /* Rest of Platform VR Peak Efficiency, % */
4483 uint8_t rop_peak_eff;
4484 /* SoC VR Efficiency at Average level, % */
4485 uint8_t soc_avg_eff;
4486 /* SoC VR Efficiency at Peak level, % */
4487 uint8_t soc_peak_eff;
4488 /* Intel-specific items */
4489 struct {
4490 /* Battery's level of DBPT support: 0, 2 */
4491 uint8_t batt_dbpt_support_level;
4492 /*
4493 * Maximum peak power from battery (10ms), Watts
4494 * If DBPT is not supported, this is 0
4495 */
4496 uint8_t batt_dbpt_max_peak_power;
4497 /*
4498 * Sustained peak power from battery, Watts
4499 * If DBPT is not supported, this is 0
4500 */
4501 uint8_t batt_dbpt_sus_peak_power;
4502 } intel;
4503} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004504
4505/*****************************************************************************/
4506/* I2C passthru command */
4507
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004508#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004509
Duncan Laurie433432b2013-06-03 10:38:22 -07004510/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004511#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004512
4513/* Mask for address */
4514#define EC_I2C_ADDR_MASK 0x3ff
4515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004516#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4517#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004518
4519/* Any error */
4520#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4521
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004522struct ec_params_i2c_passthru_msg {
Rob Barnes8bc5fa92021-06-28 09:32:28 -06004523 uint16_t addr_flags; /* I2C peripheral address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004524 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004525} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004526
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004527struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004528 uint8_t port; /* I2C port number */
4529 uint8_t num_msgs; /* Number of messages */
4530 struct ec_params_i2c_passthru_msg msg[];
4531 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004532} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004533
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004534struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004535 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4536 uint8_t num_msgs; /* Number of messages processed */
4537 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004538} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004539
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004540/*****************************************************************************/
4541/* Power button hang detect */
4542
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004543#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004544
4545/* Reasons to start hang detection timer */
4546/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004547#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004548
4549/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004550#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004551
4552 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004553#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004554
4555/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004556#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004557
4558/* Reasons to cancel hang detection */
4559
4560/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004561#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004562
4563/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004564#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004565
4566/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004567#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004568
4569/*
4570 * If this flag is set, all the other fields are ignored, and the hang detect
4571 * timer is started. This provides the AP a way to start the hang timer
4572 * without reconfiguring any of the other hang detect settings. Note that
4573 * you must previously have configured the timeouts.
4574 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004575#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004576
4577/*
4578 * If this flag is set, all the other fields are ignored (including
4579 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4580 * without reconfiguring any of the other hang detect settings.
4581 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004582#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004583
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004584struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004585 /* Flags; see EC_HANG_* */
4586 uint32_t flags;
4587
4588 /* Timeout in msec before generating host event, if enabled */
4589 uint16_t host_event_timeout_msec;
4590
4591 /* Timeout in msec before generating warm reboot, if enabled */
4592 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004593} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004594
4595/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004596/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004597
4598/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004599 * This is the single catch-all host command to exchange data regarding the
4600 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004601 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004602#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004603
4604/* Subcommands for this host command */
4605enum charge_state_command {
4606 CHARGE_STATE_CMD_GET_STATE,
4607 CHARGE_STATE_CMD_GET_PARAM,
4608 CHARGE_STATE_CMD_SET_PARAM,
4609 CHARGE_STATE_NUM_CMDS
4610};
4611
4612/*
4613 * Known param numbers are defined here. Ranges are reserved for board-specific
4614 * params, which are handled by the particular implementations.
4615 */
4616enum charge_state_params {
4617 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4618 CS_PARAM_CHG_CURRENT, /* charger current limit */
4619 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4620 CS_PARAM_CHG_STATUS, /* charger-specific status */
4621 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004622 CS_PARAM_LIMIT_POWER, /*
4623 * Check if power is limited due to
4624 * low battery and / or a weak external
4625 * charger. READ ONLY.
4626 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004627 /* How many so far? */
4628 CS_NUM_BASE_PARAMS,
4629
4630 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4631 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4632 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4633
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004634 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4635 CS_PARAM_DEBUG_MIN = 0x20000,
4636 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4637 CS_PARAM_DEBUG_MANUAL_MODE,
4638 CS_PARAM_DEBUG_SEEMS_DEAD,
4639 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4640 CS_PARAM_DEBUG_BATT_REMOVED,
4641 CS_PARAM_DEBUG_MANUAL_CURRENT,
4642 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4643 CS_PARAM_DEBUG_MAX = 0x2ffff,
4644
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004645 /* Other custom param ranges go here... */
4646};
4647
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004648struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004649 uint8_t cmd; /* enum charge_state_command */
4650 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004651 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004652
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004653 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004654 uint32_t param; /* enum charge_state_param */
4655 } get_param;
4656
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004657 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004658 uint32_t param; /* param to set */
4659 uint32_t value; /* value to set */
4660 } set_param;
4661 };
Yidi Lin42f79592020-09-21 18:04:10 +08004662 uint8_t chgnum; /* Version 1 supports chgnum */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004663} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004664
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004665struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004666 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004667 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004668 int ac;
4669 int chg_voltage;
4670 int chg_current;
4671 int chg_input_current;
4672 int batt_state_of_charge;
4673 } get_state;
4674
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004675 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004676 uint32_t value;
4677 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004678
4679 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004680 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004681} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004682
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06004683
Duncan Laurie433432b2013-06-03 10:38:22 -07004684/*
4685 * Set maximum battery charging current.
4686 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004687#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004688
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004689struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004690 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004691} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004692
4693/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004694 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004695 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004696#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004697
Duncan Laurieeb316852015-12-01 18:51:18 -08004698/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004699struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004700 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4701 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004702} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004703
Duncan Laurieeb316852015-12-01 18:51:18 -08004704#define EC_POWER_LIMIT_NONE 0xffff
4705
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004706/*
4707 * Set maximum voltage & current of a dedicated charge port
4708 */
4709#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4710
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004711struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004712 uint16_t current_lim; /* in mA */
4713 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004714} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004715
Duncan Laurieeb316852015-12-01 18:51:18 -08004716/*****************************************************************************/
4717/* Hibernate/Deep Sleep Commands */
4718
4719/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004720#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004721
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004722struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004723 /*
4724 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4725 * current settings without changing them.
4726 */
4727 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004728} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004729
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004730struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004731 /*
4732 * The current time in seconds in which the system has been in the G3
4733 * state. This value is reset if the EC transitions out of G3.
4734 */
4735 uint32_t time_g3;
4736
4737 /*
4738 * The current time remaining in seconds until the EC should hibernate.
4739 * This value is also reset if the EC transitions out of G3.
4740 */
4741 uint32_t time_remaining;
4742
4743 /*
4744 * The current time in seconds that the EC should wait in G3 before
4745 * hibernating.
4746 */
4747 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004748} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004749
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004750/* Inform the EC when entering a sleep state */
4751#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4752
4753enum host_sleep_event {
4754 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4755 HOST_SLEEP_EVENT_S3_RESUME = 2,
4756 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004757 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4758 /* S3 suspend with additional enabled wake sources */
4759 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004760};
4761
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004762struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004763 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004764} __ec_align1;
4765
4766/*
4767 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4768 * transition failures
4769 */
4770#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4771
4772/* Disable timeout detection for this sleep transition */
4773#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4774
4775struct ec_params_host_sleep_event_v1 {
4776 /* The type of sleep being entered or exited. */
4777 uint8_t sleep_event;
4778
4779 /* Padding */
4780 uint8_t reserved;
4781 union {
4782 /* Parameters that apply for suspend messages. */
4783 struct {
4784 /*
4785 * The timeout in milliseconds between when this message
4786 * is received and when the EC will declare sleep
4787 * transition failure if the sleep signal is not
4788 * asserted.
4789 */
4790 uint16_t sleep_timeout_ms;
4791 } suspend_params;
4792
4793 /* No parameters for non-suspend messages. */
4794 };
4795} __ec_align2;
4796
4797/* A timeout occurred when this bit is set */
4798#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4799
4800/*
4801 * The mask defining which bits correspond to the number of sleep transitions,
4802 * as well as the maximum number of suspend line transitions that will be
4803 * reported back to the host.
4804 */
4805#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4806
4807struct ec_response_host_sleep_event_v1 {
4808 union {
4809 /* Response fields that apply for resume messages. */
4810 struct {
4811 /*
4812 * The number of sleep power signal transitions that
4813 * occurred since the suspend message. The high bit
4814 * indicates a timeout occurred.
4815 */
4816 uint32_t sleep_transitions;
4817 } resume_response;
4818
4819 /* No response fields for non-resume messages. */
4820 };
4821} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004822
4823/*****************************************************************************/
4824/* Device events */
4825#define EC_CMD_DEVICE_EVENT 0x00AA
4826
4827enum ec_device_event {
4828 EC_DEVICE_EVENT_TRACKPAD,
4829 EC_DEVICE_EVENT_DSP,
4830 EC_DEVICE_EVENT_WIFI,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08004831 EC_DEVICE_EVENT_WLC,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004832};
4833
4834enum ec_device_event_param {
4835 /* Get and clear pending device events */
4836 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4837 /* Get device event mask */
4838 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4839 /* Set device event mask */
4840 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4841};
4842
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004843#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004844
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004845struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004846 uint32_t event_mask;
4847 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004848} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004849
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004850struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004851 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004852} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004853
Duncan Laurie433432b2013-06-03 10:38:22 -07004854/*****************************************************************************/
4855/* Smart battery pass-through */
4856
4857/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004858#define EC_CMD_SB_READ_WORD 0x00B0
4859#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004860
4861/* Get / Set string smart battery parameters
4862 * formatted as SMBUS "block".
4863 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004864#define EC_CMD_SB_READ_BLOCK 0x00B2
4865#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004866
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004867struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004868 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004869} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004870
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004871struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004872 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004873} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004874
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004875struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004876 uint8_t reg;
4877 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004878} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004879
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004880struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004881 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004882} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004883
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004884struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004885 uint8_t reg;
4886 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004887} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004888
4889/*****************************************************************************/
4890/* Battery vendor parameters
4891 *
4892 * Get or set vendor-specific parameters in the battery. Implementations may
4893 * differ between boards or batteries. On a set operation, the response
4894 * contains the actual value set, which may be rounded or clipped from the
4895 * requested value.
4896 */
4897
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004898#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004899
4900enum ec_battery_vendor_param_mode {
4901 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4902 BATTERY_VENDOR_PARAM_MODE_SET,
4903};
4904
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004905struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004906 uint32_t param;
4907 uint32_t value;
4908 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004909} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004910
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004911struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004912 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004913} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004914
4915/*****************************************************************************/
4916/*
4917 * Smart Battery Firmware Update Commands
4918 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004919#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004920
4921enum ec_sb_fw_update_subcmd {
4922 EC_SB_FW_UPDATE_PREPARE = 0x0,
4923 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4924 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4925 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4926 EC_SB_FW_UPDATE_END = 0x4,
4927 EC_SB_FW_UPDATE_STATUS = 0x5,
4928 EC_SB_FW_UPDATE_PROTECT = 0x6,
4929 EC_SB_FW_UPDATE_MAX = 0x7,
4930};
4931
4932#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4933#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4934#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4935
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004936struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004937 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4938 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004939} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004940
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004941struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004942 struct ec_sb_fw_update_header hdr;
4943 union {
4944 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4945 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4946 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4947 /* EC_SB_FW_UPDATE_END = 0x4 */
4948 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4949 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004950 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004951
4952 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004953 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004954 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4955 } write;
4956 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004957} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004958
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004959struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004960 union {
4961 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004962 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004963 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4964 } info;
4965
4966 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004967 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004968 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4969 } status;
4970 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004971} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004972
4973/*
4974 * Entering Verified Boot Mode Command
4975 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4976 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004977 *
4978 * EC no longer needs to know what mode vboot has entered,
4979 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004980 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004981#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004982
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004983struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004984 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004985} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004986
4987#define VBOOT_MODE_NORMAL 0
4988#define VBOOT_MODE_DEVELOPER 1
4989#define VBOOT_MODE_RECOVERY 2
4990
Duncan Laurie433432b2013-06-03 10:38:22 -07004991/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004992/*
4993 * I2C passthru protection command: Protects I2C tunnels against access on
4994 * certain addresses (board-specific).
4995 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004996#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004997
4998enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004999 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
5000 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
5001 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07005002};
5003
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005004struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005005 uint8_t subcmd;
5006 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005007} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005008
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005009struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07005010 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005011} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005012
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005013
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005014/*****************************************************************************/
5015/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005016 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005017 *
5018 * These commands are for sending and receiving message via HDMI CEC
5019 */
5020
5021#define MAX_CEC_MSG_LEN 16
5022
5023/* CEC message from the AP to be written on the CEC bus */
5024#define EC_CMD_CEC_WRITE_MSG 0x00B8
5025
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005026/**
5027 * struct ec_params_cec_write - Message to write to the CEC bus
5028 * @msg: message content to write to the CEC bus
5029 */
5030struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005031 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005032} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005033
5034/* Set various CEC parameters */
5035#define EC_CMD_CEC_SET 0x00BA
5036
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005037/**
5038 * struct ec_params_cec_set - CEC parameters set
5039 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5040 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
5041 * or 1 to enable CEC functionality, in case cmd is
5042 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
5043 * address between 0 and 15 or 0xff to unregister
5044 */
5045struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005046 uint8_t cmd; /* enum cec_command */
5047 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005048} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005049
5050/* Read various CEC parameters */
5051#define EC_CMD_CEC_GET 0x00BB
5052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005053/**
5054 * struct ec_params_cec_get - CEC parameters get
5055 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
5056 */
5057struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005058 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005059} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005060
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005061/**
5062 * struct ec_response_cec_get - CEC parameters get response
5063 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
5064 * disabled or 1 if CEC functionality is enabled,
5065 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
5066 * configured logical address between 0 and 15 or 0xff if unregistered
5067 */
5068struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005069 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005070} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005071
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005072/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005073enum cec_command {
5074 /* CEC reading, writing and events enable */
5075 CEC_CMD_ENABLE,
5076 /* CEC logical address */
5077 CEC_CMD_LOGICAL_ADDRESS,
5078};
5079
5080/* Events from CEC to AP */
5081enum mkbp_cec_event {
5082 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005083 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005084 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005085 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005086};
5087
Gwendal Grignou880b4582016-06-20 08:49:25 -07005088/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005089
Jett Rinkba2edaf2020-01-14 11:49:06 -07005090/* Commands for audio codec. */
5091#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005092
Jett Rinkba2edaf2020-01-14 11:49:06 -07005093enum ec_codec_subcmd {
5094 EC_CODEC_GET_CAPABILITIES = 0x0,
5095 EC_CODEC_GET_SHM_ADDR = 0x1,
5096 EC_CODEC_SET_SHM_ADDR = 0x2,
5097 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005098};
5099
Jett Rinkba2edaf2020-01-14 11:49:06 -07005100enum ec_codec_cap {
5101 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
5102 EC_CODEC_CAP_WOV_LANG_SHM = 1,
5103 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005104};
5105
Jett Rinkba2edaf2020-01-14 11:49:06 -07005106enum ec_codec_shm_id {
5107 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
5108 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
5109 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005110};
5111
Jett Rinkba2edaf2020-01-14 11:49:06 -07005112enum ec_codec_shm_type {
5113 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
5114 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005115};
5116
Jett Rinkba2edaf2020-01-14 11:49:06 -07005117struct __ec_align1 ec_param_ec_codec_get_shm_addr {
5118 uint8_t shm_id;
5119 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005120};
5121
Jett Rinkba2edaf2020-01-14 11:49:06 -07005122struct __ec_align4 ec_param_ec_codec_set_shm_addr {
5123 uint64_t phys_addr;
5124 uint32_t len;
5125 uint8_t shm_id;
5126 uint8_t reserved[3];
5127};
5128
5129struct __ec_align4 ec_param_ec_codec {
5130 uint8_t cmd; /* enum ec_codec_subcmd */
5131 uint8_t reserved[3];
5132
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005133 union {
Jett Rinkba2edaf2020-01-14 11:49:06 -07005134 struct ec_param_ec_codec_get_shm_addr
5135 get_shm_addr_param;
5136 struct ec_param_ec_codec_set_shm_addr
5137 set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005138 };
5139};
5140
Jett Rinkba2edaf2020-01-14 11:49:06 -07005141struct __ec_align4 ec_response_ec_codec_get_capabilities {
5142 uint32_t capabilities;
5143};
5144
5145struct __ec_align4 ec_response_ec_codec_get_shm_addr {
5146 uint64_t phys_addr;
5147 uint32_t len;
5148 uint8_t type;
5149 uint8_t reserved[3];
5150};
5151
5152/*****************************************************************************/
5153
5154/* Commands for DMIC on audio codec. */
5155#define EC_CMD_EC_CODEC_DMIC 0x00BD
5156
5157enum ec_codec_dmic_subcmd {
5158 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
5159 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
5160 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
5161 EC_CODEC_DMIC_SUBCMD_COUNT,
5162};
5163
5164enum ec_codec_dmic_channel {
5165 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
5166 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
5167 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
5168 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
5169 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
5170 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
5171 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
5172 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
5173 EC_CODEC_DMIC_CHANNEL_COUNT,
5174};
5175
5176struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
5177 uint8_t channel; /* enum ec_codec_dmic_channel */
5178 uint8_t gain;
5179 uint8_t reserved[2];
5180};
5181
5182struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
5183 uint8_t channel; /* enum ec_codec_dmic_channel */
5184 uint8_t reserved[3];
5185};
5186
5187struct __ec_align4 ec_param_ec_codec_dmic {
5188 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
5189 uint8_t reserved[3];
5190
5191 union {
5192 struct ec_param_ec_codec_dmic_set_gain_idx
5193 set_gain_idx_param;
5194 struct ec_param_ec_codec_dmic_get_gain_idx
5195 get_gain_idx_param;
5196 };
5197};
5198
5199struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5200 uint8_t max_gain;
5201};
5202
5203struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5204 uint8_t gain;
5205};
5206
5207/*****************************************************************************/
5208
5209/* Commands for I2S RX on audio codec. */
5210
5211#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5212
5213enum ec_codec_i2s_rx_subcmd {
5214 EC_CODEC_I2S_RX_ENABLE = 0x0,
5215 EC_CODEC_I2S_RX_DISABLE = 0x1,
5216 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5217 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5218 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
Yidi Lin42f79592020-09-21 18:04:10 +08005219 EC_CODEC_I2S_RX_RESET = 0x5,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005220 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5221};
5222
5223enum ec_codec_i2s_rx_sample_depth {
5224 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5225 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5226 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5227};
5228
5229enum ec_codec_i2s_rx_daifmt {
5230 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5231 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5232 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5233 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5234};
5235
5236struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5237 uint8_t depth;
5238 uint8_t reserved[3];
5239};
5240
5241struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5242 uint8_t left;
5243 uint8_t right;
5244 uint8_t reserved[2];
5245};
5246
5247struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5248 uint8_t daifmt;
5249 uint8_t reserved[3];
5250};
5251
5252struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5253 uint32_t bclk;
5254};
5255
5256struct __ec_align4 ec_param_ec_codec_i2s_rx {
5257 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5258 uint8_t reserved[3];
5259
5260 union {
5261 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5262 set_sample_depth_param;
5263 struct ec_param_ec_codec_i2s_rx_set_daifmt
5264 set_daifmt_param;
5265 struct ec_param_ec_codec_i2s_rx_set_bclk
5266 set_bclk_param;
5267 };
5268};
5269
5270/*****************************************************************************/
5271/* Commands for WoV on audio codec. */
5272
5273#define EC_CMD_EC_CODEC_WOV 0x00BF
5274
5275enum ec_codec_wov_subcmd {
5276 EC_CODEC_WOV_SET_LANG = 0x0,
5277 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5278 EC_CODEC_WOV_GET_LANG = 0x2,
5279 EC_CODEC_WOV_ENABLE = 0x3,
5280 EC_CODEC_WOV_DISABLE = 0x4,
5281 EC_CODEC_WOV_READ_AUDIO = 0x5,
5282 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5283 EC_CODEC_WOV_SUBCMD_COUNT,
5284};
5285
5286/*
5287 * @hash is SHA256 of the whole language model.
5288 * @total_len indicates the length of whole language model.
5289 * @offset is the cursor from the beginning of the model.
5290 * @buf is the packet buffer.
5291 * @len denotes how many bytes in the buf.
5292 */
5293struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5294 uint8_t hash[32];
5295 uint32_t total_len;
5296 uint32_t offset;
5297 uint8_t buf[128];
5298 uint32_t len;
5299};
5300
5301struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5302 uint8_t hash[32];
5303 uint32_t total_len;
5304};
5305
5306struct __ec_align4 ec_param_ec_codec_wov {
5307 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5308 uint8_t reserved[3];
5309
5310 union {
5311 struct ec_param_ec_codec_wov_set_lang
5312 set_lang_param;
5313 struct ec_param_ec_codec_wov_set_lang_shm
5314 set_lang_shm_param;
5315 };
5316};
5317
5318struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5319 uint8_t hash[32];
5320};
5321
5322struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5323 uint8_t buf[128];
5324 uint32_t len;
5325};
5326
5327struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5328 uint32_t offset;
5329 uint32_t len;
5330};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005331
5332/*****************************************************************************/
Yidi Lin42f79592020-09-21 18:04:10 +08005333/* Commands for PoE PSE controller */
5334
5335#define EC_CMD_PSE 0x00C0
5336
5337enum ec_pse_subcmd {
5338 EC_PSE_STATUS = 0x0,
5339 EC_PSE_ENABLE = 0x1,
5340 EC_PSE_DISABLE = 0x2,
5341 EC_PSE_SUBCMD_COUNT,
5342};
5343
5344struct __ec_align1 ec_params_pse {
5345 uint8_t cmd; /* enum ec_pse_subcmd */
5346 uint8_t port; /* PSE port */
5347};
5348
5349enum ec_pse_status {
5350 EC_PSE_STATUS_DISABLED = 0x0,
5351 EC_PSE_STATUS_ENABLED = 0x1,
5352 EC_PSE_STATUS_POWERED = 0x2,
5353};
5354
5355struct __ec_align1 ec_response_pse_status {
5356 uint8_t status; /* enum ec_pse_status */
5357};
5358
5359/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005360/* System commands */
5361
5362/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005363 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5364 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005365 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005366#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005367
5368/* Command */
5369enum ec_reboot_cmd {
5370 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005371 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005372 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005373 /* (command 3 was jump to RW-B) */
5374 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005375 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08005376 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
Yidi Lin42f79592020-09-21 18:04:10 +08005377 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_IDLE flag */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005378 EC_REBOOT_COLD_AP_OFF = 8, /* Cold-reboot and don't boot AP */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005379};
5380
5381/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005382#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5383#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5384#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005385
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005386struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005387 uint8_t cmd; /* enum ec_reboot_cmd */
5388 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005389} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005390
Duncan Laurie433432b2013-06-03 10:38:22 -07005391/*
5392 * Get information on last EC panic.
5393 *
5394 * Returns variable-length platform-dependent panic information. See panic.h
5395 * for details.
5396 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005397#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005398
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005399/*****************************************************************************/
5400/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005401 * Special commands
5402 *
5403 * These do not follow the normal rules for commands. See each command for
5404 * details.
5405 */
5406
5407/*
5408 * Reboot NOW
5409 *
5410 * This command will work even when the EC LPC interface is busy, because the
5411 * reboot command is processed at interrupt level. Note that when the EC
5412 * reboots, the host will reboot too, so there is no response to this command.
5413 *
5414 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5415 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005416#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005417
5418/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005419 * Resend last response (not supported on LPC).
5420 *
5421 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5422 * there was no previous command, or the previous command's response was too
5423 * big to save.
5424 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005425#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005426
5427/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005428 * This header byte on a command indicate version 0. Any header byte less
5429 * than this means that we are talking to an old EC which doesn't support
5430 * versioning. In that case, we assume version 0.
5431 *
5432 * Header bytes greater than this indicate a later version. For example,
5433 * EC_CMD_VERSION0 + 1 means we are using version 1.
5434 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005435 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005436 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005437#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005438
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005439/*****************************************************************************/
5440/*
5441 * PD commands
5442 *
5443 * These commands are for PD MCU communication.
5444 */
5445
5446/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005447#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005448#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005449
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005450enum pd_charge_state {
5451 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
5452 PD_CHARGE_NONE, /* No charging allowed */
5453 PD_CHARGE_5V, /* 5V charging only */
5454 PD_CHARGE_MAX /* Charge at max voltage */
5455};
5456
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005457/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005458#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005459
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005460struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005461 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005462 int8_t batt_soc; /* battery state of charge */
5463 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005464} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005465
5466/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005467#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5468#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
5469#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
5470#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5471#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5472#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5473#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08005474#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
5475 PD_STATUS_TCPC_ALERT_1 | \
5476 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005477struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005478 uint32_t curr_lim_ma; /* input current limit */
5479 uint16_t status; /* PD MCU status */
5480 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005481} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005482
5483/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005484#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005485
5486/* PD MCU host event status bits */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005487#define PD_EVENT_UPDATE_DEVICE BIT(0)
5488#define PD_EVENT_POWER_CHANGE BIT(1)
5489#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5490#define PD_EVENT_DATA_SWAP BIT(3)
5491#define PD_EVENT_TYPEC BIT(4)
5492
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005493struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005494 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005495} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005496
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06005497/*
5498 * Set USB type-C port role and muxes
5499 *
5500 * Deprecated in favor of TYPEC_STATUS and TYPEC_CONTROL commands.
5501 *
5502 * TODO(b/169771803): TCPMv2: Remove EC_CMD_USB_PD_CONTROL
5503 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005504#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005505
5506enum usb_pd_control_role {
5507 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5508 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5509 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5510 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5511 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005512 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005513 USB_PD_CTRL_ROLE_COUNT
5514};
5515
5516enum usb_pd_control_mux {
5517 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5518 USB_PD_CTRL_MUX_NONE = 1,
5519 USB_PD_CTRL_MUX_USB = 2,
5520 USB_PD_CTRL_MUX_DP = 3,
5521 USB_PD_CTRL_MUX_DOCK = 4,
5522 USB_PD_CTRL_MUX_AUTO = 5,
5523 USB_PD_CTRL_MUX_COUNT
5524};
5525
Duncan Laurieeb316852015-12-01 18:51:18 -08005526enum usb_pd_control_swap {
5527 USB_PD_CTRL_SWAP_NONE = 0,
5528 USB_PD_CTRL_SWAP_DATA = 1,
5529 USB_PD_CTRL_SWAP_POWER = 2,
5530 USB_PD_CTRL_SWAP_VCONN = 3,
5531 USB_PD_CTRL_SWAP_COUNT
5532};
5533
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005534struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005535 uint8_t port;
5536 uint8_t role;
5537 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005538 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005539} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005541#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5542#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
5543#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005544
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005545#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5546#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5547#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5548#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5549#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5550#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005551#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */
Duncan Laurieeb316852015-12-01 18:51:18 -08005552
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005553struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005554 uint8_t enabled;
5555 uint8_t role;
5556 uint8_t polarity;
5557 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005558} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005559
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005560struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005561 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005562 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005563 uint8_t polarity;
5564 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005565} __ec_align1;
5566
Jett Rinkba2edaf2020-01-14 11:49:06 -07005567/* Possible port partner connections based on CC line states */
5568enum pd_cc_states {
5569 PD_CC_NONE = 0, /* No port partner attached */
5570
5571 /* From DFP perspective */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005572 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005573 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5574 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5575 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
5576
5577 /* From UFP perspective */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005578 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005579 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005580};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005581
Jett Rinkba2edaf2020-01-14 11:49:06 -07005582/* Active/Passive Cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005583#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005584/* Optical/Non-optical cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005585#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005586/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005587#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
5588/* Active Link Uni-Direction */
5589#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005590
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005591struct ec_response_usb_pd_control_v2 {
5592 uint8_t enabled;
5593 uint8_t role;
5594 uint8_t polarity;
5595 char state[32];
Jett Rinkba2edaf2020-01-14 11:49:06 -07005596 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5597 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005598 uint8_t reserved; /* Reserved for future use */
5599 uint8_t control_flags; /* USB_PD_CTRL_*flags */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08005600 uint8_t cable_speed; /* TBT_SS_* cable speed */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005601 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005602} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005603
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005604#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005605
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005606/* Maximum number of PD ports on a device, num_ports will be <= this */
5607#define EC_USB_PD_MAX_PORTS 8
5608
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005609struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005610 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005611} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005612
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005613#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005614
5615#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005616struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005617 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005618} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005619
5620enum usb_chg_type {
5621 USB_CHG_TYPE_NONE,
5622 USB_CHG_TYPE_PD,
5623 USB_CHG_TYPE_C,
5624 USB_CHG_TYPE_PROPRIETARY,
5625 USB_CHG_TYPE_BC12_DCP,
5626 USB_CHG_TYPE_BC12_CDP,
5627 USB_CHG_TYPE_BC12_SDP,
5628 USB_CHG_TYPE_OTHER,
5629 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005630 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005631 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005632};
5633enum usb_power_roles {
5634 USB_PD_PORT_POWER_DISCONNECTED,
5635 USB_PD_PORT_POWER_SOURCE,
5636 USB_PD_PORT_POWER_SINK,
5637 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5638};
5639
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005640struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005641 uint16_t voltage_max;
5642 uint16_t voltage_now;
5643 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005644 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005645} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005646
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005647struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005648 uint8_t role;
5649 uint8_t type;
5650 uint8_t dualrole;
5651 uint8_t reserved1;
5652 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005653 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005654} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005655
Yidi Lin42f79592020-09-21 18:04:10 +08005656
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005657/*
5658 * This command will return the number of USB PD charge port + the number
5659 * of dedicated port present.
5660 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5661 */
5662#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005663struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005664 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005665} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005666
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005667/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005668#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005669
5670enum usb_pd_fw_update_cmds {
5671 USB_PD_FW_REBOOT,
5672 USB_PD_FW_FLASH_ERASE,
5673 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005674 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005675};
5676
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005677struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005678 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005679 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005680 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005681 uint32_t size; /* Size to write in bytes */
5682 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005683} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005684
5685/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005686#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005687/* RW hash is first 20 bytes of SHA-256 of RW section */
5688#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005689struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005690 uint16_t dev_id;
5691 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005692 uint8_t reserved; /*
5693 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005694 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005695 * Should have been reserved[2].
5696 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005697 uint32_t current_image; /* One of ec_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005698} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005699
5700/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005701#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005702
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005703struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005704 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005705} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005706
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005707/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005708#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005709struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005710 uint16_t vid; /* USB-IF VID */
5711 uint16_t pid; /* USB-IF PID */
5712 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005713} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005714
5715/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005716#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005717
5718/* Negative port parameters have special meaning */
5719enum usb_pd_override_ports {
5720 OVERRIDE_DONT_CHARGE = -2,
5721 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005722 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005723};
5724
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005725struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005726 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005727} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005728
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005729/*
5730 * Read (and delete) one entry of PD event log.
5731 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5732 * future non-PD logs that use the same internal EC event_log.
5733 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005734#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005735
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005736struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005737 uint32_t timestamp; /* relative timestamp in milliseconds */
5738 uint8_t type; /* event type : see PD_EVENT_xx below */
5739 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5740 uint16_t data; /* type-defined data payload */
5741 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005742} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005743
5744/* The timestamp is the microsecond counter shifted to get about a ms. */
5745#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5746
Duncan Laurieeb316852015-12-01 18:51:18 -08005747#define PD_LOG_SIZE_MASK 0x1f
5748#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005749#define PD_LOG_PORT_SHIFT 5
5750#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5751 ((size) & PD_LOG_SIZE_MASK))
5752#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5753#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5754
5755/* PD event log : entry types */
5756/* PD MCU events */
5757#define PD_EVENT_MCU_BASE 0x00
5758#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5759#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5760/* Reserved for custom board event */
5761#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5762/* PD generic accessory events */
5763#define PD_EVENT_ACC_BASE 0x20
5764#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5765#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5766/* PD power supply events */
5767#define PD_EVENT_PS_BASE 0x40
5768#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5769/* PD video dongles events */
5770#define PD_EVENT_VIDEO_BASE 0x60
5771#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5772#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5773/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005774#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005775
5776/*
5777 * PD_EVENT_MCU_CHARGE event definition :
5778 * the payload is "struct usb_chg_measures"
5779 * the data field contains the port state flags as defined below :
5780 */
5781/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005782#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005783/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005784#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005785/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005786#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005787/* Charger type */
5788#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005789#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005790/* Power delivery role */
5791#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5792
5793/*
5794 * PD_EVENT_PS_FAULT data field flags definition :
5795 */
5796#define PS_FAULT_OCP 1
5797#define PS_FAULT_FAST_OCP 2
5798#define PS_FAULT_OVP 3
5799#define PS_FAULT_DISCH 4
5800
5801/*
5802 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5803 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005804struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005805 uint8_t major;
5806 uint8_t minor;
5807 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005808} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005809
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005810struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005811 uint8_t family[2];
5812 uint8_t chipid[2];
5813 struct mcdp_version irom;
5814 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005815} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005816
5817/* struct mcdp_info field decoding */
5818#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5819#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5820
5821/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005822#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005823struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005824 uint16_t svid_idx; /* SVID index to get */
5825 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005826} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005828struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005829 uint16_t svid; /* SVID */
5830 uint16_t opos; /* Object Position */
5831 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005832} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005833
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005834#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005835
5836enum pd_mode_cmd {
5837 PD_EXIT_MODE = 0,
5838 PD_ENTER_MODE = 1,
5839 /* Not a command. Do NOT remove. */
5840 PD_MODE_CMD_COUNT,
5841};
5842
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005843struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005844 uint32_t cmd; /* enum pd_mode_cmd */
5845 uint16_t svid; /* SVID to set */
5846 uint8_t opos; /* Object Position */
5847 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005848} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005849
5850/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005851#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005852
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005853struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005854 uint8_t type; /* event type : see PD_EVENT_xx above */
5855 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005856} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005857
Yidi Lin42f79592020-09-21 18:04:10 +08005858
Gwendal Grignou880b4582016-06-20 08:49:25 -07005859/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005860#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005861
5862enum ec_pd_control_cmd {
5863 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5864 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5865 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005866 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5867 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005868};
5869
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005870struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005871 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005872 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005873} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005874
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005875/* Get info about USB-C SS muxes */
5876#define EC_CMD_USB_PD_MUX_INFO 0x011A
5877
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005878struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005879 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005880} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005881
5882/* Flags representing mux state */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005883#define USB_PD_MUX_NONE 0 /* Open switch */
5884#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5885#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5886#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5887#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
Rob Barnes5ab14662021-09-17 10:24:45 -06005888#define USB_PD_MUX_HPD_IRQ_DEASSERTED 0 /* HPD IRQ is deasserted */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005889#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
Rob Barnes5ab14662021-09-17 10:24:45 -06005890#define USB_PD_MUX_HPD_LVL_DEASSERTED 0 /* HPD level is deasserted */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005891#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
5892#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005893#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
5894
5895/* USB-C Dock connected */
5896#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005897
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005898struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005899 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005900} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005901
5902#define EC_CMD_PD_CHIP_INFO 0x011B
5903
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005904struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005905 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005906 /*
5907 * Fetch the live chip info or hard-coded + cached chip info
5908 * 0: hardcoded value for VID/PID, cached value for FW version
5909 * 1: live chip value for VID/PID/FW Version
5910 */
5911 uint8_t live;
5912} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005913
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005914struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005915 uint16_t vendor_id;
5916 uint16_t product_id;
5917 uint16_t device_id;
5918 union {
5919 uint8_t fw_version_string[8];
5920 uint64_t fw_version_number;
5921 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005922} __ec_align2;
5923
5924struct ec_response_pd_chip_info_v1 {
5925 uint16_t vendor_id;
5926 uint16_t product_id;
5927 uint16_t device_id;
5928 union {
5929 uint8_t fw_version_string[8];
5930 uint64_t fw_version_number;
5931 };
5932 union {
5933 uint8_t min_req_fw_version_string[8];
5934 uint64_t min_req_fw_version_number;
5935 };
5936} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005937
5938/* Run RW signature verification and get status */
5939#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5940
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005941struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005942 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005943} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005944
5945/* For controlling RWSIG task */
5946#define EC_CMD_RWSIG_ACTION 0x011D
5947
5948enum rwsig_action {
5949 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5950 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5951};
5952
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005953struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005954 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005955} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005956
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005957/* Run verification on a slot */
5958#define EC_CMD_EFS_VERIFY 0x011E
5959
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005960struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005961 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005962} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005963
5964/*
5965 * Retrieve info from Cros Board Info store. Response is based on the data
5966 * type. Integers return a uint32. Strings return a string, using the response
5967 * size to determine how big it is.
5968 */
5969#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5970/*
5971 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5972 * hardware write-protect enabled.
5973 */
5974#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5975
Daisuke Nojirif984a052018-02-15 12:38:15 -08005976enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005977 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5978 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5979 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005980 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005981 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005982 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005983 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005984 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Yidi Lin42f79592020-09-21 18:04:10 +08005985 /* Second Source Factory Cache */
5986 CBI_TAG_SSFC = 8, /* uint32_t bit field */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06005987 CBI_TAG_REWORK_ID = 9, /* uint64_t or smaller */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005988 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005989};
5990
5991/*
5992 * Flags to control read operation
5993 *
5994 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5995 * write was successful without reboot.
5996 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005997#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005998
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005999struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006000 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006001 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006002} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006003
6004/*
6005 * Flags to control write behavior.
6006 *
6007 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
6008 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006009 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006010 * will be initialized to zero first.
6011 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006012#define CBI_SET_NO_SYNC BIT(0)
6013#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006014
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006015struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08006016 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006017 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08006018 uint32_t size; /* Data size */
6019 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006020} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08006021
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006022/*
6023 * Information about resets of the AP by the EC and the EC's own uptime.
6024 */
6025#define EC_CMD_GET_UPTIME_INFO 0x0121
6026
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006027/* EC reset causes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006028#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
6029#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
6030#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
6031#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
6032#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
6033#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
6034#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
6035#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
6036#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
6037#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
6038#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
6039#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
6040#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
6041#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
6042 * previous boot
6043 */
6044#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
6045#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
6046#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
6047#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
6048#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006049#define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This
6050 * enables PD in RO for Chromebox.
6051 */
Yidi Lin42f79592020-09-21 18:04:10 +08006052#define EC_RESET_FLAG_EFS BIT(20) /* Jumped to this image by EFS */
6053#define EC_RESET_FLAG_AP_IDLE BIT(21) /* Leave alone AP */
6054#define EC_RESET_FLAG_INITIAL_PWR BIT(22) /* EC had power, then was reset */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006055
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006056/*
6057 * Reason codes used by the AP after a shutdown to figure out why it was reset
6058 * by the EC. These are sent in EC commands. Therefore, to maintain protocol
6059 * compatibility:
6060 * - New entries must be inserted prior to the _COUNT field
6061 * - If an existing entry is no longer in service, it must be replaced with a
6062 * RESERVED entry instead.
6063 * - The semantic meaning of an entry should not change.
6064 * - Do not exceed 2^15 - 1 for reset reasons or 2^16 - 1 for shutdown reasons.
6065 */
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006066enum chipset_shutdown_reason {
6067 /*
6068 * Beginning of reset reasons.
6069 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006070 CHIPSET_RESET_BEGIN = 0,
6071 CHIPSET_RESET_UNKNOWN = CHIPSET_RESET_BEGIN,
6072 /* Custom reason defined by a board.c or baseboard.c file */
6073 CHIPSET_RESET_BOARD_CUSTOM,
6074 /* Believe that the AP has hung */
6075 CHIPSET_RESET_HANG_REBOOT,
6076 /* Reset by EC console command */
6077 CHIPSET_RESET_CONSOLE_CMD,
6078 /* Reset by EC host command */
6079 CHIPSET_RESET_HOST_CMD,
6080 /* Keyboard module reset key combination */
6081 CHIPSET_RESET_KB_SYSRESET,
6082 /* Keyboard module warm reboot */
6083 CHIPSET_RESET_KB_WARM_REBOOT,
6084 /* Debug module warm reboot */
6085 CHIPSET_RESET_DBG_WARM_REBOOT,
6086 /* I cannot self-terminate. You must lower me into the steel. */
6087 CHIPSET_RESET_AP_REQ,
6088 /* Reset as side-effect of startup sequence */
6089 CHIPSET_RESET_INIT,
6090 /* EC detected an AP watchdog event. */
6091 CHIPSET_RESET_AP_WATCHDOG,
6092
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006093 CHIPSET_RESET_COUNT, /* End of reset reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006094
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006095 /*
6096 * Beginning of shutdown reasons.
6097 */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006098 CHIPSET_SHUTDOWN_BEGIN = BIT(15),
6099 CHIPSET_SHUTDOWN_POWERFAIL = CHIPSET_SHUTDOWN_BEGIN,
6100 /* Forcing a shutdown as part of EC initialization */
6101 CHIPSET_SHUTDOWN_INIT,
6102 /* Custom reason on a per-board basis. */
6103 CHIPSET_SHUTDOWN_BOARD_CUSTOM,
6104 /* This is a reason to inhibit startup, not cause shut down. */
6105 CHIPSET_SHUTDOWN_BATTERY_INHIBIT,
6106 /* A power_wait_signal is being asserted */
6107 CHIPSET_SHUTDOWN_WAIT,
6108 /* Critical battery level. */
6109 CHIPSET_SHUTDOWN_BATTERY_CRIT,
6110 /* Because you told me to. */
6111 CHIPSET_SHUTDOWN_CONSOLE_CMD,
6112 /* Forcing a shutdown to effect entry to G3. */
6113 CHIPSET_SHUTDOWN_G3,
6114 /* Force shutdown due to over-temperature. */
6115 CHIPSET_SHUTDOWN_THERMAL,
6116 /* Force a chipset shutdown from the power button through EC */
6117 CHIPSET_SHUTDOWN_BUTTON,
6118
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006119 CHIPSET_SHUTDOWN_COUNT, /* End of shutdown reasons. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006120};
6121
6122
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006123struct ec_response_uptime_info {
6124 /*
6125 * Number of milliseconds since the last EC boot. Sysjump resets
6126 * typically do not restart the EC's time_since_boot epoch.
6127 *
6128 * WARNING: The EC's sense of time is much less accurate than the AP's
6129 * sense of time, in both phase and frequency. This timebase is similar
6130 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
6131 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006132 uint32_t time_since_ec_boot_ms;
6133
6134 /*
6135 * Number of times the AP was reset by the EC since the last EC boot.
6136 * Note that the AP may be held in reset by the EC during the initial
6137 * boot sequence, such that the very first AP boot may count as more
6138 * than one here.
6139 */
6140 uint32_t ap_resets_since_ec_boot;
6141
6142 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006143 * The set of flags which describe the EC's most recent reset.
6144 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006145 */
6146 uint32_t ec_reset_flags;
6147
6148 /* Empty log entries have both the cause and timestamp set to zero. */
6149 struct ap_reset_log_entry {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006150 /* See enum chipset_{reset,shutdown}_reason for details. */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006151 uint16_t reset_cause;
6152
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006153 /* Reserved for protocol growth. */
6154 uint16_t reserved;
6155
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006156 /*
6157 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006158 * last EC boot, in the same epoch as time_since_ec_boot_ms.
6159 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006160 */
6161 uint32_t reset_time_ms;
6162 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006163} __ec_align4;
6164
6165/*
6166 * Add entropy to the device secret (stored in the rollback region).
6167 *
6168 * Depending on the chip, the operation may take a long time (e.g. to erase
6169 * flash), so the commands are asynchronous.
6170 */
6171#define EC_CMD_ADD_ENTROPY 0x0122
6172
6173enum add_entropy_action {
6174 /* Add entropy to the current secret. */
6175 ADD_ENTROPY_ASYNC = 0,
6176 /*
6177 * Add entropy, and also make sure that the previous secret is erased.
6178 * (this can be implemented by adding entropy multiple times until
6179 * all rolback blocks have been overwritten).
6180 */
6181 ADD_ENTROPY_RESET_ASYNC = 1,
6182 /* Read back result from the previous operation. */
6183 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006184};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006185
6186struct ec_params_rollback_add_entropy {
6187 uint8_t action;
6188} __ec_align1;
6189
6190/*
6191 * Perform a single read of a given ADC channel.
6192 */
6193#define EC_CMD_ADC_READ 0x0123
6194
6195struct ec_params_adc_read {
6196 uint8_t adc_channel;
6197} __ec_align1;
6198
6199struct ec_response_adc_read {
6200 int32_t adc_value;
6201} __ec_align4;
6202
6203/*
6204 * Read back rollback info
6205 */
6206#define EC_CMD_ROLLBACK_INFO 0x0124
6207
6208struct ec_response_rollback_info {
6209 int32_t id; /* Incrementing number to indicate which region to use. */
6210 int32_t rollback_min_version;
6211 int32_t rw_rollback_version;
6212} __ec_align4;
6213
Yidi Lin42f79592020-09-21 18:04:10 +08006214
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006215/* Issue AP reset */
6216#define EC_CMD_AP_RESET 0x0125
6217
6218/*****************************************************************************/
6219/* Locate peripheral chips
6220 *
6221 * Return values:
6222 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
6223 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
6224 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
6225 */
6226#define EC_CMD_LOCATE_CHIP 0x0126
6227
6228enum ec_chip_type {
6229 EC_CHIP_TYPE_CBI_EEPROM = 0,
6230 EC_CHIP_TYPE_TCPC = 1,
6231 EC_CHIP_TYPE_COUNT,
6232 EC_CHIP_TYPE_MAX = 0xFF,
6233};
6234
6235enum ec_bus_type {
6236 EC_BUS_TYPE_I2C = 0,
6237 EC_BUS_TYPE_EMBEDDED = 1,
6238 EC_BUS_TYPE_COUNT,
6239 EC_BUS_TYPE_MAX = 0xFF,
6240};
6241
6242struct ec_i2c_info {
6243 uint16_t port; /* Physical port for device */
6244 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
6245};
6246
6247struct ec_params_locate_chip {
6248 uint8_t type; /* enum ec_chip_type */
6249 uint8_t index; /* Specifies one instance of chip type */
6250 /* Used for type specific parameters in future */
6251 union {
6252 uint16_t reserved;
6253 };
6254} __ec_align2;
6255
Yidi Lin42f79592020-09-21 18:04:10 +08006256
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006257struct ec_response_locate_chip {
6258 uint8_t bus_type; /* enum ec_bus_type */
6259 uint8_t reserved; /* Aligning the following union to 2 bytes */
6260 union {
6261 struct ec_i2c_info i2c_info;
6262 };
6263} __ec_align2;
6264
Jett Rinkba2edaf2020-01-14 11:49:06 -07006265/*
6266 * Reboot AP on G3
6267 *
6268 * This command is used for validation purpose, where the AP needs to be
6269 * returned back to S0 state from G3 state without using the servo to trigger
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006270 * wake events.
6271 * - With command version 0:
6272 * AP reboots immediately from G3
6273 * command usage: ectool reboot_ap_on_g3 && shutdown -h now
6274 * - With command version 1:
6275 * AP reboots after the user specified delay
6276 * command usage: ectool reboot_ap_on_g3 [<delay>] && shutdown -h now
Jett Rinkba2edaf2020-01-14 11:49:06 -07006277 */
6278#define EC_CMD_REBOOT_AP_ON_G3 0x0127
6279
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006280struct ec_params_reboot_ap_on_g3_v1 {
6281 /* configurable delay in seconds in G3 state */
6282 uint32_t reboot_ap_at_g3_delay;
6283} __ec_align4;
6284
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006285/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07006286/* Get PD port capabilities
6287 *
6288 * Returns the following static *capabilities* of the given port:
6289 * 1) Power role: source, sink, or dual. It is not anticipated that
6290 * future CrOS devices would ever be only a source, so the options are
6291 * sink or dual.
6292 * 2) Try-power role: source, sink, or none (practically speaking, I don't
6293 * believe any CrOS device would support Try.SNK, so this would be source
6294 * or none).
6295 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
6296 * for CrOS devices.
6297 */
6298#define EC_CMD_GET_PD_PORT_CAPS 0x0128
6299
6300enum ec_pd_power_role_caps {
6301 EC_PD_POWER_ROLE_SOURCE = 0,
6302 EC_PD_POWER_ROLE_SINK = 1,
6303 EC_PD_POWER_ROLE_DUAL = 2,
6304};
6305
6306enum ec_pd_try_power_role_caps {
6307 EC_PD_TRY_POWER_ROLE_NONE = 0,
6308 EC_PD_TRY_POWER_ROLE_SINK = 1,
6309 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6310};
6311
6312enum ec_pd_data_role_caps {
6313 EC_PD_DATA_ROLE_DFP = 0,
6314 EC_PD_DATA_ROLE_UFP = 1,
6315 EC_PD_DATA_ROLE_DUAL = 2,
6316};
6317
6318/* From: power_manager/power_supply_properties.proto */
6319enum ec_pd_port_location {
6320 /* The location of the port is unknown, or there's only one port. */
6321 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6322
6323 /*
6324 * Various positions on the device. The first word describes the side of
6325 * the device where the port is located while the second clarifies the
6326 * position. For example, LEFT_BACK means the farthest-back port on the
6327 * left side, while BACK_LEFT means the leftmost port on the back of the
6328 * device.
6329 */
6330 EC_PD_PORT_LOCATION_LEFT = 1,
6331 EC_PD_PORT_LOCATION_RIGHT = 2,
6332 EC_PD_PORT_LOCATION_BACK = 3,
6333 EC_PD_PORT_LOCATION_FRONT = 4,
6334 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6335 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
6336 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
6337 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6338 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6339 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
6340};
6341
6342struct ec_params_get_pd_port_caps {
6343 uint8_t port; /* Which port to interrogate */
6344} __ec_align1;
6345
6346struct ec_response_get_pd_port_caps {
6347 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6348 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6349 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6350 uint8_t pd_port_location; /* enum ec_pd_port_location */
6351} __ec_align1;
6352
6353/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006354/*
6355 * Button press simulation
6356 *
6357 * This command is used to simulate a button press.
6358 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6359 * Time duration for which button needs to be pressed is an optional parameter.
6360 *
6361 * NOTE: This is only available on unlocked devices for testing purposes only.
6362 */
6363#define EC_CMD_BUTTON 0x0129
6364
6365struct ec_params_button {
6366 /* Button mask aligned to enum keyboard_button_type */
6367 uint32_t btn_mask;
6368
6369 /* Duration in milliseconds button needs to be pressed */
6370 uint32_t press_ms;
6371} __ec_align1;
6372
6373enum keyboard_button_type {
6374 KEYBOARD_BUTTON_POWER = 0,
6375 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
6376 KEYBOARD_BUTTON_VOLUME_UP = 2,
6377 KEYBOARD_BUTTON_RECOVERY = 3,
6378 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6379 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6380 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6381 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6382 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6383 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6384 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6385 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
6386
6387 KEYBOARD_BUTTON_COUNT
6388};
Yidi Lin42f79592020-09-21 18:04:10 +08006389
Rajat Jainc0495722020-04-02 23:58:35 -07006390/*****************************************************************************/
6391/*
6392 * "Get the Keyboard Config". An EC implementing this command is expected to be
6393 * vivaldi capable, i.e. can send action codes for the top row keys.
6394 * Additionally, capability to send function codes for the same keys is
6395 * optional and acceptable.
6396 *
6397 * Note: If the top row can generate both function and action codes by
6398 * using a dedicated Fn key, it does not matter whether the key sends
6399 * "function" or "action" codes by default. In both cases, the response
6400 * for this command will look the same.
6401 */
6402#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6403
6404/* Possible values for the top row keys */
6405enum action_key {
6406 TK_ABSENT = 0,
6407 TK_BACK = 1,
6408 TK_FORWARD = 2,
6409 TK_REFRESH = 3,
6410 TK_FULLSCREEN = 4,
6411 TK_OVERVIEW = 5,
6412 TK_BRIGHTNESS_DOWN = 6,
6413 TK_BRIGHTNESS_UP = 7,
6414 TK_VOL_MUTE = 8,
6415 TK_VOL_DOWN = 9,
6416 TK_VOL_UP = 10,
6417 TK_SNAPSHOT = 11,
6418 TK_PRIVACY_SCRN_TOGGLE = 12,
6419 TK_KBD_BKLIGHT_DOWN = 13,
6420 TK_KBD_BKLIGHT_UP = 14,
6421 TK_PLAY_PAUSE = 15,
6422 TK_NEXT_TRACK = 16,
6423 TK_PREV_TRACK = 17,
Scott Chao18141d8c2021-07-30 10:40:57 +08006424 TK_KBD_BKLIGHT_TOGGLE = 18,
6425 TK_MICMUTE = 19,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006426 TK_MENU = 20,
Rajat Jainc0495722020-04-02 23:58:35 -07006427};
6428
6429/*
6430 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6431 * If this needs to change, please create a new version of the command.
6432 */
6433#define MAX_TOP_ROW_KEYS 15
6434#define MIN_TOP_ROW_KEYS 10
6435
6436/*
6437 * Is the keyboard capable of sending function keys *in addition to*
6438 * action keys. This is possible for e.g. if the keyboard has a
6439 * dedicated Fn key.
6440 */
6441#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
6442/*
6443 * Whether the keyboard has a dedicated numeric keyboard.
6444 */
6445#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
6446/*
6447 * Whether the keyboard has a screenlock key.
6448 */
6449#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
6450
6451struct ec_response_keybd_config {
6452 /*
6453 * Number of top row keys, excluding Esc and Screenlock.
6454 * If this is 0, all Vivaldi keyboard code is disabled.
6455 * (i.e. does not expose any tables to the kernel).
6456 */
6457 uint8_t num_top_row_keys;
6458
6459 /*
6460 * The action keys in the top row, in order from left to right.
6461 * The values are filled from enum action_key. Esc and Screenlock
6462 * keys are not considered part of top row keys.
6463 */
6464 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6465
6466 /* Capability flags */
6467 uint8_t capabilities;
6468
6469} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006470
Yidi Lin42f79592020-09-21 18:04:10 +08006471/*
6472 * Configure smart discharge
6473 */
6474#define EC_CMD_SMART_DISCHARGE 0x012B
6475
6476#define EC_SMART_DISCHARGE_FLAGS_SET BIT(0)
6477
6478/* Discharge rates when the system is in cutoff or hibernation. */
6479struct discharge_rate {
6480 uint16_t cutoff; /* Discharge rate (uA) in cutoff */
6481 uint16_t hibern; /* Discharge rate (uA) in hibernation */
6482};
6483
6484struct smart_discharge_zone {
6485 /* When the capacity (mAh) goes below this, EC cuts off the battery. */
6486 int cutoff;
6487 /* When the capacity (mAh) is below this, EC stays up. */
6488 int stayup;
6489};
6490
6491struct ec_params_smart_discharge {
6492 uint8_t flags; /* EC_SMART_DISCHARGE_FLAGS_* */
6493 /*
6494 * Desired hours for the battery to survive before reaching 0%. Set to
6495 * zero to disable smart discharging. That is, the system hibernates as
6496 * soon as the G3 idle timer expires.
6497 */
6498 uint16_t hours_to_zero;
6499 /* Set both to zero to keep the current rates. */
6500 struct discharge_rate drate;
6501};
6502
6503struct ec_response_smart_discharge {
6504 uint16_t hours_to_zero;
6505 struct discharge_rate drate;
6506 struct smart_discharge_zone dzone;
6507};
6508
6509/*****************************************************************************/
6510/* Voltage regulator controls */
6511
6512/*
6513 * Get basic info of voltage regulator for given index.
6514 *
6515 * Returns the regulator name and supported voltage list in mV.
6516 */
6517#define EC_CMD_REGULATOR_GET_INFO 0x012C
6518
6519/* Maximum length of regulator name */
6520#define EC_REGULATOR_NAME_MAX_LEN 16
6521
6522/* Maximum length of the supported voltage list. */
6523#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16
6524
6525struct ec_params_regulator_get_info {
6526 uint32_t index;
6527} __ec_align4;
6528
6529struct ec_response_regulator_get_info {
6530 char name[EC_REGULATOR_NAME_MAX_LEN];
6531 uint16_t num_voltages;
6532 uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT];
6533} __ec_align2;
6534
6535/*
6536 * Configure the regulator as enabled / disabled.
6537 */
6538#define EC_CMD_REGULATOR_ENABLE 0x012D
6539
6540struct ec_params_regulator_enable {
6541 uint32_t index;
6542 uint8_t enable;
6543} __ec_align4;
6544
6545/*
6546 * Query if the regulator is enabled.
6547 *
6548 * Returns 1 if the regulator is enabled, 0 if not.
6549 */
6550#define EC_CMD_REGULATOR_IS_ENABLED 0x012E
6551
6552struct ec_params_regulator_is_enabled {
6553 uint32_t index;
6554} __ec_align4;
6555
6556struct ec_response_regulator_is_enabled {
6557 uint8_t enabled;
6558} __ec_align1;
6559
6560/*
6561 * Set voltage for the voltage regulator within the range specified.
6562 *
6563 * The driver should select the voltage in range closest to min_mv.
6564 *
6565 * Also note that this might be called before the regulator is enabled, and the
6566 * setting should be in effect after the regulator is enabled.
6567 */
6568#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F
6569
6570struct ec_params_regulator_set_voltage {
6571 uint32_t index;
6572 uint32_t min_mv;
6573 uint32_t max_mv;
6574} __ec_align4;
6575
6576/*
6577 * Get the currently configured voltage for the voltage regulator.
6578 *
6579 * Note that this might be called before the regulator is enabled, and this
6580 * should return the configured output voltage if the regulator is enabled.
6581 */
6582#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130
6583
6584struct ec_params_regulator_get_voltage {
6585 uint32_t index;
6586} __ec_align4;
6587
6588struct ec_response_regulator_get_voltage {
6589 uint32_t voltage_mv;
6590} __ec_align4;
6591
6592/*
6593 * Gather all discovery information for the given port and partner type.
6594 *
6595 * Note that if discovery has not yet completed, only the currently completed
6596 * responses will be filled in. If the discovery data structures are changed
6597 * in the process of the command running, BUSY will be returned.
6598 *
6599 * VDO field sizes are set to the maximum possible number of VDOs a VDM may
6600 * contain, while the number of SVIDs here is selected to fit within the PROTO2
6601 * maximum parameter size.
6602 */
6603#define EC_CMD_TYPEC_DISCOVERY 0x0131
6604
6605enum typec_partner_type {
6606 TYPEC_PARTNER_SOP = 0,
6607 TYPEC_PARTNER_SOP_PRIME = 1,
6608};
6609
6610struct ec_params_typec_discovery {
6611 uint8_t port;
6612 uint8_t partner_type; /* enum typec_partner_type */
6613} __ec_align1;
6614
6615struct svid_mode_info {
6616 uint16_t svid;
6617 uint16_t mode_count; /* Number of modes partner sent */
6618 uint32_t mode_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6619};
6620
6621struct ec_response_typec_discovery {
6622 uint8_t identity_count; /* Number of identity VDOs partner sent */
6623 uint8_t svid_count; /* Number of SVIDs partner sent */
6624 uint16_t reserved;
6625 uint32_t discovery_vdo[6]; /* Max VDOs allowed after VDM header is 6 */
6626 struct svid_mode_info svids[0];
6627} __ec_align1;
6628
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006629/* USB Type-C commands for AP-controlled device policy. */
6630#define EC_CMD_TYPEC_CONTROL 0x0132
6631
6632enum typec_control_command {
6633 TYPEC_CONTROL_COMMAND_EXIT_MODES,
6634 TYPEC_CONTROL_COMMAND_CLEAR_EVENTS,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006635 TYPEC_CONTROL_COMMAND_ENTER_MODE,
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006636 TYPEC_CONTROL_COMMAND_TBT_UFP_REPLY,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006637};
6638
6639/* Modes (USB or alternate) that a type-C port may enter. */
6640enum typec_mode {
6641 TYPEC_MODE_DP,
6642 TYPEC_MODE_TBT,
6643 TYPEC_MODE_USB4,
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006644};
6645
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006646/* Replies the AP may specify to the TBT EnterMode command as a UFP */
6647enum typec_tbt_ufp_reply {
6648 TYPEC_TBT_UFP_REPLY_NAK,
6649 TYPEC_TBT_UFP_REPLY_ACK,
6650};
6651
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006652struct ec_params_typec_control {
6653 uint8_t port;
6654 uint8_t command; /* enum typec_control_command */
6655 uint16_t reserved;
6656
6657 /*
6658 * This section will be interpreted based on |command|. Define a
6659 * placeholder structure to avoid having to increase the size and bump
6660 * the command version when adding new sub-commands.
6661 */
6662 union {
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006663 /* Used for CLEAR_EVENTS */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006664 uint32_t clear_events_mask;
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006665 /* Used for ENTER_MODE - enum typec_mode */
6666 uint8_t mode_to_enter;
6667 /* Used for TBT_UFP_REPLY - enum typec_tbt_ufp_reply */
6668 uint8_t tbt_ufp_reply;
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006669 uint8_t placeholder[128];
6670 };
6671} __ec_align1;
6672
6673/*
6674 * Gather all status information for a port.
6675 *
6676 * Note: this covers many of the return fields from the deprecated
6677 * EC_CMD_USB_PD_CONTROL command, except those that are redundant with the
6678 * discovery data. The "enum pd_cc_states" is defined with the deprecated
6679 * EC_CMD_USB_PD_CONTROL command.
6680 *
6681 * This also combines in the EC_CMD_USB_PD_MUX_INFO flags.
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006682 */
6683#define EC_CMD_TYPEC_STATUS 0x0133
6684
6685/*
6686 * Power role.
6687 *
6688 * Note this is also used for PD header creation, and values align to those in
6689 * the Power Delivery Specification Revision 3.0 (See
6690 * 6.2.1.1.4 Port Power Role).
6691 */
6692enum pd_power_role {
6693 PD_ROLE_SINK = 0,
6694 PD_ROLE_SOURCE = 1
6695};
6696
6697/*
6698 * Data role.
6699 *
6700 * Note this is also used for PD header creation, and the first two values
6701 * align to those in the Power Delivery Specification Revision 3.0 (See
6702 * 6.2.1.1.6 Port Data Role).
6703 */
6704enum pd_data_role {
6705 PD_ROLE_UFP = 0,
6706 PD_ROLE_DFP = 1,
6707 PD_ROLE_DISCONNECTED = 2,
6708};
6709
6710enum pd_vconn_role {
6711 PD_ROLE_VCONN_OFF = 0,
6712 PD_ROLE_VCONN_SRC = 1,
6713};
6714
6715/*
6716 * Note: BIT(0) may be used to determine whether the polarity is CC1 or CC2,
6717 * regardless of whether a debug accessory is connected.
6718 */
6719enum tcpc_cc_polarity {
6720 /*
6721 * _CCx: is used to indicate the polarity while not connected to
6722 * a Debug Accessory. Only one CC line will assert a resistor and
6723 * the other will be open.
6724 */
6725 POLARITY_CC1 = 0,
6726 POLARITY_CC2 = 1,
6727
6728 /*
6729 * _CCx_DTS is used to indicate the polarity while connected to a
6730 * SRC Debug Accessory. Assert resistors on both lines.
6731 */
6732 POLARITY_CC1_DTS = 2,
6733 POLARITY_CC2_DTS = 3,
6734
6735 /*
6736 * The current TCPC code relies on these specific POLARITY values.
6737 * Adding in a check to verify if the list grows for any reason
6738 * that this will give a hint that other places need to be
6739 * adjusted.
6740 */
6741 POLARITY_COUNT
6742};
6743
6744#define MODE_DP_PIN_A BIT(0)
6745#define MODE_DP_PIN_B BIT(1)
6746#define MODE_DP_PIN_C BIT(2)
6747#define MODE_DP_PIN_D BIT(3)
6748#define MODE_DP_PIN_E BIT(4)
6749#define MODE_DP_PIN_F BIT(5)
6750#define MODE_DP_PIN_ALL GENMASK(5, 0)
6751
6752#define PD_STATUS_EVENT_SOP_DISC_DONE BIT(0)
6753#define PD_STATUS_EVENT_SOP_PRIME_DISC_DONE BIT(1)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006754#define PD_STATUS_EVENT_HARD_RESET BIT(2)
Scott Chao18141d8c2021-07-30 10:40:57 +08006755#define PD_STATUS_EVENT_DISCONNECTED BIT(3)
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006756
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006757/*
6758 * Encode and decode for BCD revision response
6759 *
6760 * Note: the major revision set is written assuming that the value given is the
6761 * Specification Revision from the PD header, which currently only maps to PD
6762 * 1.0-3.0 with the major revision being one greater than the binary value.
6763 */
6764#define PD_STATUS_REV_SET_MAJOR(r) ((r + 1) << 12)
6765#define PD_STATUS_REV_GET_MAJOR(r) ((r >> 12) & 0xF)
6766#define PD_STATUS_REV_GET_MINOR(r) ((r >> 8) & 0xF)
6767
6768/*
6769 * Decode helpers for Source and Sink Capability PDOs
6770 *
6771 * Note: The Power Delivery Specification should be considered the ultimate
6772 * source of truth on the decoding of these PDOs
6773 */
6774#define PDO_TYPE_FIXED (0 << 30)
6775#define PDO_TYPE_BATTERY (1 << 30)
6776#define PDO_TYPE_VARIABLE (2 << 30)
6777#define PDO_TYPE_AUGMENTED (3 << 30)
6778#define PDO_TYPE_MASK (3 << 30)
6779
6780/*
6781 * From Table 6-9 and Table 6-14 PD Rev 3.0 Ver 2.0
6782 *
6783 * <31:30> : Fixed Supply
6784 * <29> : Dual-Role Power
6785 * <28> : SNK/SRC dependent
6786 * <27> : Unconstrained Power
6787 * <26> : USB Communications Capable
6788 * <25> : Dual-Role Data
6789 * <24:20> : SNK/SRC dependent
6790 * <19:10> : Voltage in 50mV Units
6791 * <9:0> : Maximum Current in 10mA units
6792 */
6793#define PDO_FIXED_DUAL_ROLE BIT(29)
6794#define PDO_FIXED_UNCONSTRAINED BIT(27)
6795#define PDO_FIXED_COMM_CAP BIT(26)
6796#define PDO_FIXED_DATA_SWAP BIT(25)
6797#define PDO_FIXED_FRS_CURR_MASK GENMASK(24, 23) /* Sink Cap only */
6798#define PDO_FIXED_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6799#define PDO_FIXED_CURRENT(p) ((p & 0x3FF) * 10)
6800
6801/*
6802 * From Table 6-12 and Table 6-16 PD Rev 3.0 Ver 2.0
6803 *
6804 * <31:30> : Battery
6805 * <29:20> : Maximum Voltage in 50mV units
6806 * <19:10> : Minimum Voltage in 50mV units
6807 * <9:0> : Maximum Allowable Power in 250mW units
6808 */
6809#define PDO_BATT_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6810#define PDO_BATT_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6811#define PDO_BATT_MAX_POWER(p) ((p & 0x3FF) * 250)
6812
6813/*
6814 * From Table 6-11 and Table 6-15 PD Rev 3.0 Ver 2.0
6815 *
6816 * <31:30> : Variable Supply (non-Battery)
6817 * <29:20> : Maximum Voltage in 50mV units
6818 * <19:10> : Minimum Voltage in 50mV units
6819 * <9:0> : Operational Current in 10mA units
6820 */
6821#define PDO_VAR_MAX_VOLTAGE(p) ((p >> 20 & 0x3FF) * 50)
6822#define PDO_VAR_MIN_VOLTAGE(p) ((p >> 10 & 0x3FF) * 50)
6823#define PDO_VAR_MAX_CURRENT(p) ((p & 0x3FF) * 10)
6824
6825/*
6826 * From Table 6-13 and Table 6-17 PD Rev 3.0 Ver 2.0
6827 *
6828 * Note this type is reserved in PD 2.0, and only one type of APDO is
6829 * supported as of the cited version.
6830 *
6831 * <31:30> : Augmented Power Data Object
6832 * <29:28> : Programmable Power Supply
6833 * <27> : PPS Power Limited
6834 * <26:25> : Reserved
6835 * <24:17> : Maximum Voltage in 100mV increments
6836 * <16> : Reserved
6837 * <15:8> : Minimum Voltage in 100mV increments
6838 * <7> : Reserved
6839 * <6:0> : Maximum Current in 50mA increments
6840 */
6841#define PDO_AUG_MAX_VOLTAGE(p) ((p >> 17 & 0xFF) * 100)
6842#define PDO_AUG_MIN_VOLTAGE(p) ((p >> 8 & 0xFF) * 100)
6843#define PDO_AUG_MAX_CURRENT(p) ((p & 0x7F) * 50)
6844
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006845struct ec_params_typec_status {
6846 uint8_t port;
6847} __ec_align1;
6848
6849struct ec_response_typec_status {
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006850 uint8_t pd_enabled; /* PD communication enabled - bool */
6851 uint8_t dev_connected; /* Device connected - bool */
6852 uint8_t sop_connected; /* Device is SOP PD capable - bool */
6853 uint8_t source_cap_count; /* Number of Source Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006854
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006855 uint8_t power_role; /* enum pd_power_role */
6856 uint8_t data_role; /* enum pd_data_role */
6857 uint8_t vconn_role; /* enum pd_vconn_role */
6858 uint8_t sink_cap_count; /* Number of Sink Cap PDOs */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006859
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006860 uint8_t polarity; /* enum tcpc_cc_polarity */
6861 uint8_t cc_state; /* enum pd_cc_states */
6862 uint8_t dp_pin; /* DP pin mode (MODE_DP_IN_[A-E]) */
6863 uint8_t mux_state; /* USB_PD_MUX* - encoded mux state */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006864
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006865 char tc_state[32]; /* TC state name */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006866
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006867 uint32_t events; /* PD_STATUS_EVENT bitmask */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006868
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006869 /*
6870 * BCD PD revisions for partners
6871 *
6872 * The format has the PD major reversion in the upper nibble, and PD
6873 * minor version in the next nibble. Following two nibbles are
6874 * currently 0.
6875 * ex. PD 3.2 would map to 0x3200
6876 *
6877 * PD major/minor will be 0 if no PD device is connected.
6878 */
6879 uint16_t sop_revision;
6880 uint16_t sop_prime_revision;
6881
6882 uint32_t source_cap_pdos[7]; /* Max 7 PDOs can be present */
6883
6884 uint32_t sink_cap_pdos[7]; /* Max 7 PDOs can be present */
Tim Wawrzynczak7c80de62020-10-01 13:00:00 -06006885} __ec_align1;
6886
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006887/**
6888 * Get the number of peripheral charge ports
6889 */
6890#define EC_CMD_PCHG_COUNT 0x0134
6891
6892#define EC_PCHG_MAX_PORTS 8
6893
6894struct ec_response_pchg_count {
6895 uint8_t port_count;
6896} __ec_align1;
6897
6898/**
6899 * Get the status of a peripheral charge port
6900 */
6901#define EC_CMD_PCHG 0x0135
6902
6903struct ec_params_pchg {
6904 uint8_t port;
6905} __ec_align1;
6906
6907struct ec_response_pchg {
6908 uint32_t error; /* enum pchg_error */
6909 uint8_t state; /* enum pchg_state state */
6910 uint8_t battery_percentage;
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006911 uint8_t unused0;
6912 uint8_t unused1;
6913 /* Fields added in version 1 */
6914 uint32_t fw_version;
6915 uint32_t dropped_event_count;
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006916} __ec_align2;
6917
6918enum pchg_state {
6919 /* Charger is reset and not initialized. */
6920 PCHG_STATE_RESET = 0,
6921 /* Charger is initialized or disabled. */
6922 PCHG_STATE_INITIALIZED,
6923 /* Charger is enabled and ready to detect a device. */
6924 PCHG_STATE_ENABLED,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006925 /* Device is in proximity. */
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006926 PCHG_STATE_DETECTED,
6927 /* Device is being charged. */
6928 PCHG_STATE_CHARGING,
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006929 /* Device is fully charged. It implies DETECTED (& not charging). */
6930 PCHG_STATE_FULL,
6931 /* In download (a.k.a. firmware update) mode */
6932 PCHG_STATE_DOWNLOAD,
6933 /* In download mode. Ready for receiving data. */
6934 PCHG_STATE_DOWNLOADING,
6935 /* Device is ready for data communication. */
6936 PCHG_STATE_CONNECTED,
6937 /* Put no more entry below */
6938 PCHG_STATE_COUNT,
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006939};
6940
6941#define EC_PCHG_STATE_TEXT { \
6942 [PCHG_STATE_RESET] = "RESET", \
6943 [PCHG_STATE_INITIALIZED] = "INITIALIZED", \
6944 [PCHG_STATE_ENABLED] = "ENABLED", \
6945 [PCHG_STATE_DETECTED] = "DETECTED", \
6946 [PCHG_STATE_CHARGING] = "CHARGING", \
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006947 [PCHG_STATE_FULL] = "FULL", \
6948 [PCHG_STATE_DOWNLOAD] = "DOWNLOAD", \
6949 [PCHG_STATE_DOWNLOADING] = "DOWNLOADING", \
6950 [PCHG_STATE_CONNECTED] = "CONNECTED", \
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08006951 }
6952
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006953/**
6954 * Update firmware of peripheral chip
6955 */
6956#define EC_CMD_PCHG_UPDATE 0x0136
6957
6958/* Port number is encoded in bit[28:31]. */
6959#define EC_MKBP_PCHG_PORT_SHIFT 28
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006960/* Utility macros for converting MKBP event <-> port number. */
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006961#define EC_MKBP_PCHG_EVENT_TO_PORT(e) (((e) >> EC_MKBP_PCHG_PORT_SHIFT) & 0xf)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006962#define EC_MKBP_PCHG_PORT_TO_EVENT(p) (BIT((p) + EC_MKBP_PCHG_PORT_SHIFT))
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006963/* Utility macro for extracting event bits. */
6964#define EC_MKBP_PCHG_EVENT_MASK(e) ((e) \
6965 & GENMASK(EC_MKBP_PCHG_PORT_SHIFT-1, 0))
6966
6967#define EC_MKBP_PCHG_UPDATE_OPENED BIT(0)
6968#define EC_MKBP_PCHG_WRITE_COMPLETE BIT(1)
6969#define EC_MKBP_PCHG_UPDATE_CLOSED BIT(2)
6970#define EC_MKBP_PCHG_UPDATE_ERROR BIT(3)
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08006971#define EC_MKBP_PCHG_DEVICE_EVENT BIT(4)
Rob Barnes8bc5fa92021-06-28 09:32:28 -06006972
6973enum ec_pchg_update_cmd {
6974 /* Reset chip to normal mode. */
6975 EC_PCHG_UPDATE_CMD_RESET_TO_NORMAL = 0,
6976 /* Reset and put a chip in update (a.k.a. download) mode. */
6977 EC_PCHG_UPDATE_CMD_OPEN,
6978 /* Write a block of data containing FW image. */
6979 EC_PCHG_UPDATE_CMD_WRITE,
6980 /* Close update session. */
6981 EC_PCHG_UPDATE_CMD_CLOSE,
6982 /* End of commands */
6983 EC_PCHG_UPDATE_CMD_COUNT,
6984};
6985
6986struct ec_params_pchg_update {
6987 /* PCHG port number */
6988 uint8_t port;
6989 /* enum ec_pchg_update_cmd */
6990 uint8_t cmd;
6991 /* Padding */
6992 uint8_t reserved0;
6993 uint8_t reserved1;
6994 /* Version of new firmware */
6995 uint32_t version;
6996 /* CRC32 of new firmware */
6997 uint32_t crc32;
6998 /* Address in chip memory where <data> is written to */
6999 uint32_t addr;
7000 /* Size of <data> */
7001 uint32_t size;
7002 /* Partial data of new firmware */
7003 uint8_t data[];
7004} __ec_align4;
7005
7006BUILD_ASSERT(EC_PCHG_UPDATE_CMD_COUNT
7007 < BIT(sizeof(((struct ec_params_pchg_update *)0)->cmd)*8));
7008
7009struct ec_response_pchg_update {
7010 /* Block size */
7011 uint32_t block_size;
7012} __ec_align4;
7013
7014
7015#define EC_CMD_DISPLAY_SOC 0x0137
7016
7017struct ec_response_display_soc {
7018 int16_t display_soc; /* Display charge in 10ths of a % (1000=100.0%) */
7019 int16_t full_factor; /* Full factor in 10ths of a % (1000=100.0%) */
7020 int16_t shutdown_soc; /* Shutdown SoC in 10ths of a % (1000=100.0%) */
7021} __ec_align2;
7022
7023
7024#define EC_CMD_SET_BASE_STATE 0x0138
7025
7026struct ec_params_set_base_state {
7027 uint8_t cmd; /* enum ec_set_base_state_cmd */
7028} __ec_align1;
7029
7030enum ec_set_base_state_cmd {
7031 EC_SET_BASE_STATE_DETACH = 0,
7032 EC_SET_BASE_STATE_ATTACH,
7033 EC_SET_BASE_STATE_RESET,
7034};
7035
Boris Mittelberg0c3b7f52022-02-15 14:57:55 -08007036#define EC_CMD_I2C_CONTROL 0x0139
7037
7038/* Subcommands for I2C control */
7039
7040enum ec_i2c_control_command {
7041 EC_I2C_CONTROL_GET_SPEED,
7042 EC_I2C_CONTROL_SET_SPEED,
7043};
7044
7045#define EC_I2C_CONTROL_SPEED_UNKNOWN 0
7046
7047struct ec_params_i2c_control {
7048 uint8_t port; /* I2C port number */
7049 uint8_t cmd; /* enum ec_i2c_control_command */
7050 union {
7051 uint16_t speed_khz;
7052 } cmd_params;
7053} __ec_align_size1;
7054
7055struct ec_response_i2c_control {
7056 union {
7057 uint16_t speed_khz;
7058 } cmd_response;
7059} __ec_align_size1;
7060
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07007061/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007062/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08007063
7064/*****************************************************************************/
7065/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007066 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08007067 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007068#define EC_CMD_CR51_BASE 0x0300
7069#define EC_CMD_CR51_LAST 0x03FF
7070
7071/*****************************************************************************/
7072/* Fingerprint MCU commands: range 0x0400-0x040x */
7073
7074/* Fingerprint SPI sensor passthru command: prototyping ONLY */
7075#define EC_CMD_FP_PASSTHRU 0x0400
7076
7077#define EC_FP_FLAG_NOT_COMPLETE 0x1
7078
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007079struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007080 uint16_t len; /* Number of bytes to write then read */
7081 uint16_t flags; /* EC_FP_FLAG_xxx */
7082 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007083} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007084
7085/* Configure the Fingerprint MCU behavior */
7086#define EC_CMD_FP_MODE 0x0402
7087
7088/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007089#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007090/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007091#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007092/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007093#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007094/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007095#define FP_MODE_CAPTURE BIT(3)
7096/* Finger enrollment session on-going */
7097#define FP_MODE_ENROLL_SESSION BIT(4)
7098/* Enroll the current finger image */
7099#define FP_MODE_ENROLL_IMAGE BIT(5)
7100/* Try to match the current finger image */
7101#define FP_MODE_MATCH BIT(6)
7102/* Reset and re-initialize the sensor. */
7103#define FP_MODE_RESET_SENSOR BIT(7)
Yidi Lin42f79592020-09-21 18:04:10 +08007104/* Sensor maintenance for dead pixels. */
7105#define FP_MODE_SENSOR_MAINTENANCE BIT(8)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007106/* special value: don't change anything just read back current mode */
7107#define FP_MODE_DONT_CHANGE BIT(31)
7108
7109#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
7110 FP_MODE_FINGER_DOWN | \
7111 FP_MODE_FINGER_UP | \
7112 FP_MODE_CAPTURE | \
7113 FP_MODE_ENROLL_SESSION | \
7114 FP_MODE_ENROLL_IMAGE | \
7115 FP_MODE_MATCH | \
7116 FP_MODE_RESET_SENSOR | \
Yidi Lin42f79592020-09-21 18:04:10 +08007117 FP_MODE_SENSOR_MAINTENANCE | \
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007118 FP_MODE_DONT_CHANGE)
7119
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007120/* Capture types defined in bits [30..28] */
7121#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007122#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
7123/*
7124 * This enum must remain ordered, if you add new values you must ensure that
7125 * FP_CAPTURE_TYPE_MAX is still the last one.
7126 */
7127enum fp_capture_type {
7128 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
7129 FP_CAPTURE_VENDOR_FORMAT = 0,
7130 /* Simple raw image capture (produces width x height x bpp bits) */
7131 FP_CAPTURE_SIMPLE_IMAGE = 1,
7132 /* Self test pattern (e.g. checkerboard) */
7133 FP_CAPTURE_PATTERN0 = 2,
7134 /* Self test pattern (e.g. inverted checkerboard) */
7135 FP_CAPTURE_PATTERN1 = 3,
7136 /* Capture for Quality test with fixed contrast */
7137 FP_CAPTURE_QUALITY_TEST = 4,
7138 /* Capture for pixel reset value test */
7139 FP_CAPTURE_RESET_TEST = 5,
7140 FP_CAPTURE_TYPE_MAX,
7141};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007142/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007143#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
7144 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007145
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007146struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007147 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007148} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007150struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007151 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007152} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007153
7154/* Retrieve Fingerprint sensor information */
7155#define EC_CMD_FP_INFO 0x0403
7156
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007157/* Number of dead pixels detected on the last maintenance */
7158#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007159/* Unknown number of dead pixels detected on the last maintenance */
7160#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007161/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007162#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007163/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007164#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007165/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007166#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007167/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007168#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007169
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007170struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007171 /* Sensor identification */
7172 uint32_t vendor_id;
7173 uint32_t product_id;
7174 uint32_t model_id;
7175 uint32_t version;
7176 /* Image frame characteristics */
7177 uint32_t frame_size;
7178 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7179 uint16_t width;
7180 uint16_t height;
7181 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007182 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007183} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007184
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007185struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007186 /* Sensor identification */
7187 uint32_t vendor_id;
7188 uint32_t product_id;
7189 uint32_t model_id;
7190 uint32_t version;
7191 /* Image frame characteristics */
7192 uint32_t frame_size;
7193 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
7194 uint16_t width;
7195 uint16_t height;
7196 uint16_t bpp;
7197 uint16_t errors; /* see FP_ERROR_ flags above */
7198 /* Template/finger current information */
7199 uint32_t template_size; /* max template size in bytes */
7200 uint16_t template_max; /* maximum number of fingers/templates */
7201 uint16_t template_valid; /* number of valid fingers/templates */
7202 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007203 uint32_t template_version; /* version of the template format */
7204} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007205
7206/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007207#define EC_CMD_FP_FRAME 0x0404
7208
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007209/* constants defining the 'offset' field which also contains the frame index */
7210#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007211/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007212#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007213/* First frame buffer holding a template */
7214#define FP_FRAME_INDEX_TEMPLATE 1
7215#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007216#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
7217
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007218/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07007219#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007220
7221/* Constants for encryption parameters */
7222#define FP_CONTEXT_NONCE_BYTES 12
7223#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
7224#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07007225#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007226#define FP_CONTEXT_TPM_BYTES 32
7227
Jett Rinkba2edaf2020-01-14 11:49:06 -07007228/* Constants for positive match parameters. */
7229#define FP_POSITIVE_MATCH_SALT_BYTES 16
7230
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007231struct ec_fp_template_encryption_metadata {
7232 /*
7233 * Version of the structure format (N=3).
7234 */
7235 uint16_t struct_version;
7236 /* Reserved bytes, set to 0. */
7237 uint16_t reserved;
7238 /*
7239 * The salt is *only* ever used for key derivation. The nonce is unique,
7240 * a different one is used for every message.
7241 */
7242 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07007243 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007244 uint8_t tag[FP_CONTEXT_TAG_BYTES];
7245};
7246
7247struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007248 /*
7249 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
7250 * in the high nibble, and the real offset within the frame in
7251 * FP_FRAME_OFFSET_MASK.
7252 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007253 uint32_t offset;
7254 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007255} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007256
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007257/* Load a template into the MCU */
7258#define EC_CMD_FP_TEMPLATE 0x0405
7259
7260/* Flag in the 'size' field indicating that the full template has been sent */
7261#define FP_TEMPLATE_COMMIT 0x80000000
7262
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007263struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007264 uint32_t offset;
7265 uint32_t size;
7266 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007267} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007268
7269/* Clear the current fingerprint user context and set a new one */
7270#define EC_CMD_FP_CONTEXT 0x0406
7271
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007272struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007273 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007274} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007275
Jett Rinkba2edaf2020-01-14 11:49:06 -07007276enum fp_context_action {
7277 FP_CONTEXT_ASYNC = 0,
7278 FP_CONTEXT_GET_RESULT = 1,
7279};
7280
7281/* Version 1 of the command is "asynchronous". */
7282struct ec_params_fp_context_v1 {
7283 uint8_t action; /**< enum fp_context_action */
7284 uint8_t reserved[3]; /**< padding for alignment */
7285 uint32_t userid[FP_CONTEXT_USERID_WORDS];
7286} __ec_align4;
7287
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007288#define EC_CMD_FP_STATS 0x0407
7289
7290#define FPSTATS_CAPTURE_INV BIT(0)
7291#define FPSTATS_MATCHING_INV BIT(1)
7292
7293struct ec_response_fp_stats {
7294 uint32_t capture_time_us;
7295 uint32_t matching_time_us;
7296 uint32_t overall_time_us;
7297 struct {
7298 uint32_t lo;
7299 uint32_t hi;
7300 } overall_t0;
7301 uint8_t timestamps_invalid;
7302 int8_t template_matched;
7303} __ec_align2;
7304
7305#define EC_CMD_FP_SEED 0x0408
7306struct ec_params_fp_seed {
7307 /*
7308 * Version of the structure format (N=3).
7309 */
7310 uint16_t struct_version;
7311 /* Reserved bytes, set to 0. */
7312 uint16_t reserved;
7313 /* Seed from the TPM. */
7314 uint8_t seed[FP_CONTEXT_TPM_BYTES];
7315} __ec_align4;
7316
7317#define EC_CMD_FP_ENC_STATUS 0x0409
7318
7319/* FP TPM seed has been set or not */
7320#define FP_ENC_STATUS_SEED_SET BIT(0)
7321
7322struct ec_response_fp_encryption_status {
7323 /* Used bits in encryption engine status */
7324 uint32_t valid_flags;
7325 /* Encryption engine status */
7326 uint32_t status;
7327} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007328
Jett Rinkba2edaf2020-01-14 11:49:06 -07007329#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
7330struct ec_params_fp_read_match_secret {
7331 uint16_t fgr;
7332} __ec_align4;
7333
7334/* The positive match secret has the length of the SHA256 digest. */
7335#define FP_POSITIVE_MATCH_SECRET_BYTES 32
7336struct ec_response_fp_read_match_secret {
7337 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
7338} __ec_align4;
7339
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007340/*****************************************************************************/
7341/* Touchpad MCU commands: range 0x0500-0x05FF */
7342
7343/* Perform touchpad self test */
7344#define EC_CMD_TP_SELF_TEST 0x0500
7345
7346/* Get number of frame types, and the size of each type */
7347#define EC_CMD_TP_FRAME_INFO 0x0501
7348
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007349struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007350 uint32_t n_frames;
7351 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007352} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007353
7354/* Create a snapshot of current frame readings */
7355#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
7356
7357/* Read the frame */
7358#define EC_CMD_TP_FRAME_GET 0x0503
7359
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007360struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007361 uint32_t frame_index;
7362 uint32_t offset;
7363 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007364} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08007365
7366/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007367/* EC-EC communication commands: range 0x0600-0x06FF */
7368
7369#define EC_COMM_TEXT_MAX 8
7370
7371/*
7372 * Get battery static information, i.e. information that never changes, or
7373 * very infrequently.
7374 */
7375#define EC_CMD_BATTERY_GET_STATIC 0x0600
7376
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007377/**
7378 * struct ec_params_battery_static_info - Battery static info parameters
7379 * @index: Battery index.
7380 */
7381struct ec_params_battery_static_info {
7382 uint8_t index;
7383} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007384
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007385/**
7386 * struct ec_response_battery_static_info - Battery static info response
7387 * @design_capacity: Battery Design Capacity (mAh)
7388 * @design_voltage: Battery Design Voltage (mV)
7389 * @manufacturer: Battery Manufacturer String
7390 * @model: Battery Model Number String
7391 * @serial: Battery Serial Number String
7392 * @type: Battery Type String
7393 * @cycle_count: Battery Cycle Count
7394 */
7395struct ec_response_battery_static_info {
7396 uint16_t design_capacity;
7397 uint16_t design_voltage;
7398 char manufacturer[EC_COMM_TEXT_MAX];
7399 char model[EC_COMM_TEXT_MAX];
7400 char serial[EC_COMM_TEXT_MAX];
7401 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007402 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007403 uint32_t cycle_count;
7404} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007405
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007406/**
7407 * struct ec_response_battery_static_info_v1 - hostcmd v1 battery static info
7408 * Equivalent to struct ec_response_battery_static_info, but with longer
7409 * strings.
7410 * @design_capacity: battery design capacity (in mAh)
7411 * @design_voltage: battery design voltage (in mV)
7412 * @cycle_count: battery cycle count
7413 * @manufacturer_ext: battery manufacturer string
7414 * @model_ext: battery model string
7415 * @serial_ext: battery serial number string
7416 * @type_ext: battery type string
7417 */
7418struct ec_response_battery_static_info_v1 {
7419 uint16_t design_capacity;
7420 uint16_t design_voltage;
7421 uint32_t cycle_count;
7422 char manufacturer_ext[12];
7423 char model_ext[12];
7424 char serial_ext[12];
7425 char type_ext[12];
7426} __ec_align4;
7427
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007428/*
7429 * Get battery dynamic information, i.e. information that is likely to change
7430 * every time it is read.
7431 */
7432#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
7433
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007434/**
7435 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
7436 * @index: Battery index.
7437 */
7438struct ec_params_battery_dynamic_info {
7439 uint8_t index;
7440} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007441
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007442/**
7443 * struct ec_response_battery_dynamic_info - Battery dynamic info response
7444 * @actual_voltage: Battery voltage (mV)
7445 * @actual_current: Battery current (mA); negative=discharging
7446 * @remaining_capacity: Remaining capacity (mAh)
7447 * @full_capacity: Capacity (mAh, might change occasionally)
7448 * @flags: Flags, see EC_BATT_FLAG_*
7449 * @desired_voltage: Charging voltage desired by battery (mV)
7450 * @desired_current: Charging current desired by battery (mA)
7451 */
7452struct ec_response_battery_dynamic_info {
7453 int16_t actual_voltage;
7454 int16_t actual_current;
7455 int16_t remaining_capacity;
7456 int16_t full_capacity;
7457 int16_t flags;
7458 int16_t desired_voltage;
7459 int16_t desired_current;
7460} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007461
7462/*
Rob Barnes8bc5fa92021-06-28 09:32:28 -06007463 * Control charger chip. Used to control charger chip on the peripheral.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007464 */
7465#define EC_CMD_CHARGER_CONTROL 0x0602
7466
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007467/**
7468 * struct ec_params_charger_control - Charger control parameters
7469 * @max_current: Charger current (mA). Positive to allow base to draw up to
7470 * max_current and (possibly) charge battery, negative to request current
7471 * from base (OTG).
7472 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
7473 * >= 0.
7474 * @allow_charging: Allow base battery charging (only makes sense if
7475 * max_current > 0).
7476 */
7477struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007478 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007479 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007480 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007481} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007482
Yu-Ping Wu9ff78232021-01-06 18:13:36 +08007483/* Get ACK from the USB-C SS muxes */
7484#define EC_CMD_USB_PD_MUX_ACK 0x0603
7485
7486struct ec_params_usb_pd_mux_ack {
7487 uint8_t port; /* USB-C port number */
7488} __ec_align1;
7489
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007490/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08007491/*
7492 * Reserve a range of host commands for board-specific, experimental, or
7493 * special purpose features. These can be (re)used without updating this file.
7494 *
7495 * CAUTION: Don't go nuts with this. Shipping products should document ALL
7496 * their EC commands for easier development, testing, debugging, and support.
7497 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007498 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
7499 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
7500 *
Duncan Laurieeb316852015-12-01 18:51:18 -08007501 * In your experimental code, you may want to do something like this:
7502 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007503 * #define EC_CMD_MAGIC_FOO 0x0000
7504 * #define EC_CMD_MAGIC_BAR 0x0001
7505 * #define EC_CMD_MAGIC_HEY 0x0002
7506 *
7507 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
7508 * EC_VER_MASK(0);
7509 *
7510 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
7511 * EC_VER_MASK(0);
7512 *
7513 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
7514 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08007515 */
7516#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
7517#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
7518
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007519/*
7520 * Given the private host command offset, calculate the true private host
7521 * command value.
7522 */
7523#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
7524 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
7525
Duncan Laurie93e24442014-01-06 12:30:52 -08007526/*****************************************************************************/
7527/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07007528 * Passthru commands
7529 *
7530 * Some platforms have sub-processors chained to each other. For example.
7531 *
7532 * AP <--> EC <--> PD MCU
7533 *
7534 * The top 2 bits of the command number are used to indicate which device the
7535 * command is intended for. Device 0 is always the device receiving the
7536 * command; other device mapping is board-specific.
7537 *
7538 * When a device receives a command to be passed to a sub-processor, it passes
7539 * it on with the device number set back to 0. This allows the sub-processor
7540 * to remain blissfully unaware of whether the command originated on the next
7541 * device up the chain, or was passed through from the AP.
7542 *
7543 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
7544 * AP sends command 0x4002 to the EC
7545 * EC sends command 0x0002 to the PD MCU
7546 * EC forwards PD MCU response back to the AP
7547 */
7548
7549/* Offset and max command number for sub-device n */
7550#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
7551#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
7552
7553/*****************************************************************************/
7554/*
Duncan Laurie93e24442014-01-06 12:30:52 -08007555 * Deprecated constants. These constants have been renamed for clarity. The
7556 * meaning and size has not changed. Programs that use the old names should
7557 * switch to the new names soon, as the old names may not be carried forward
7558 * forever.
7559 */
7560#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
7561#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
7562#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
7563
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06007564#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07007565
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08007566#ifdef __cplusplus
7567}
7568#endif
7569
Duncan Laurieeb316852015-12-01 18:51:18 -08007570#endif /* __CROS_EC_EC_COMMANDS_H */