blob: 62761a29adfe18b0438a03761a7e094f2b07fafd [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
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080012#ifdef __cplusplus
13extern "C" {
14#endif
15
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070016#ifdef CHROMIUM_EC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080017/*
18 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
19 * It is used to not include macros that may cause conflicts in foreign
20 * projects (refer to crbug.com/984623).
21 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070022
Duncan Laurie67f26cc2017-06-29 23:17:22 -070023/*
24 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
25 * generates more efficient code for accessing request/response structures on
26 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
27 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -070028#include "common.h"
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080029#include "compile_time_macros.h"
30
31#else
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080032#define BUILD_ASSERT(_cond)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070033#endif /* CHROMIUM_EC */
34
35#ifdef __KERNEL__
36#include <linux/limits.h>
37#else
38/*
39 * Defines macros that may be needed but are for sure defined by the linux
40 * kernel. This section is removed when cros_ec_commands.h is generated (by
41 * util/make_linux_ec_commands_h.sh).
42 * cros_ec_commands.h looks more integrated to the kernel.
43 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080044
45#ifndef BIT
46#define BIT(nr) (1UL << (nr))
Duncan Laurie67f26cc2017-06-29 23:17:22 -070047#endif
48
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080049#ifndef BIT_ULL
50#define BIT_ULL(nr) (1ULL << (nr))
51#endif
52
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070053#endif /* __KERNEL__ */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080054
Stefan Reinauerd6682e82013-02-21 15:39:35 -080055/*
Duncan Laurie93e24442014-01-06 12:30:52 -080056 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080057 *
Duncan Laurie93e24442014-01-06 12:30:52 -080058 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
59 * determined in other ways. Remove this once the kernel code no longer
60 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080061 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080062#define EC_PROTO_VERSION 0x00000002
63
64/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080065#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -080066
67/* I/O addresses for ACPI commands */
68#define EC_LPC_ADDR_ACPI_DATA 0x62
69#define EC_LPC_ADDR_ACPI_CMD 0x66
70
71/* I/O addresses for host command */
72#define EC_LPC_ADDR_HOST_DATA 0x200
73#define EC_LPC_ADDR_HOST_CMD 0x204
74
75/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080076/* Protocol version 2 */
77#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
78#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080079 * EC_PROTO2_MAX_PARAM_SIZE
80 */
Duncan Laurie93e24442014-01-06 12:30:52 -080081/* Protocol version 3 */
82#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
83#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080084
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080085/*
86 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
87 * and they tell the kernel that so we have to think of it as two parts.
88 */
Bill Richardsone221aad2013-06-12 10:50:41 -070089#define EC_HOST_CMD_REGION0 0x800
90#define EC_HOST_CMD_REGION1 0x880
91#define EC_HOST_CMD_REGION_SIZE 0x80
92
Stefan Reinauerd6682e82013-02-21 15:39:35 -080093/* EC command register bit functions */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080094#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
95#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
96#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
97#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
98#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
99#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
100#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800101
102#define EC_LPC_ADDR_MEMMAP 0x900
103#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
104#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
105
106/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700107#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
108#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
109#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
110#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800111#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
112#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
113#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
114#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
115#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700116#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
117/* Unused 0x28 - 0x2f */
118#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
119/* Unused 0x31 - 0x33 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600120#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
121/* Battery values are all 32 bits, unless otherwise noted. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800122#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
123#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
124#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600125#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
126#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
127#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
128/* Unused 0x4f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800129#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
130#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
131#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
132#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700133/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800134#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
135#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
136#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
137#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700138#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
139/* Unused 0x84 - 0x8f */
140#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
141/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800142#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
143/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
144/* 0x94 - 0x99: 1st Accelerometer */
145/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700146#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700147/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700148
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700149/*
150 * ACPI is unable to access memory mapped data at or above this offset due to
151 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
152 * which might be needed by ACPI.
153 */
154#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700155
156/* Define the format of the accelerometer mapped memory status byte. */
157#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800158#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
159#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800160
161/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
162#define EC_TEMP_SENSOR_ENTRIES 16
163/*
164 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
165 *
166 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
167 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700168#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800169
170/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700171#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
172#define EC_TEMP_SENSOR_ERROR 0xfe
173#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
174#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800175/*
176 * The offset of temperature value stored in mapped memory. This allows
177 * reporting a temperature range of 200K to 454K = -73C to 181C.
178 */
179#define EC_TEMP_SENSOR_OFFSET 200
180
Duncan Laurie93e24442014-01-06 12:30:52 -0800181/*
182 * Number of ALS readings at EC_MEMMAP_ALS
183 */
184#define EC_ALS_ENTRIES 2
185
186/*
187 * The default value a temperature sensor will return when it is present but
188 * has not been read this boot. This is a reasonable number to avoid
189 * triggering alarms on the host.
190 */
191#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
192
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800193#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
194#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
195#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
196
197/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
198#define EC_BATT_FLAG_AC_PRESENT 0x01
199#define EC_BATT_FLAG_BATT_PRESENT 0x02
200#define EC_BATT_FLAG_DISCHARGING 0x04
201#define EC_BATT_FLAG_CHARGING 0x08
202#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600203/* Set if some of the static/dynamic data is invalid (or outdated). */
204#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800205
206/* Switch flags at EC_MEMMAP_SWITCHES */
207#define EC_SWITCH_LID_OPEN 0x01
208#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
209#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700210/* Was recovery requested via keyboard; now unused. */
211#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800212/* Recovery requested via dedicated signal (from servo board) */
213#define EC_SWITCH_DEDICATED_RECOVERY 0x10
214/* Was fake developer mode switch; now unused. Remove in next refactor. */
215#define EC_SWITCH_IGNORE0 0x20
216
217/* Host command interface flags */
218/* Host command interface supports LPC args (LPC interface only) */
219#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800220/* Host command interface supports version 3 protocol */
221#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800222
223/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800224#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
225#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
226#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
227#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
228#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800229
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700230/*****************************************************************************/
231/*
232 * ACPI commands
233 *
234 * These are valid ONLY on the ACPI command/data port.
235 */
236
237/*
238 * ACPI Read Embedded Controller
239 *
240 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
241 *
242 * Use the following sequence:
243 *
244 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
245 * - Wait for EC_LPC_CMDR_PENDING bit to clear
246 * - Write address to EC_LPC_ADDR_ACPI_DATA
247 * - Wait for EC_LPC_CMDR_DATA bit to set
248 * - Read value from EC_LPC_ADDR_ACPI_DATA
249 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700250#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700251
252/*
253 * ACPI Write Embedded Controller
254 *
255 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
256 *
257 * Use the following sequence:
258 *
259 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
260 * - Wait for EC_LPC_CMDR_PENDING bit to clear
261 * - Write address to EC_LPC_ADDR_ACPI_DATA
262 * - Wait for EC_LPC_CMDR_PENDING bit to clear
263 * - Write value to EC_LPC_ADDR_ACPI_DATA
264 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700265#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700266
267/*
268 * ACPI Burst Enable Embedded Controller
269 *
270 * This enables burst mode on the EC to allow the host to issue several
271 * commands back-to-back. While in this mode, writes to mapped multi-byte
272 * data are locked out to ensure data consistency.
273 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700274#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700275
276/*
277 * ACPI Burst Disable Embedded Controller
278 *
279 * This disables burst mode on the EC and stops preventing EC writes to mapped
280 * multi-byte data.
281 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700282#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700283
284/*
285 * ACPI Query Embedded Controller
286 *
287 * This clears the lowest-order bit in the currently pending host events, and
288 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
289 * event 0x80000000 = 32), or 0 if no event was pending.
290 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700291#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700292
293/* Valid addresses in ACPI memory space, for read/write commands */
294
295/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
296#define EC_ACPI_MEM_VERSION 0x00
297/*
298 * Test location; writing value here updates test compliment byte to (0xff -
299 * value).
300 */
301#define EC_ACPI_MEM_TEST 0x01
302/* Test compliment; writes here are ignored. */
303#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
304
305/* Keyboard backlight brightness percent (0 - 100) */
306#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
307/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
308#define EC_ACPI_MEM_FAN_DUTY 0x04
309
310/*
311 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
312 * independent thresholds attached to them. The current value of the ID
313 * register determines which sensor is affected by the THRESHOLD and COMMIT
314 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
315 * as the memory-mapped sensors. The COMMIT register applies those settings.
316 *
317 * The spec does not mandate any way to read back the threshold settings
318 * themselves, but when a threshold is crossed the AP needs a way to determine
319 * which sensor(s) are responsible. Each reading of the ID register clears and
320 * returns one sensor ID that has crossed one of its threshold (in either
321 * direction) since the last read. A value of 0xFF means "no new thresholds
322 * have tripped". Setting or enabling the thresholds for a sensor will clear
323 * the unread event count for that sensor.
324 */
325#define EC_ACPI_MEM_TEMP_ID 0x05
326#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
327#define EC_ACPI_MEM_TEMP_COMMIT 0x07
328/*
329 * Here are the bits for the COMMIT register:
330 * bit 0 selects the threshold index for the chosen sensor (0/1)
331 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
332 * Each write to the commit register affects one threshold.
333 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800334#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
335#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700336/*
337 * Example:
338 *
339 * Set the thresholds for sensor 2 to 50 C and 60 C:
340 * write 2 to [0x05] -- select temp sensor 2
341 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
342 * write 0x2 to [0x07] -- enable threshold 0 with this value
343 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
344 * write 0x3 to [0x07] -- enable threshold 1 with this value
345 *
346 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
347 * write 2 to [0x05] -- select temp sensor 2
348 * write 0x1 to [0x07] -- disable threshold 1
349 */
350
351/* DPTF battery charging current limit */
352#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
353
354/* Charging limit is specified in 64 mA steps */
355#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
356/* Value to disable DPTF battery charging limit */
357#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700358
jiazi Yang51fc93f2016-07-28 05:15:01 -0400359/*
360 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800361 * Bits Definition
362 * 3:1 Device DPTF Profile Number (DDPN)
363 * 0 = Reserved for backward compatibility (indicates no valid
364 * profile number. Host should fall back to using TBMD).
365 * 1..7 = DPTF Profile number to indicate to host which table needs
366 * to be loaded.
367 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400368 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700369#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800370#define EC_ACPI_MEM_TBMD_SHIFT 0
371#define EC_ACPI_MEM_TBMD_MASK 0x1
372#define EC_ACPI_MEM_DDPN_SHIFT 1
373#define EC_ACPI_MEM_DDPN_MASK 0x7
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700374
375/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600376 * Report device features. Uses the same format as the host command, except:
377 *
378 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
379 * of features", which is of limited interest when the system is already
380 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
381 * these are supported, it defaults to 0.
382 * This allows detecting the presence of this field since older versions of
383 * the EC codebase would simply return 0xff to that unknown address. Check
384 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
385 * are valid.
386 */
387#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
388#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
389#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
390#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
391#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
392#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
393#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
394#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
395
396#define EC_ACPI_MEM_BATTERY_INDEX 0x12
397
398/*
399 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
400 * is enabled (1) or disabled (0).
401 * bit 0 USB port ID 0
402 * ...
403 * bit 7 USB port ID 7
404 */
405#define EC_ACPI_MEM_USB_PORT_POWER 0x13
406
407/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700408 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
409 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
410 */
411#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
412#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
413
414/* Current version of ACPI memory address space */
415#define EC_ACPI_MEM_VERSION_CURRENT 2
416
417
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800418/*
419 * This header file is used in coreboot both in C and ACPI code. The ACPI code
420 * is pre-processed to handle constants but the ASL compiler is unable to
421 * handle actual C code so keep it separate.
422 */
423#ifndef __ACPI__
424
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800425#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800426/*
427 * Define __packed if someone hasn't beat us to it. Linux kernel style
428 * checking prefers __packed over __attribute__((packed)).
429 */
430#ifndef __packed
431#define __packed __attribute__((packed))
432#endif
433
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700434#ifndef __aligned
435#define __aligned(x) __attribute__((aligned(x)))
436#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800437#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700438
439/*
440 * Attributes for EC request and response packets. Just defining __packed
441 * results in inefficient assembly code on ARM, if the structure is actually
442 * 32-bit aligned, as it should be for all buffers.
443 *
444 * Be very careful when adding these to existing structures. They will round
445 * up the structure size to the specified boundary.
446 *
447 * Also be very careful to make that if a structure is included in some other
448 * parent structure that the alignment will still be true given the packing of
449 * the parent structure. This is particularly important if the sub-structure
450 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200451 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700452 *
453 * Also be very careful using __packed - particularly when nesting non-packed
454 * structures inside packed ones. In fact, DO NOT use __packed directly;
455 * always use one of these attributes.
456 *
457 * Once everything is annotated properly, the following search strings should
458 * not return ANY matches in this file other than right here:
459 *
460 * "__packed" - generates inefficient code; all sub-structs must also be packed
461 *
462 * "struct [^_]" - all structs should be annotated, except for structs that are
463 * members of other structs/unions (and their original declarations should be
464 * annotated).
465 */
466#ifdef CONFIG_HOSTCMD_ALIGNED
467
468/*
469 * Packed structures where offset and size are always aligned to 1, 2, or 4
470 * byte boundary.
471 */
472#define __ec_align1 __packed
473#define __ec_align2 __packed __aligned(2)
474#define __ec_align4 __packed __aligned(4)
475
476/*
477 * Packed structure which must be under-aligned, because its size is not a
478 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
479 * of all multi-byte fields in it, even though they are themselves aligned.
480 *
481 * In theory, we could duplicate the structure with __aligned(4) for accessing
482 * its members, but use the __packed version for sizeof().
483 */
484#define __ec_align_size1 __packed
485
486/*
487 * Packed structure which must be under-aligned, because its offset inside a
488 * parent structure is not a 4-byte multiple.
489 */
490#define __ec_align_offset1 __packed
491#define __ec_align_offset2 __packed __aligned(2)
492
493/*
494 * Structures which are complicated enough that I'm skipping them on the first
495 * pass. They are effectively unchanged from their previous definitions.
496 *
497 * TODO(rspangler): Figure out what to do with these. It's likely necessary
498 * to work out the size and offset of each member and add explicit padding to
499 * maintain those.
500 */
501#define __ec_todo_packed __packed
502#define __ec_todo_unpacked
503
504#else /* !CONFIG_HOSTCMD_ALIGNED */
505
506/*
507 * Packed structures make no assumption about alignment, so they do inefficient
508 * byte-wise reads.
509 */
510#define __ec_align1 __packed
511#define __ec_align2 __packed
512#define __ec_align4 __packed
513#define __ec_align_size1 __packed
514#define __ec_align_offset1 __packed
515#define __ec_align_offset2 __packed
516#define __ec_todo_packed __packed
517#define __ec_todo_unpacked
518
519#endif /* !CONFIG_HOSTCMD_ALIGNED */
520
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800521/* LPC command status byte masks */
522/* EC has written a byte in the data register and host hasn't read it yet */
523#define EC_LPC_STATUS_TO_HOST 0x01
524/* Host has written a command/data byte and the EC hasn't read it yet */
525#define EC_LPC_STATUS_FROM_HOST 0x02
526/* EC is processing a command */
527#define EC_LPC_STATUS_PROCESSING 0x04
528/* Last write to EC was a command, not data */
529#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700530/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800531#define EC_LPC_STATUS_BURST_MODE 0x10
532/* SCI event is pending (requesting SCI query) */
533#define EC_LPC_STATUS_SCI_PENDING 0x20
534/* SMI event is pending (requesting SMI query) */
535#define EC_LPC_STATUS_SMI_PENDING 0x40
536/* (reserved) */
537#define EC_LPC_STATUS_RESERVED 0x80
538
539/*
540 * EC is busy. This covers both the EC processing a command, and the host has
541 * written a new command but the EC hasn't picked it up yet.
542 */
543#define EC_LPC_STATUS_BUSY_MASK \
544 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
545
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800546/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700547 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700548 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800549enum ec_status {
550 EC_RES_SUCCESS = 0,
551 EC_RES_INVALID_COMMAND = 1,
552 EC_RES_ERROR = 2,
553 EC_RES_INVALID_PARAM = 3,
554 EC_RES_ACCESS_DENIED = 4,
555 EC_RES_INVALID_RESPONSE = 5,
556 EC_RES_INVALID_VERSION = 6,
557 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700558 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
559 EC_RES_UNAVAILABLE = 9, /* No response available */
560 EC_RES_TIMEOUT = 10, /* We got a timeout */
561 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800562 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
563 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700564 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700565 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600566 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
567 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
568 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
569 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
570 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700571
572 EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */
573} __packed;
574BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800575
576/*
577 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
578 * EC command uses code 0 to mean "no event pending". We explicitly specify
579 * each value in the enum listing so they won't change if we delete/insert an
580 * item or rearrange the list (it needs to be stable across platforms, not
581 * just within a single compiled instance).
582 */
583enum host_event_code {
584 EC_HOST_EVENT_LID_CLOSED = 1,
585 EC_HOST_EVENT_LID_OPEN = 2,
586 EC_HOST_EVENT_POWER_BUTTON = 3,
587 EC_HOST_EVENT_AC_CONNECTED = 4,
588 EC_HOST_EVENT_AC_DISCONNECTED = 5,
589 EC_HOST_EVENT_BATTERY_LOW = 6,
590 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
591 EC_HOST_EVENT_BATTERY = 8,
592 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700593 /* Event generated by a device attached to the EC */
594 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800595 EC_HOST_EVENT_THERMAL = 11,
596 EC_HOST_EVENT_USB_CHARGER = 12,
597 EC_HOST_EVENT_KEY_PRESSED = 13,
598 /*
599 * EC has finished initializing the host interface. The host can check
600 * for this event following sending a EC_CMD_REBOOT_EC command to
601 * determine when the EC is ready to accept subsequent commands.
602 */
603 EC_HOST_EVENT_INTERFACE_READY = 14,
604 /* Keyboard recovery combo has been pressed */
605 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
606
607 /* Shutdown due to thermal overload */
608 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
609 /* Shutdown due to battery level too low */
610 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
611
Duncan Laurie93e24442014-01-06 12:30:52 -0800612 /* Suggest that the AP throttle itself */
613 EC_HOST_EVENT_THROTTLE_START = 18,
614 /* Suggest that the AP resume normal speed */
615 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700616
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800617 /* Hang detect logic detected a hang and host event timeout expired */
618 EC_HOST_EVENT_HANG_DETECT = 20,
619 /* Hang detect logic detected a hang and warm rebooted the AP */
620 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700621
622 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700623 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800624
Duncan Lauried8401182014-09-29 08:32:19 -0700625 /* Battery Status flags have changed */
626 EC_HOST_EVENT_BATTERY_STATUS = 23,
627
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700628 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800629 EC_HOST_EVENT_PANIC = 24,
630
Furquan Shaikh066cc852015-06-20 15:53:03 -0700631 /* Keyboard fastboot combo has been pressed */
632 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
633
Gwendal Grignou880b4582016-06-20 08:49:25 -0700634 /* EC RTC event occurred */
635 EC_HOST_EVENT_RTC = 26,
636
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700637 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700638 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700639
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700640 /* EC desires to change state of host-controlled USB mux */
641 EC_HOST_EVENT_USB_MUX = 28,
642
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800643 /*
644 * The device has changed "modes". This can be one of the following:
645 *
646 * - TABLET/LAPTOP mode
647 * - detachable base attach/detach event
648 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400649 EC_HOST_EVENT_MODE_CHANGE = 29,
650
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700651 /* Keyboard recovery combo with hardware reinitialization */
652 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
653
Jett Rinkba2edaf2020-01-14 11:49:06 -0700654 /* WoV */
655 EC_HOST_EVENT_WOV = 31,
656
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700657 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800658 * The high bit of the event mask is not used as a host event code. If
659 * it reads back as set, then the entire event mask should be
660 * considered invalid by the host. This can happen when reading the
661 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
662 * not initialized on the EC, or improperly configured on the host.
663 */
664 EC_HOST_EVENT_INVALID = 32
665};
666/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800667#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800668
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800669/**
670 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
671 * @flags: The host argument flags.
672 * @command_version: Command version.
673 * @data_size: The length of data.
674 * @checksum: Checksum; sum of command + flags + command_version + data_size +
675 * all params/response data bytes.
676 */
677struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800678 uint8_t flags;
679 uint8_t command_version;
680 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800681 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800682} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800683
684/* Flags for ec_lpc_host_args.flags */
685/*
686 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
687 * params.
688 *
689 * If EC gets a command and this flag is not set, this is an old-style command.
690 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
691 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700692 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800693 */
694#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
695/*
696 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
697 *
698 * If EC responds to a command and this flag is not set, this is an old-style
699 * response. Command version is 0 and response data from EC is at
700 * EC_LPC_ADDR_OLD_PARAM with unknown length.
701 */
702#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
703
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800704/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800705/*
706 * Byte codes returned by EC over SPI interface.
707 *
708 * These can be used by the AP to debug the EC interface, and to determine
709 * when the EC is not in a state where it will ever get around to responding
710 * to the AP.
711 *
712 * Example of sequence of bytes read from EC for a current good transfer:
713 * 1. - - AP asserts chip select (CS#)
714 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
715 * 3. - - EC starts handling CS# interrupt
716 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
717 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
718 * bytes looking for EC_SPI_FRAME_START
719 * 6. - - EC finishes processing and sets up response
720 * 7. EC_SPI_FRAME_START - AP reads frame byte
721 * 8. (response packet) - AP reads response packet
722 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
723 * 10 - - AP deasserts chip select
724 * 11 - - EC processes CS# interrupt and sets up DMA for
725 * next request
726 *
727 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
728 * the following byte values:
729 * EC_SPI_OLD_READY
730 * EC_SPI_RX_READY
731 * EC_SPI_RECEIVING
732 * EC_SPI_PROCESSING
733 *
734 * Then the EC found an error in the request, or was not ready for the request
735 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
736 * because the EC is unable to tell when the AP is done sending its request.
737 */
738
739/*
740 * Framing byte which precedes a response packet from the EC. After sending a
741 * request, the AP will clock in bytes until it sees the framing byte, then
742 * clock in the response packet.
743 */
744#define EC_SPI_FRAME_START 0xec
745
746/*
747 * Padding bytes which are clocked out after the end of a response packet.
748 */
749#define EC_SPI_PAST_END 0xed
750
751/*
752 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
753 * that the AP will send a valid packet header (starting with
754 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
755 */
756#define EC_SPI_RX_READY 0xf8
757
758/*
759 * EC has started receiving the request from the AP, but hasn't started
760 * processing it yet.
761 */
762#define EC_SPI_RECEIVING 0xf9
763
764/* EC has received the entire request from the AP and is processing it. */
765#define EC_SPI_PROCESSING 0xfa
766
767/*
768 * EC received bad data from the AP, such as a packet header with an invalid
769 * length. EC will ignore all data until chip select deasserts.
770 */
771#define EC_SPI_RX_BAD_DATA 0xfb
772
773/*
774 * EC received data from the AP before it was ready. That is, the AP asserted
775 * chip select and started clocking data before the EC was ready to receive it.
776 * EC will ignore all data until chip select deasserts.
777 */
778#define EC_SPI_NOT_READY 0xfc
779
780/*
781 * EC was ready to receive a request from the AP. EC has treated the byte sent
782 * by the AP as part of a request packet, or (for old-style ECs) is processing
783 * a fully received packet but is not ready to respond yet.
784 */
785#define EC_SPI_OLD_READY 0xfd
786
787/*****************************************************************************/
788
789/*
790 * Protocol version 2 for I2C and SPI send a request this way:
791 *
792 * 0 EC_CMD_VERSION0 + (command version)
793 * 1 Command number
794 * 2 Length of params = N
795 * 3..N+2 Params, if any
796 * N+3 8-bit checksum of bytes 0..N+2
797 *
798 * The corresponding response is:
799 *
800 * 0 Result code (EC_RES_*)
801 * 1 Length of params = M
802 * 2..M+1 Params, if any
803 * M+2 8-bit checksum of bytes 0..M+1
804 */
805#define EC_PROTO2_REQUEST_HEADER_BYTES 3
806#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
807#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
808 EC_PROTO2_REQUEST_TRAILER_BYTES)
809
810#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
811#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
812#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
813 EC_PROTO2_RESPONSE_TRAILER_BYTES)
814
815/* Parameter length was limited by the LPC interface */
816#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
817
818/* Maximum request and response packet sizes for protocol version 2 */
819#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
820 EC_PROTO2_MAX_PARAM_SIZE)
821#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
822 EC_PROTO2_MAX_PARAM_SIZE)
823
824/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800825
826/*
827 * Value written to legacy command port / prefix byte to indicate protocol
828 * 3+ structs are being used. Usage is bus-dependent.
829 */
830#define EC_COMMAND_PROTOCOL_3 0xda
831
832#define EC_HOST_REQUEST_VERSION 3
833
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800834/**
835 * struct ec_host_request - Version 3 request from host.
836 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
837 * receives a header with a version it doesn't know how to
838 * parse.
839 * @checksum: Checksum of request and data; sum of all bytes including checksum
840 * should total to 0.
841 * @command: Command to send (EC_CMD_...)
842 * @command_version: Command version.
843 * @reserved: Unused byte in current protocol version; set to 0.
844 * @data_len: Length of data which follows this header.
845 */
846struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800847 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800848 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800849 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800850 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800851 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800852 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800853} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800854
855#define EC_HOST_RESPONSE_VERSION 3
856
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800857/**
858 * struct ec_host_response - Version 3 response from EC.
859 * @struct_version: Struct version (=3).
860 * @checksum: Checksum of response and data; sum of all bytes including
861 * checksum should total to 0.
862 * @result: EC's response to the command (separate from communication failure)
863 * @data_len: Length of data which follows this header.
864 * @reserved: Unused bytes in current protocol version; set to 0.
865 */
866struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800867 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800868 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800869 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800870 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800871 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800872} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800873
874/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600875
876/*
877 * Host command protocol V4.
878 *
879 * Packets always start with a request or response header. They are followed
880 * by data_len bytes of data. If the data_crc_present flag is set, the data
881 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
882 * polynomial.
883 *
884 * Host algorithm when sending a request q:
885 *
886 * 101) tries_left=(some value, e.g. 3);
887 * 102) q.seq_num++
888 * 103) q.seq_dup=0
889 * 104) Calculate q.header_crc.
890 * 105) Send request q to EC.
891 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
892 *
893 * 201) If r.struct_version != 4, go to 301.
894 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
895 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
896 * 204) If r.seq_num != q.seq_num, go to 301.
897 * 205) If r.seq_dup == q.seq_dup, return success.
898 * 207) If r.seq_dup == 1, go to 301.
899 * 208) Return error.
900 *
901 * 301) If --tries_left <= 0, return error.
902 * 302) If q.seq_dup == 1, go to 105.
903 * 303) q.seq_dup = 1
904 * 304) Go to 104.
905 *
906 * EC algorithm when receiving a request q.
907 * EC has response buffer r, error buffer e.
908 *
909 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
910 * and go to 301
911 * 102) If q.header_crc mismatches calculated CRC, set e.result =
912 * EC_RES_INVALID_HEADER_CRC and go to 301
913 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
914 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
915 * and go to 301.
916 * 104) If q.seq_dup == 0, go to 201.
917 * 105) If q.seq_num != r.seq_num, go to 201.
918 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
919 *
920 * 201) Process request q into response r.
921 * 202) r.seq_num = q.seq_num
922 * 203) r.seq_dup = q.seq_dup
923 * 204) Calculate r.header_crc
924 * 205) If r.data_len > 0 and data is no longer available, set e.result =
925 * EC_RES_DUP_UNAVAILABLE and go to 301.
926 * 206) Send response r.
927 *
928 * 301) e.seq_num = q.seq_num
929 * 302) e.seq_dup = q.seq_dup
930 * 303) Calculate e.header_crc.
931 * 304) Send error response e.
932 */
933
934/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800935struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600936 /*
937 * bits 0-3: struct_version: Structure version (=4)
938 * bit 4: is_response: Is response (=0)
939 * bits 5-6: seq_num: Sequence number
940 * bit 7: seq_dup: Sequence duplicate flag
941 */
942 uint8_t fields0;
943
944 /*
945 * bits 0-4: command_version: Command version
946 * bits 5-6: Reserved (set 0, ignore on read)
947 * bit 7: data_crc_present: Is data CRC present after data
948 */
949 uint8_t fields1;
950
951 /* Command code (EC_CMD_*) */
952 uint16_t command;
953
954 /* Length of data which follows this header (not including data CRC) */
955 uint16_t data_len;
956
957 /* Reserved (set 0, ignore on read) */
958 uint8_t reserved;
959
960 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
961 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800962} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600963
964/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800965struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600966 /*
967 * bits 0-3: struct_version: Structure version (=4)
968 * bit 4: is_response: Is response (=1)
969 * bits 5-6: seq_num: Sequence number
970 * bit 7: seq_dup: Sequence duplicate flag
971 */
972 uint8_t fields0;
973
974 /*
975 * bits 0-6: Reserved (set 0, ignore on read)
976 * bit 7: data_crc_present: Is data CRC present after data
977 */
978 uint8_t fields1;
979
980 /* Result code (EC_RES_*) */
981 uint16_t result;
982
983 /* Length of data which follows this header (not including data CRC) */
984 uint16_t data_len;
985
986 /* Reserved (set 0, ignore on read) */
987 uint8_t reserved;
988
989 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
990 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800991} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600992
993/* Fields in fields0 byte */
994#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
995#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
996#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
997#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
998#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
999
1000/* Fields in fields1 byte */
1001#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1002#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1003
1004/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001005/*
1006 * Notes on commands:
1007 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001008 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001009 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001010 * specified, the command does not input or output data, respectively.
1011 * Parameter/response length is implicit in the structs. Some underlying
1012 * communication protocols (I2C, SPI) may add length or checksum headers, but
1013 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001014 *
1015 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1016 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001017 */
1018
1019/*****************************************************************************/
1020/* General / test commands */
1021
1022/*
1023 * Get protocol version, used to deal with non-backward compatible protocol
1024 * changes.
1025 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001026#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001027
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001028/**
1029 * struct ec_response_proto_version - Response to the proto version command.
1030 * @version: The protocol version.
1031 */
1032struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001033 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001034} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001035
1036/*
1037 * Hello. This is a simple command to test the EC is responsive to
1038 * commands.
1039 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001040#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001041
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001042/**
1043 * struct ec_params_hello - Parameters to the hello command.
1044 * @in_data: Pass anything here.
1045 */
1046struct ec_params_hello {
1047 uint32_t in_data;
1048} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001050/**
1051 * struct ec_response_hello - Response to the hello command.
1052 * @out_data: Output will be in_data + 0x01020304.
1053 */
1054struct ec_response_hello {
1055 uint32_t out_data;
1056} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001057
1058/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001059#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001060
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001061#if !defined(CHROMIUM_EC) && !defined(__KERNEL__)
1062/*
1063 * enum ec_current_image is deprecated and replaced by enum ec_image. This
1064 * macro exists for backwards compatibility of external projects until they
1065 * have been updated: b/149987779.
1066 */
1067#define ec_current_image ec_image
1068#endif
1069
1070enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001071 EC_IMAGE_UNKNOWN = 0,
1072 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001073 EC_IMAGE_RW,
1074 EC_IMAGE_RW_A = EC_IMAGE_RW,
1075 EC_IMAGE_RO_B,
1076 EC_IMAGE_RW_B
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001077};
1078
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001079/**
1080 * struct ec_response_get_version - Response to the get version command.
1081 * @version_string_ro: Null-terminated RO firmware version string.
1082 * @version_string_rw: Null-terminated RW firmware version string.
1083 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001084 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001085 */
1086struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001087 char version_string_ro[32];
1088 char version_string_rw[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001089 char reserved[32];
1090 uint32_t current_image;
1091} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001092
1093/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001094#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001095
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001096/**
1097 * struct ec_params_read_test - Parameters for the read test command.
1098 * @offset: Starting value for read buffer.
1099 * @size: Size to read in bytes.
1100 */
1101struct ec_params_read_test {
1102 uint32_t offset;
1103 uint32_t size;
1104} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001106/**
1107 * struct ec_response_read_test - Response to the read test command.
1108 * @data: Data returned by the read test command.
1109 */
1110struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001111 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001112} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001113
1114/*
1115 * Get build information
1116 *
1117 * Response is null-terminated string.
1118 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001119#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001120
1121/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001122#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001124/**
1125 * struct ec_response_get_chip_info - Response to the get chip info command.
1126 * @vendor: Null-terminated string for chip vendor.
1127 * @name: Null-terminated string for chip name.
1128 * @revision: Null-terminated string for chip mask version.
1129 */
1130struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001131 char vendor[32];
1132 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001133 char revision[32];
1134} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001135
1136/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001137#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001138
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001139/**
1140 * struct ec_response_board_version - Response to the board version command.
1141 * @board_version: A monotonously incrementing number.
1142 */
1143struct ec_response_board_version {
1144 uint16_t board_version;
1145} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001146
1147/*
1148 * Read memory-mapped data.
1149 *
1150 * This is an alternate interface to memory-mapped data for bus protocols
1151 * which don't support direct-mapped memory - I2C, SPI, etc.
1152 *
1153 * Response is params.size bytes of data.
1154 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001155#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001156
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001157/**
1158 * struct ec_params_read_memmap - Parameters for the read memory map command.
1159 * @offset: Offset in memmap (EC_MEMMAP_*).
1160 * @size: Size to read in bytes.
1161 */
1162struct ec_params_read_memmap {
1163 uint8_t offset;
1164 uint8_t size;
1165} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001166
1167/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001168#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001169
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001170/**
1171 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1172 * @cmd: Command to check.
1173 */
1174struct ec_params_get_cmd_versions {
1175 uint8_t cmd;
1176} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001177
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001178/**
1179 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1180 * versions (v1)
1181 * @cmd: Command to check.
1182 */
1183struct ec_params_get_cmd_versions_v1 {
1184 uint16_t cmd;
1185} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001186
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001187/**
1188 * struct ec_response_get_cmd_version - Response to the get command versions.
1189 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1190 * a desired version.
1191 */
1192struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001193 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001194} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001195
Duncan Laurie433432b2013-06-03 10:38:22 -07001196/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001197 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001198 * on lpc since it has its own out-of-band busy indicator.
1199 *
1200 * lpc must read the status from the command register. Attempting this on
1201 * lpc will overwrite the args/parameter space and corrupt its data.
1202 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001203#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001204
1205/* Avoid using ec_status which is for return values */
1206enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001207 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001208};
1209
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001210/**
1211 * struct ec_response_get_comms_status - Response to the get comms status
1212 * command.
1213 * @flags: Mask of enum ec_comms_status.
1214 */
1215struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001216 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001217} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001218
Duncan Laurie93e24442014-01-06 12:30:52 -08001219/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001220#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001221
1222/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001223struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001224 uint32_t ec_result;
1225 uint32_t ret_len;
1226 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001227} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001228
1229/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001230struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001231 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001232} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001233
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001234/* Get protocol information */
1235#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001236
1237/* Flags for ec_response_get_protocol_info.flags */
1238/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001239#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001240
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001241/**
1242 * struct ec_response_get_protocol_info - Response to the get protocol info.
1243 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1244 * version n).
1245 * @max_request_packet_size: Maximum request packet size in bytes.
1246 * @max_response_packet_size: Maximum response packet size in bytes.
1247 * @flags: see EC_PROTOCOL_INFO_*
1248 */
1249struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001250 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001251 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001252 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001253 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001254 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001255} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001256
1257
1258/*****************************************************************************/
1259/* Get/Set miscellaneous values */
1260
1261/* The upper byte of .flags tells what to do (nothing means "get") */
1262#define EC_GSV_SET 0x80000000
1263
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001264/*
1265 * The lower three bytes of .flags identifies the parameter, if that has
1266 * meaning for an individual command.
1267 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001268#define EC_GSV_PARAM_MASK 0x00ffffff
1269
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001270struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001271 uint32_t flags;
1272 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001273} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001274
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001275struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001276 uint32_t flags;
1277 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001278} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001279
Duncan Laurieeb316852015-12-01 18:51:18 -08001280/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001281#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001282
Duncan Laurieeb316852015-12-01 18:51:18 -08001283/*****************************************************************************/
1284/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001285#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001286
1287/* Supported features */
1288enum ec_feature_code {
1289 /*
1290 * This image contains a limited set of features. Another image
1291 * in RW partition may support more features.
1292 */
1293 EC_FEATURE_LIMITED = 0,
1294 /*
1295 * Commands for probing/reading/writing/erasing the flash in the
1296 * EC are present.
1297 */
1298 EC_FEATURE_FLASH = 1,
1299 /*
1300 * Can control the fan speed directly.
1301 */
1302 EC_FEATURE_PWM_FAN = 2,
1303 /*
1304 * Can control the intensity of the keyboard backlight.
1305 */
1306 EC_FEATURE_PWM_KEYB = 3,
1307 /*
1308 * Support Google lightbar, introduced on Pixel.
1309 */
1310 EC_FEATURE_LIGHTBAR = 4,
1311 /* Control of LEDs */
1312 EC_FEATURE_LED = 5,
1313 /* Exposes an interface to control gyro and sensors.
1314 * The host goes through the EC to access these sensors.
1315 * In addition, the EC may provide composite sensors, like lid angle.
1316 */
1317 EC_FEATURE_MOTION_SENSE = 6,
1318 /* The keyboard is controlled by the EC */
1319 EC_FEATURE_KEYB = 7,
1320 /* The AP can use part of the EC flash as persistent storage. */
1321 EC_FEATURE_PSTORE = 8,
1322 /* The EC monitors BIOS port 80h, and can return POST codes. */
1323 EC_FEATURE_PORT80 = 9,
1324 /*
1325 * Thermal management: include TMP specific commands.
1326 * Higher level than direct fan control.
1327 */
1328 EC_FEATURE_THERMAL = 10,
1329 /* Can switch the screen backlight on/off */
1330 EC_FEATURE_BKLIGHT_SWITCH = 11,
1331 /* Can switch the wifi module on/off */
1332 EC_FEATURE_WIFI_SWITCH = 12,
1333 /* Monitor host events, through for example SMI or SCI */
1334 EC_FEATURE_HOST_EVENTS = 13,
1335 /* The EC exposes GPIO commands to control/monitor connected devices. */
1336 EC_FEATURE_GPIO = 14,
1337 /* The EC can send i2c messages to downstream devices. */
1338 EC_FEATURE_I2C = 15,
1339 /* Command to control charger are included */
1340 EC_FEATURE_CHARGER = 16,
1341 /* Simple battery support. */
1342 EC_FEATURE_BATTERY = 17,
1343 /*
1344 * Support Smart battery protocol
1345 * (Common Smart Battery System Interface Specification)
1346 */
1347 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001348 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001349 EC_FEATURE_HANG_DETECT = 19,
1350 /* Report power information, for pit only */
1351 EC_FEATURE_PMU = 20,
1352 /* Another Cros EC device is present downstream of this one */
1353 EC_FEATURE_SUB_MCU = 21,
1354 /* Support USB Power delivery (PD) commands */
1355 EC_FEATURE_USB_PD = 22,
1356 /* Control USB multiplexer, for audio through USB port for instance. */
1357 EC_FEATURE_USB_MUX = 23,
1358 /* Motion Sensor code has an internal software FIFO */
1359 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1360 /* Support temporary secure vstore */
1361 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001362 /* EC decides on USB-C SS mux state, muxes configured by host */
1363 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1364 /* EC has RTC feature that can be controlled by host commands */
1365 EC_FEATURE_RTC = 27,
1366 /* The MCU exposes a Fingerprint sensor */
1367 EC_FEATURE_FINGERPRINT = 28,
1368 /* The MCU exposes a Touchpad */
1369 EC_FEATURE_TOUCHPAD = 29,
1370 /* The MCU has RWSIG task enabled */
1371 EC_FEATURE_RWSIG = 30,
1372 /* EC has device events support */
1373 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001374 /* EC supports the unified wake masks for LPC/eSPI systems */
1375 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001376 /* EC supports 64-bit host events */
1377 EC_FEATURE_HOST_EVENT64 = 33,
1378 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1379 EC_FEATURE_EXEC_IN_RAM = 34,
1380 /* EC supports CEC commands */
1381 EC_FEATURE_CEC = 35,
1382 /* EC supports tight sensor timestamping. */
1383 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001384 /*
1385 * EC supports tablet mode detection aligned to Chrome and allows
1386 * setting of threshold by host command using
1387 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1388 */
1389 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001390 /*
1391 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
1392 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1393 * be sent to RO to be precise.
1394 */
1395 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001396 /* The MCU is a System Companion Processor (SCP). */
1397 EC_FEATURE_SCP = 39,
1398 /* The MCU is an Integrated Sensor Hub */
1399 EC_FEATURE_ISH = 40,
Duncan Laurieeb316852015-12-01 18:51:18 -08001400};
1401
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001402#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1403#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1404
1405struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001406 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001407} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001408
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001409/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001410/* Get the board's SKU ID from EC */
1411#define EC_CMD_GET_SKU_ID 0x000E
1412
Kevin Chiue2bb0592017-09-12 09:13:41 +08001413/* Set SKU ID from AP */
1414#define EC_CMD_SET_SKU_ID 0x000F
1415
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001416struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001417 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001418} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001419
1420/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001421/* Flash commands */
1422
1423/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001424#define EC_CMD_FLASH_INFO 0x0010
1425#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001426
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001427/**
1428 * struct ec_response_flash_info - Response to the flash info command.
1429 * @flash_size: Usable flash size in bytes.
1430 * @write_block_size: Write block size. Write offset and size must be a
1431 * multiple of this.
1432 * @erase_block_size: Erase block size. Erase offset and size must be a
1433 * multiple of this.
1434 * @protect_block_size: Protection block size. Protection offset and size
1435 * must be a multiple of this.
1436 *
1437 * Version 0 returns these fields.
1438 */
1439struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001440 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001441 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001442 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001443 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001444} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001446/*
1447 * Flags for version 1+ flash info command
1448 * EC flash erases bits to 0 instead of 1.
1449 */
1450#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001451
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001452/*
1453 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001454 * be necessary on a chip where write/erase can be corrupted by other board
1455 * activity, or where the chip needs to enable some sort of programming voltage,
1456 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001457 * chip functionality.
1458 */
1459#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001460
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001461/**
1462 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1463 * @flash_size: Usable flash size in bytes.
1464 * @write_block_size: Write block size. Write offset and size must be a
1465 * multiple of this.
1466 * @erase_block_size: Erase block size. Erase offset and size must be a
1467 * multiple of this.
1468 * @protect_block_size: Protection block size. Protection offset and size
1469 * must be a multiple of this.
1470 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1471 * size is exactly this and offset is a multiple of this.
1472 * For example, an EC may have a write buffer which can do
1473 * half-page operations if data is aligned, and a slower
1474 * word-at-a-time write mode.
1475 * @flags: Flags; see EC_FLASH_INFO_*
1476 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001477 * Version 1 returns the same initial fields as version 0, with additional
1478 * fields following.
1479 *
1480 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001481 * if they did we'd define the version 0 structure as a sub-structure of this
1482 * one.
1483 *
1484 * Version 2 supports flash banks of different sizes:
1485 * The caller specified the number of banks it has preallocated
1486 * (num_banks_desc)
1487 * The EC returns the number of banks describing the flash memory.
1488 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001489 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001490struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001491 /* Version 0 fields; see above for description */
1492 uint32_t flash_size;
1493 uint32_t write_block_size;
1494 uint32_t erase_block_size;
1495 uint32_t protect_block_size;
1496
1497 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001498 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001499 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001500} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001501
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001502struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001503 /* Number of banks to describe */
1504 uint16_t num_banks_desc;
1505 /* Reserved; set 0; ignore on read */
1506 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001507} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001508
1509struct ec_flash_bank {
1510 /* Number of sector is in this bank. */
1511 uint16_t count;
1512 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1513 uint8_t size_exp;
1514 /* Minimal write size for the sectors in this bank */
1515 uint8_t write_size_exp;
1516 /* Erase size for the sectors in this bank */
1517 uint8_t erase_size_exp;
1518 /* Size for write protection, usually identical to erase size. */
1519 uint8_t protect_size_exp;
1520 /* Reserved; set 0; ignore on read */
1521 uint8_t reserved[2];
1522};
1523
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001524struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001525 /* Total flash in the EC. */
1526 uint32_t flash_size;
1527 /* Flags; see EC_FLASH_INFO_* */
1528 uint32_t flags;
1529 /* Maximum size to use to send data to write to the EC. */
1530 uint32_t write_ideal_size;
1531 /* Number of banks present in the EC. */
1532 uint16_t num_banks_total;
1533 /* Number of banks described in banks array. */
1534 uint16_t num_banks_desc;
1535 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001536} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001537
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001538/*
1539 * Read flash
1540 *
1541 * Response is params.size bytes of data.
1542 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001543#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001544
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001545/**
1546 * struct ec_params_flash_read - Parameters for the flash read command.
1547 * @offset: Byte offset to read.
1548 * @size: Size to read in bytes.
1549 */
1550struct ec_params_flash_read {
1551 uint32_t offset;
1552 uint32_t size;
1553} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001554
1555/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001556#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001557#define EC_VER_FLASH_WRITE 1
1558
1559/* Version 0 of the flash command supported only 64 bytes of data */
1560#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001561
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001562/**
1563 * struct ec_params_flash_write - Parameters for the flash write command.
1564 * @offset: Byte offset to write.
1565 * @size: Size to write in bytes.
1566 */
1567struct ec_params_flash_write {
1568 uint32_t offset;
1569 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001570 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001571} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001572
1573/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001574#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001575
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001576/**
1577 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1578 * @offset: Byte offset to erase.
1579 * @size: Size to erase in bytes.
1580 */
1581struct ec_params_flash_erase {
1582 uint32_t offset;
1583 uint32_t size;
1584} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001585
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001586/*
1587 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001588 * subcommands can returns:
1589 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1590 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1591 * EC_RES_ERROR : other errors.
1592 * EC_RES_BUSY : an existing erase operation is in progress.
1593 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1594 *
1595 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1596 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1597 * the proper result.
1598 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1599 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1600 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1601 * permitted while erasing. (For instance, STM32F4).
1602 */
1603enum ec_flash_erase_cmd {
1604 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1605 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1606 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1607};
1608
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001609/**
1610 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1611 * @cmd: One of ec_flash_erase_cmd.
1612 * @reserved: Pad byte; currently always contains 0.
1613 * @flag: No flags defined yet; set to 0.
1614 * @params: Same as v0 parameters.
1615 */
1616struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001617 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001618 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001619 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001620 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001621} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001622
1623/*
1624 * Get/set flash protection.
1625 *
1626 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1627 * firmware write protect GPIO, not all flags will take effect immediately;
1628 * some flags require a subsequent hard reset to take effect. Check the
1629 * returned flags bits to see what actually happened.
1630 *
1631 * If mask=0, simply returns the current flags state.
1632 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001633#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001634#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1635
1636/* Flags for flash protection */
1637/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001638#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001639/*
1640 * RO flash code protected now. If this bit is set, at-boot status cannot
1641 * be changed.
1642 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001643#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001644/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001645#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001646/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001647#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001648/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001649#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001650/*
1651 * Error - flash protection is in inconsistent state. At least one bank of
1652 * flash which should be protected is not protected. Usually fixed by
1653 * re-requesting the desired flags, or by a hard reset if that fails.
1654 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001655#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001656/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001657#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001658/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001659#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001660/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001661#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001662/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001663#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001664/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001665#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001666
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001667
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001668/**
1669 * struct ec_params_flash_protect - Parameters for the flash protect command.
1670 * @mask: Bits in flags to apply.
1671 * @flags: New flags to apply.
1672 */
1673struct ec_params_flash_protect {
1674 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001675 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001676} __ec_align4;
1677
1678/**
1679 * struct ec_response_flash_protect - Response to the flash protect command.
1680 * @flags: Current value of flash protect flags.
1681 * @valid_flags: Flags which are valid on this platform. This allows the
1682 * caller to distinguish between flags which aren't set vs. flags
1683 * which can't be set on this platform.
1684 * @writable_flags: Flags which can be changed given the current protection
1685 * state.
1686 */
1687struct ec_response_flash_protect {
1688 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001689 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001690 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001691} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001692
1693/*
1694 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1695 * write protect. These commands may be reused with version > 0.
1696 */
1697
1698/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001699#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001700#define EC_VER_FLASH_REGION_INFO 1
1701
1702enum ec_flash_region {
1703 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001704 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001705 /*
1706 * Region which holds active RW image. 'Active' is different from
1707 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1708 * scheduled to run, active/non-active applies only to RW images (for
1709 * the same reason 'update' applies only to RW images. It's a state of
1710 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1711 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1712 * doesn't enter 'running' state but it's still active on a flash.
1713 */
1714 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001715 /*
1716 * Region which should be write-protected in the factory (a superset of
1717 * EC_FLASH_REGION_RO)
1718 */
1719 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001720 /* Region which holds updatable (non-active) RW image */
1721 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001722 /* Number of regions */
1723 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001724};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001725/*
1726 * 'RW' is vague if there are multiple RW images; we mean the active one,
1727 * so the old constant is deprecated.
1728 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001729#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001731/**
1732 * struct ec_params_flash_region_info - Parameters for the flash region info
1733 * command.
1734 * @region: Flash region; see EC_FLASH_REGION_*
1735 */
1736struct ec_params_flash_region_info {
1737 uint32_t region;
1738} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001739
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001740struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001741 uint32_t offset;
1742 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001743} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001744
Duncan Laurie433432b2013-06-03 10:38:22 -07001745/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001746#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001747#define EC_VER_VBNV_CONTEXT 1
1748#define EC_VBNV_BLOCK_SIZE 16
1749
1750enum ec_vbnvcontext_op {
1751 EC_VBNV_CONTEXT_OP_READ,
1752 EC_VBNV_CONTEXT_OP_WRITE,
1753};
1754
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001755struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001756 uint32_t op;
1757 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001758} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001759
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001760struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001761 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001762} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001763
1764
1765/* Get SPI flash information */
1766#define EC_CMD_FLASH_SPI_INFO 0x0018
1767
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001768struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001769 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1770 uint8_t jedec[3];
1771
1772 /* Pad byte; currently always contains 0 */
1773 uint8_t reserved0;
1774
1775 /* Manufacturer / device ID from command 0x90 */
1776 uint8_t mfr_dev_id[2];
1777
1778 /* Status registers from command 0x05 and 0x35 */
1779 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001780} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001781
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001782
1783/* Select flash during flash operations */
1784#define EC_CMD_FLASH_SELECT 0x0019
1785
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001786/**
1787 * struct ec_params_flash_select - Parameters for the flash select command.
1788 * @select: 1 to select flash, 0 to deselect flash
1789 */
1790struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001791 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001792} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001793
1794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001795/**
1796 * Request random numbers to be generated and returned.
1797 * Can be used to test the random number generator is truly random.
1798 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1799 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1800 */
1801#define EC_CMD_RAND_NUM 0x001A
1802#define EC_VER_RAND_NUM 0
1803
1804struct ec_params_rand_num {
1805 uint16_t num_rand_bytes; /**< num random bytes to generate */
1806} __ec_align4;
1807
1808struct ec_response_rand_num {
1809 uint8_t rand[0]; /**< generated random numbers */
1810} __ec_align4;
1811
1812BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1813
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001814/**
1815 * Get information about the key used to sign the RW firmware.
1816 * For more details on the fields, see "struct vb21_packed_key".
1817 */
1818#define EC_CMD_RWSIG_INFO 0x001B
1819#define EC_VER_RWSIG_INFO 0
1820
1821#define VBOOT2_KEY_ID_BYTES 20
1822
1823#ifdef CHROMIUM_EC
1824/* Don't force external projects to depend on the vboot headers. */
1825#include "vb21_struct.h"
1826BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1827#endif
1828
1829struct ec_response_rwsig_info {
1830 /**
1831 * Signature algorithm used by the key
1832 * (enum vb2_signature_algorithm).
1833 */
1834 uint16_t sig_alg;
1835
1836 /**
1837 * Hash digest algorithm used with the key
1838 * (enum vb2_hash_algorithm).
1839 */
1840 uint16_t hash_alg;
1841
1842 /** Key version. */
1843 uint32_t key_version;
1844
1845 /** Key ID (struct vb2_id). */
1846 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
1847
1848 uint8_t key_is_valid;
1849
1850 /** Alignment padding. */
1851 uint8_t reserved[3];
1852} __ec_align4;
1853
1854BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
1855
1856/**
1857 * Get information about the system, such as reset flags, locked state, etc.
1858 */
1859#define EC_CMD_SYSINFO 0x001C
1860#define EC_VER_SYSINFO 0
1861
1862enum sysinfo_flags {
1863 SYSTEM_IS_LOCKED = BIT(0),
1864 SYSTEM_IS_FORCE_LOCKED = BIT(1),
1865 SYSTEM_JUMP_ENABLED = BIT(2),
1866 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
1867 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4)
1868};
1869
1870struct ec_response_sysinfo {
1871 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
1872 uint32_t current_image; /**< enum ec_current_image */
1873 uint32_t flags; /**< enum sysinfo_flags */
1874} __ec_align4;
1875
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001876/*****************************************************************************/
1877/* PWM commands */
1878
1879/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001880#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001881
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001882struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001883 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001884} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001885
1886/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001887#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001888
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001889/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001890struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001891 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001892} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001893
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001894/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001895struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001896 uint32_t rpm;
1897 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001898} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001899
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001900/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001901/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001902#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001903
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001904struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001905 uint8_t percent;
1906 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001907} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001908
1909/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001910/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001911#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001912
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001913struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001914 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001915} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001916
1917/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001918#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001919
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001920/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001921struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001922 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001923} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001924
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001925/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001926struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001927 uint32_t percent;
1928 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001929} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001930
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001931#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001932/* 16 bit duty cycle, 0xffff = 100% */
1933#define EC_PWM_MAX_DUTY 0xffff
1934
1935enum ec_pwm_type {
1936 /* All types, indexed by board-specific enum pwm_channel */
1937 EC_PWM_TYPE_GENERIC = 0,
1938 /* Keyboard backlight */
1939 EC_PWM_TYPE_KB_LIGHT,
1940 /* Display backlight */
1941 EC_PWM_TYPE_DISPLAY_LIGHT,
1942 EC_PWM_TYPE_COUNT,
1943};
1944
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001945struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001946 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1947 uint8_t pwm_type; /* ec_pwm_type */
1948 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001949} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001950
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001951#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001952
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001953struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001954 uint8_t pwm_type; /* ec_pwm_type */
1955 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001956} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001957
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001958struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001959 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001960} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001961
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001962/*****************************************************************************/
1963/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001964 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001965 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1966 * into a subcommand. We'll make separate structs for subcommands with
1967 * different input args, so that we know how much to expect.
1968 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001969#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001970
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001971struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07001972 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001973} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001974
Duncan Laurie433432b2013-06-03 10:38:22 -07001975#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001976
1977/*
1978 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07001979 * host command, but the alignment is the same regardless. Keep it that way.
1980 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001981struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001982 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001983 int32_t google_ramp_up;
1984 int32_t google_ramp_down;
1985 int32_t s3s0_ramp_up;
1986 int32_t s0_tick_delay[2]; /* AC=0/1 */
1987 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1988 int32_t s0s3_ramp_down;
1989 int32_t s3_sleep_for;
1990 int32_t s3_ramp_up;
1991 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001992
1993 /* Oscillation */
1994 uint8_t new_s0;
1995 uint8_t osc_min[2]; /* AC=0/1 */
1996 uint8_t osc_max[2]; /* AC=0/1 */
1997 uint8_t w_ofs[2]; /* AC=0/1 */
1998
1999 /* Brightness limits based on the backlight and AC. */
2000 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2001 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2002 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2003
2004 /* Battery level thresholds */
2005 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2006
2007 /* Map [AC][battery_level] to color index */
2008 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2009 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2010
2011 /* Color palette */
2012 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002013} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002014
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002015struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002016 /* Timing */
2017 int32_t google_ramp_up;
2018 int32_t google_ramp_down;
2019 int32_t s3s0_ramp_up;
2020 int32_t s0_tick_delay[2]; /* AC=0/1 */
2021 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2022 int32_t s0s3_ramp_down;
2023 int32_t s3_sleep_for;
2024 int32_t s3_ramp_up;
2025 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002026 int32_t s5_ramp_up;
2027 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002028 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002029 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002030 int32_t tap_display_time;
2031
2032 /* Tap-for-battery params */
2033 uint8_t tap_pct_red;
2034 uint8_t tap_pct_green;
2035 uint8_t tap_seg_min_on;
2036 uint8_t tap_seg_max_on;
2037 uint8_t tap_seg_osc;
2038 uint8_t tap_idx[3];
2039
2040 /* Oscillation */
2041 uint8_t osc_min[2]; /* AC=0/1 */
2042 uint8_t osc_max[2]; /* AC=0/1 */
2043 uint8_t w_ofs[2]; /* AC=0/1 */
2044
2045 /* Brightness limits based on the backlight and AC. */
2046 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2047 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2048 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2049
2050 /* Battery level thresholds */
2051 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2052
2053 /* Map [AC][battery_level] to color index */
2054 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2055 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2056
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002057 /* s5: single color pulse on inhibited power-up */
2058 uint8_t s5_idx;
2059
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002060 /* Color palette */
2061 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002062} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002063
Duncan Laurieeb316852015-12-01 18:51:18 -08002064/* Lightbar command params v2
2065 * crbug.com/467716
2066 *
2067 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2068 * logical groups to make it more manageable ( < 120 bytes).
2069 *
2070 * NOTE: Each of these groups must be less than 120 bytes.
2071 */
2072
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002073struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002074 /* Timing */
2075 int32_t google_ramp_up;
2076 int32_t google_ramp_down;
2077 int32_t s3s0_ramp_up;
2078 int32_t s0_tick_delay[2]; /* AC=0/1 */
2079 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2080 int32_t s0s3_ramp_down;
2081 int32_t s3_sleep_for;
2082 int32_t s3_ramp_up;
2083 int32_t s3_ramp_down;
2084 int32_t s5_ramp_up;
2085 int32_t s5_ramp_down;
2086 int32_t tap_tick_delay;
2087 int32_t tap_gate_delay;
2088 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002089} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002090
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002091struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002092 /* Tap-for-battery params */
2093 uint8_t tap_pct_red;
2094 uint8_t tap_pct_green;
2095 uint8_t tap_seg_min_on;
2096 uint8_t tap_seg_max_on;
2097 uint8_t tap_seg_osc;
2098 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002099} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002100
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002101struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002102 /* Oscillation */
2103 uint8_t osc_min[2]; /* AC=0/1 */
2104 uint8_t osc_max[2]; /* AC=0/1 */
2105 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002106} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002107
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002108struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002109 /* Brightness limits based on the backlight and AC. */
2110 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2111 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2112 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002113} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002114
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002115struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002116 /* Battery level thresholds */
2117 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002118} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002119
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002120struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002121 /* Map [AC][battery_level] to color index */
2122 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2123 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2124
2125 /* s5: single color pulse on inhibited power-up */
2126 uint8_t s5_idx;
2127
2128 /* Color palette */
2129 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002130} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002131
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002132/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002133#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002134struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002135 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002136 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002137} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002138
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002139struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002140 uint8_t cmd; /* Command (see enum lightbar_command) */
2141 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002142 /*
2143 * The following commands have no args:
2144 *
2145 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2146 * version, get_brightness, get_demo, suspend, resume,
2147 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2148 * get_params_v2_bright, get_params_v2_thlds,
2149 * get_params_v2_colors
2150 *
2151 * Don't use an empty struct, because C++ hates that.
2152 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002153
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002154 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002155 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002156 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002157
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002158 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002159 uint8_t ctrl, reg, value;
2160 } reg;
2161
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002162 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002163 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002164 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002165
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002166 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002167 uint8_t led;
2168 } get_rgb;
2169
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002170 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002171 uint8_t enable;
2172 } manual_suspend_ctrl;
2173
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002174 struct lightbar_params_v0 set_params_v0;
2175 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002176
2177 struct lightbar_params_v2_timing set_v2par_timing;
2178 struct lightbar_params_v2_tap set_v2par_tap;
2179 struct lightbar_params_v2_oscillation set_v2par_osc;
2180 struct lightbar_params_v2_brightness set_v2par_bright;
2181 struct lightbar_params_v2_thresholds set_v2par_thlds;
2182 struct lightbar_params_v2_colors set_v2par_colors;
2183
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002184 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002185 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002186} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002187
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002188struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002189 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002190 struct __ec_todo_unpacked {
2191 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002192 uint8_t reg;
2193 uint8_t ic0;
2194 uint8_t ic1;
2195 } vals[23];
2196 } dump;
2197
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002198 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002199 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002200 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002201
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002202 struct lightbar_params_v0 get_params_v0;
2203 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002204
Duncan Laurieeb316852015-12-01 18:51:18 -08002205
2206 struct lightbar_params_v2_timing get_params_v2_timing;
2207 struct lightbar_params_v2_tap get_params_v2_tap;
2208 struct lightbar_params_v2_oscillation get_params_v2_osc;
2209 struct lightbar_params_v2_brightness get_params_v2_bright;
2210 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2211 struct lightbar_params_v2_colors get_params_v2_colors;
2212
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002213 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002214 uint32_t num;
2215 uint32_t flags;
2216 } version;
2217
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002218 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002219 uint8_t red, green, blue;
2220 } get_rgb;
2221
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002222 /*
2223 * The following commands have no response:
2224 *
2225 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2226 * set_params_v0, set_params_v1, set_program,
2227 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2228 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2229 * set_v2par_thlds, set_v2par_colors
2230 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002231 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002232} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002233
2234/* Lightbar commands */
2235enum lightbar_command {
2236 LIGHTBAR_CMD_DUMP = 0,
2237 LIGHTBAR_CMD_OFF = 1,
2238 LIGHTBAR_CMD_ON = 2,
2239 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002240 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002241 LIGHTBAR_CMD_SEQ = 5,
2242 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002243 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002244 LIGHTBAR_CMD_GET_SEQ = 8,
2245 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002246 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2247 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002248 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002249 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2250 LIGHTBAR_CMD_GET_RGB = 14,
2251 LIGHTBAR_CMD_GET_DEMO = 15,
2252 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2253 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002254 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002255 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2256 LIGHTBAR_CMD_SUSPEND = 20,
2257 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002258 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2259 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2260 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2261 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2262 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2263 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2264 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2265 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2266 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2267 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2268 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2269 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002270 LIGHTBAR_NUM_CMDS
2271};
2272
2273/*****************************************************************************/
2274/* LED control commands */
2275
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002276#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002277
Bill Richardsone221aad2013-06-12 10:50:41 -07002278enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002279 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002280 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002281 /*
2282 * LED to indicate system power state (on or in suspend).
2283 * May be on power button or on C-panel.
2284 */
2285 EC_LED_ID_POWER_LED,
2286 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002287 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002288 /* LED to indicate left side */
2289 EC_LED_ID_LEFT_LED,
2290 /* LED to indicate right side */
2291 EC_LED_ID_RIGHT_LED,
2292 /* LED to indicate recovery mode with HW_REINIT */
2293 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2294 /* LED to indicate sysrq debug mode. */
2295 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002296
2297 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002298};
Duncan Laurie433432b2013-06-03 10:38:22 -07002299
Bill Richardsone221aad2013-06-12 10:50:41 -07002300/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002301#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2302#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002303
2304enum ec_led_colors {
2305 EC_LED_COLOR_RED = 0,
2306 EC_LED_COLOR_GREEN,
2307 EC_LED_COLOR_BLUE,
2308 EC_LED_COLOR_YELLOW,
2309 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002310 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002311
2312 EC_LED_COLOR_COUNT
2313};
2314
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002315struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002316 uint8_t led_id; /* Which LED to control */
2317 uint8_t flags; /* Control flags */
2318
2319 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002320} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002321
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002322struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002323 /*
2324 * Available brightness value range.
2325 *
2326 * Range 0 means color channel not present.
2327 * Range 1 means on/off control.
2328 * Other values means the LED is control by PWM.
2329 */
2330 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002331} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002332
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002333/*****************************************************************************/
2334/* Verified boot commands */
2335
2336/*
2337 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2338 * reused for other purposes with version > 0.
2339 */
2340
2341/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002342#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002343
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002344struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002345 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2346 uint8_t hash_type; /* enum ec_vboot_hash_type */
2347 uint8_t nonce_size; /* Nonce size; may be 0 */
2348 uint8_t reserved0; /* Reserved; set 0 */
2349 uint32_t offset; /* Offset in flash to hash */
2350 uint32_t size; /* Number of bytes to hash */
2351 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002352} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002353
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002354struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002355 uint8_t status; /* enum ec_vboot_hash_status */
2356 uint8_t hash_type; /* enum ec_vboot_hash_type */
2357 uint8_t digest_size; /* Size of hash digest in bytes */
2358 uint8_t reserved0; /* Ignore; will be 0 */
2359 uint32_t offset; /* Offset in flash which was hashed */
2360 uint32_t size; /* Number of bytes hashed */
2361 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002362} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002363
2364enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002365 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2366 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2367 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2368 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002369};
2370
2371enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002372 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002373};
2374
2375enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002376 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2377 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2378 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002379};
2380
Duncan Laurie433432b2013-06-03 10:38:22 -07002381/*
2382 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2383 * If one of these is specified, the EC will automatically update offset and
2384 * size to the correct values for the specified image (RO or RW).
2385 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002386#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2387#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2388#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2389
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002390/*
2391 * 'RW' is vague if there are multiple RW images; we mean the active one,
2392 * so the old constant is deprecated.
2393 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002394#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002395
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002396/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002397/*
2398 * Motion sense commands. We'll make separate structs for sub-commands with
2399 * different input args, so that we know how much to expect.
2400 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002401#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002402
2403/* Motion sense commands */
2404enum motionsense_command {
2405 /*
2406 * Dump command returns all motion sensor data including motion sense
2407 * module flags and individual sensor flags.
2408 */
2409 MOTIONSENSE_CMD_DUMP = 0,
2410
2411 /*
2412 * Info command returns data describing the details of a given sensor,
2413 * including enum motionsensor_type, enum motionsensor_location, and
2414 * enum motionsensor_chip.
2415 */
2416 MOTIONSENSE_CMD_INFO = 1,
2417
2418 /*
2419 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002420 * in milliseconds.
2421 * It is per sensor, the EC run sample task at the minimum of all
2422 * sensors EC_RATE.
2423 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2424 * to collect all the sensor samples.
2425 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2426 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002427 */
2428 MOTIONSENSE_CMD_EC_RATE = 2,
2429
2430 /*
2431 * Sensor ODR command is a setter/getter command for the output data
2432 * rate of a specific motion sensor in millihertz.
2433 */
2434 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2435
2436 /*
2437 * Sensor range command is a setter/getter command for the range of
2438 * a specified motion sensor in +/-G's or +/- deg/s.
2439 */
2440 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2441
2442 /*
2443 * Setter/getter command for the keyboard wake angle. When the lid
2444 * angle is greater than this value, keyboard wake is disabled in S3,
2445 * and when the lid angle goes less than this value, keyboard wake is
2446 * enabled. Note, the lid angle measurement is an approximate,
2447 * un-calibrated value, hence the wake angle isn't exact.
2448 */
2449 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2450
Duncan Laurieeb316852015-12-01 18:51:18 -08002451 /*
2452 * Returns a single sensor data.
2453 */
2454 MOTIONSENSE_CMD_DATA = 6,
2455
2456 /*
2457 * Return sensor fifo info.
2458 */
2459 MOTIONSENSE_CMD_FIFO_INFO = 7,
2460
2461 /*
2462 * Insert a flush element in the fifo and return sensor fifo info.
2463 * The host can use that element to synchronize its operation.
2464 */
2465 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2466
2467 /*
2468 * Return a portion of the fifo.
2469 */
2470 MOTIONSENSE_CMD_FIFO_READ = 9,
2471
2472 /*
2473 * Perform low level calibration.
2474 * On sensors that support it, ask to do offset calibration.
2475 */
2476 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2477
2478 /*
2479 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002480 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002481 * The offsets can be calculated by the host, or via
2482 * PERFORM_CALIB command.
2483 */
2484 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2485
2486 /*
2487 * List available activities for a MOTION sensor.
2488 * Indicates if they are enabled or disabled.
2489 */
2490 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2491
2492 /*
2493 * Activity management
2494 * Enable/Disable activity recognition.
2495 */
2496 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2497
2498 /*
2499 * Lid Angle
2500 */
2501 MOTIONSENSE_CMD_LID_ANGLE = 14,
2502
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002503 /*
2504 * Allow the FIFO to trigger interrupt via MKBP events.
2505 * By default the FIFO does not send interrupt to process the FIFO
2506 * until the AP is ready or it is coming from a wakeup sensor.
2507 */
2508 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2509
2510 /*
2511 * Spoof the readings of the sensors. The spoofed readings can be set
2512 * to arbitrary values, or will lock to the last read actual values.
2513 */
2514 MOTIONSENSE_CMD_SPOOF = 16,
2515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002516 /* Set lid angle for tablet mode detection. */
2517 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2518
2519 /*
2520 * Sensor Scale command is a setter/getter command for the calibration
2521 * scale.
2522 */
2523 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2524
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002525 /*
2526 * Read the current online calibration values (if available).
2527 */
2528 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2529
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002530 /* Number of motionsense sub-commands. */
2531 MOTIONSENSE_NUM_CMDS
2532};
2533
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002534/* List of motion sensor types. */
2535enum motionsensor_type {
2536 MOTIONSENSE_TYPE_ACCEL = 0,
2537 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002538 MOTIONSENSE_TYPE_MAG = 2,
2539 MOTIONSENSE_TYPE_PROX = 3,
2540 MOTIONSENSE_TYPE_LIGHT = 4,
2541 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002542 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002543 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002544 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002545 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002546};
2547
2548/* List of motion sensor locations. */
2549enum motionsensor_location {
2550 MOTIONSENSE_LOC_BASE = 0,
2551 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002552 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002553 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002554};
2555
2556/* List of motion sensor chips. */
2557enum motionsensor_chip {
2558 MOTIONSENSE_CHIP_KXCJ9 = 0,
2559 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002560 MOTIONSENSE_CHIP_BMI160 = 2,
2561 MOTIONSENSE_CHIP_SI1141 = 3,
2562 MOTIONSENSE_CHIP_SI1142 = 4,
2563 MOTIONSENSE_CHIP_SI1143 = 5,
2564 MOTIONSENSE_CHIP_KX022 = 6,
2565 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002566 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002567 MOTIONSENSE_CHIP_BMP280 = 9,
2568 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002569 MOTIONSENSE_CHIP_BH1730 = 11,
2570 MOTIONSENSE_CHIP_GPIO = 12,
2571 MOTIONSENSE_CHIP_LIS2DH = 13,
2572 MOTIONSENSE_CHIP_LSM6DSM = 14,
2573 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002574 MOTIONSENSE_CHIP_LIS2MDL = 16,
2575 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2576 MOTIONSENSE_CHIP_LSM6DSO = 18,
2577 MOTIONSENSE_CHIP_LNG2DM = 19,
2578 MOTIONSENSE_CHIP_TCS3400 = 20,
2579 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2580 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002581 MOTIONSENSE_CHIP_LIS2DS = 23,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002582 MOTIONSENSE_CHIP_MAX,
2583};
2584
2585/* List of orientation positions */
2586enum motionsensor_orientation {
2587 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2588 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2589 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2590 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2591 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002592};
2593
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002594struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002595 /* Flags for each sensor. */
2596 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002597 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002598 uint8_t sensor_num;
2599 /* Each sensor is up to 3-axis. */
2600 union {
2601 int16_t data[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002602 struct __ec_todo_packed {
2603 uint16_t reserved;
Duncan Laurieeb316852015-12-01 18:51:18 -08002604 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002605 };
2606 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002607 uint8_t activity; /* motionsensor_activity */
2608 uint8_t state;
2609 int16_t add_info[2];
2610 };
2611 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002612} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002613
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002614/* Response to AP reporting calibration data for a given sensor. */
2615struct ec_response_online_calibration_data {
2616 /** The calibration values. */
2617 int16_t data[3];
2618};
2619
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002620/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002621struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002622 /* Size of the fifo */
2623 uint16_t size;
2624 /* Amount of space used in the fifo */
2625 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002626 /* Timestamp recorded in us.
2627 * aka accurate timestamp when host event was triggered.
2628 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002629 uint32_t timestamp;
2630 /* Total amount of vector lost */
2631 uint16_t total_lost;
2632 /* Lost events since the last fifo_info, per sensors */
2633 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002634} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002635
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002636struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002637 uint32_t number_data;
2638 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002639} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002640
2641/* List supported activity recognition */
2642enum motionsensor_activity {
2643 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2644 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2645 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002646 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Duncan Laurieeb316852015-12-01 18:51:18 -08002647};
2648
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002649struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002650 uint8_t sensor_num;
2651 uint8_t activity; /* one of enum motionsensor_activity */
2652 uint8_t enable; /* 1: enable, 0: disable */
2653 uint8_t reserved;
2654 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002655} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002656
2657/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002658#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002659
2660/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002661#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002662
2663/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002664 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002665 * data contains time stamp
2666 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002667#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2668#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2669#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2670#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2671#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002672
2673/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002674 * Send this value for the data element to only perform a read. If you
2675 * send any other value, the EC will interpret it as data to set and will
2676 * return the actual value set.
2677 */
2678#define EC_MOTION_SENSE_NO_VALUE -1
2679
Duncan Laurieeb316852015-12-01 18:51:18 -08002680#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2681
2682/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2683/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002684#define MOTION_SENSE_SET_OFFSET BIT(0)
2685
2686/* Default Scale value, factor 1. */
2687#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002688
2689#define LID_ANGLE_UNRELIABLE 500
2690
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002691enum motionsense_spoof_mode {
2692 /* Disable spoof mode. */
2693 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2694
2695 /* Enable spoof mode, but use provided component values. */
2696 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2697
2698 /* Enable spoof mode, but use the current sensor values. */
2699 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2700
2701 /* Query the current spoof mode status for the sensor. */
2702 MOTIONSENSE_SPOOF_MODE_QUERY,
2703};
2704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002705struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002706 uint8_t cmd;
2707 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002708 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002709 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002710 /*
2711 * Maximal number of sensor the host is expecting.
2712 * 0 means the host is only interested in the number
2713 * of sensors controlled by the EC.
2714 */
2715 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002716 } dump;
2717
2718 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002719 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002720 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002721 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002722 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2723 * kb_wake_angle: angle to wakup AP.
2724 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002725 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002726 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002727
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002728 /*
2729 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2730 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002731 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002732 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002733 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002734
2735 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002736 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2737 * Allow entering/exiting the calibration mode.
2738 */
2739 struct __ec_todo_unpacked {
2740 uint8_t sensor_num;
2741 uint8_t enable;
2742 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002743
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002744 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002745 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2746 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002747 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002748 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002749 uint8_t sensor_num;
2750
2751 /* Rounding flag, true for round-up, false for down. */
2752 uint8_t roundup;
2753
2754 uint16_t reserved;
2755
2756 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2757 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002758 } ec_rate, sensor_odr, sensor_range;
2759
2760 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002761 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002762 uint8_t sensor_num;
2763
2764 /*
2765 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2766 * the calibration information in the EC.
2767 * If unset, just retrieve calibration information.
2768 */
2769 uint16_t flags;
2770
2771 /*
2772 * Temperature at calibration, in units of 0.01 C
2773 * 0x8000: invalid / unknown.
2774 * 0x0: 0C
2775 * 0x7fff: +327.67C
2776 */
2777 int16_t temp;
2778
2779 /*
2780 * Offset for calibration.
2781 * Unit:
2782 * Accelerometer: 1/1024 g
2783 * Gyro: 1/1024 deg/s
2784 * Compass: 1/16 uT
2785 */
2786 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002787 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002788
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002789 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2790 struct __ec_todo_packed {
2791 uint8_t sensor_num;
2792
2793 /*
2794 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2795 * the calibration information in the EC.
2796 * If unset, just retrieve calibration information.
2797 */
2798 uint16_t flags;
2799
2800 /*
2801 * Temperature at calibration, in units of 0.01 C
2802 * 0x8000: invalid / unknown.
2803 * 0x0: 0C
2804 * 0x7fff: +327.67C
2805 */
2806 int16_t temp;
2807
2808 /*
2809 * Scale for calibration:
2810 * By default scale is 1, it is encoded on 16bits:
2811 * 1 = BIT(15)
2812 * ~2 = 0xFFFF
2813 * ~0 = 0.
2814 */
2815 uint16_t scale[3];
2816 } sensor_scale;
2817
2818
Duncan Laurieeb316852015-12-01 18:51:18 -08002819 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002820 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002821
2822 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002823 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002824 /*
2825 * Number of expected vector to return.
2826 * EC may return less or 0 if none available.
2827 */
2828 uint32_t max_data_vector;
2829 } fifo_read;
2830
2831 struct ec_motion_sense_activity set_activity;
2832
2833 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002834 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002835
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002836 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2837 struct __ec_todo_unpacked {
2838 /*
2839 * 1: enable, 0 disable fifo,
2840 * EC_MOTION_SENSE_NO_VALUE return value.
2841 */
2842 int8_t enable;
2843 } fifo_int_enable;
2844
2845 /* Used for MOTIONSENSE_CMD_SPOOF */
2846 struct __ec_todo_packed {
2847 uint8_t sensor_id;
2848
2849 /* See enum motionsense_spoof_mode. */
2850 uint8_t spoof_enable;
2851
2852 /* Ignored, used for alignment. */
2853 uint8_t reserved;
2854
2855 /* Individual component values to spoof. */
2856 int16_t components[3];
2857 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002859 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2860 struct __ec_todo_unpacked {
2861 /*
2862 * Lid angle threshold for switching between tablet and
2863 * clamshell mode.
2864 */
2865 int16_t lid_angle;
2866
2867 /*
2868 * Hysteresis degree to prevent fluctuations between
2869 * clamshell and tablet mode if lid angle keeps
2870 * changing around the threshold. Lid motion driver will
2871 * use lid_angle + hys_degree to trigger tablet mode and
2872 * lid_angle - hys_degree to trigger clamshell mode.
2873 */
2874 int16_t hys_degree;
2875 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002876
2877 /*
2878 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
2879 * Allow reading a single sensor's online calibration value.
2880 */
2881 struct __ec_todo_unpacked {
2882 uint8_t sensor_num;
2883 } online_calib_read;
2884
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002885 };
2886} __ec_todo_packed;
2887
Jett Rinkba2edaf2020-01-14 11:49:06 -07002888enum motion_sense_cmd_info_flags {
2889 /* The sensor supports online calibration */
2890 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
2891};
2892
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002893struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002894 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002895 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002896 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002897 /* Flags representing the motion sensor module. */
2898 uint8_t module_flags;
2899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002900 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002901 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002902
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002903 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002904 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002905 * for holding all the data.
2906 */
2907 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002908 } dump;
2909
2910 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002911 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002912 /* Should be element of enum motionsensor_type. */
2913 uint8_t type;
2914
2915 /* Should be element of enum motionsensor_location. */
2916 uint8_t location;
2917
2918 /* Should be element of enum motionsensor_chip. */
2919 uint8_t chip;
2920 } info;
2921
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002922 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2923 struct __ec_todo_unpacked {
2924 /* Should be element of enum motionsensor_type. */
2925 uint8_t type;
2926
2927 /* Should be element of enum motionsensor_location. */
2928 uint8_t location;
2929
2930 /* Should be element of enum motionsensor_chip. */
2931 uint8_t chip;
2932
2933 /* Minimum sensor sampling frequency */
2934 uint32_t min_frequency;
2935
2936 /* Maximum sensor sampling frequency */
2937 uint32_t max_frequency;
2938
2939 /* Max number of sensor events that could be in fifo */
2940 uint32_t fifo_max_event_count;
2941 } info_3;
2942
Jett Rinkba2edaf2020-01-14 11:49:06 -07002943 /* Used for MOTIONSENSE_CMD_INFO version 4 */
2944 struct __ec_align4 {
2945 /* Should be element of enum motionsensor_type. */
2946 uint8_t type;
2947
2948 /* Should be element of enum motionsensor_location. */
2949 uint8_t location;
2950
2951 /* Should be element of enum motionsensor_chip. */
2952 uint8_t chip;
2953
2954 /* Minimum sensor sampling frequency */
2955 uint32_t min_frequency;
2956
2957 /* Maximum sensor sampling frequency */
2958 uint32_t max_frequency;
2959
2960 /* Max number of sensor events that could be in fifo */
2961 uint32_t fifo_max_event_count;
2962
2963 /*
2964 * Should be elements of
2965 * enum motion_sense_cmd_info_flags
2966 */
2967 uint32_t flags;
2968 } info_4;
2969
Duncan Laurieeb316852015-12-01 18:51:18 -08002970 /* Used for MOTIONSENSE_CMD_DATA */
2971 struct ec_response_motion_sensor_data data;
2972
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002973 /*
2974 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002975 * MOTIONSENSE_CMD_SENSOR_RANGE,
2976 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2977 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2978 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002979 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002980 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002981 /* Current value of the parameter queried. */
2982 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002983 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2984 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08002985
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002986 /*
2987 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
2988 * PERFORM_CALIB.
2989 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002990 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002991 int16_t temp;
2992 int16_t offset[3];
2993 } sensor_offset, perform_calib;
2994
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002995 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2996 struct __ec_todo_unpacked {
2997 int16_t temp;
2998 uint16_t scale[3];
2999 } sensor_scale;
3000
Duncan Laurieeb316852015-12-01 18:51:18 -08003001 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3002
3003 struct ec_response_motion_sense_fifo_data fifo_read;
3004
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003005 struct ec_response_online_calibration_data online_calib_read;
3006
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003007 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003008 uint16_t reserved;
3009 uint32_t enabled;
3010 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003011 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003012
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003013 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003014
Duncan Laurieeb316852015-12-01 18:51:18 -08003015 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003016 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003017 /*
3018 * Angle between 0 and 360 degree if available,
3019 * LID_ANGLE_UNRELIABLE otherwise.
3020 */
3021 uint16_t value;
3022 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003023
3024 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3025 struct __ec_todo_unpacked {
3026 /*
3027 * Lid angle threshold for switching between tablet and
3028 * clamshell mode.
3029 */
3030 uint16_t lid_angle;
3031
3032 /* Hysteresis degree. */
3033 uint16_t hys_degree;
3034 } tablet_mode_threshold;
3035
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003036 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003037} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003038
3039/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003040/* Force lid open command */
3041
3042/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003043#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003044
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003045struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003046 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003047} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003048
3049/*****************************************************************************/
3050/* Configure the behavior of the power button */
3051#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3052
3053enum ec_config_power_button_flags {
3054 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003055 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003056};
3057
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003058struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003059 /* See enum ec_config_power_button_flags */
3060 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003061} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003062
3063/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003064/* USB charging control commands */
3065
3066/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003067#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003068
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003069enum usb_charge_mode {
3070 /* Disable USB port. */
3071 USB_CHARGE_MODE_DISABLED,
3072 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3073 USB_CHARGE_MODE_SDP2,
3074 /* Set USB port to Charging Downstream Port, BC 1.2. */
3075 USB_CHARGE_MODE_CDP,
3076 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3077 USB_CHARGE_MODE_DCP_SHORT,
3078 /* Enable USB port (for dumb ports). */
3079 USB_CHARGE_MODE_ENABLED,
3080 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3081 USB_CHARGE_MODE_DEFAULT,
3082
3083 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003084};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003085
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003086enum usb_suspend_charge {
3087 /* Enable charging in suspend */
3088 USB_ALLOW_SUSPEND_CHARGE,
3089 /* Disable charging in suspend */
3090 USB_DISALLOW_SUSPEND_CHARGE
3091};
3092
3093struct ec_params_usb_charge_set_mode {
3094 uint8_t usb_port_id;
3095 uint8_t mode:7; /* enum usb_charge_mode */
3096 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
3097} __ec_align1;
3098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003099/*****************************************************************************/
3100/* Persistent storage for host */
3101
3102/* Maximum bytes that can be read/written in a single command */
3103#define EC_PSTORE_SIZE_MAX 64
3104
3105/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003106#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003107
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003108struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003109 /* Persistent storage size, in bytes */
3110 uint32_t pstore_size;
3111 /* Access size; read/write offset and size must be a multiple of this */
3112 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003113} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003114
3115/*
3116 * Read persistent storage
3117 *
3118 * Response is params.size bytes of data.
3119 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003120#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003121
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003122struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003123 uint32_t offset; /* Byte offset to read */
3124 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003125} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003126
3127/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003128#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003129
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003130struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003131 uint32_t offset; /* Byte offset to write */
3132 uint32_t size; /* Size to write in bytes */
3133 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003134} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003135
3136/*****************************************************************************/
3137/* Real-time clock */
3138
3139/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003140struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003141 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003142} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003143
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003144struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003145 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003146} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003147
3148/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003149#define EC_CMD_RTC_GET_VALUE 0x0044
3150#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003151
3152/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003153#define EC_CMD_RTC_SET_VALUE 0x0046
3154#define EC_CMD_RTC_SET_ALARM 0x0047
3155
3156/* Pass as time param to SET_ALARM to clear the current alarm */
3157#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003158
3159/*****************************************************************************/
3160/* Port80 log access */
3161
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003162/* Maximum entries that can be read/written in a single command */
3163#define EC_PORT80_SIZE_MAX 32
3164
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003165/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003166#define EC_CMD_PORT80_LAST_BOOT 0x0048
3167#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003168
3169enum ec_port80_subcmd {
3170 EC_PORT80_GET_INFO = 0,
3171 EC_PORT80_READ_BUFFER,
3172};
3173
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003174struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003175 uint16_t subcmd;
3176 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003177 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003178 uint32_t offset;
3179 uint32_t num_entries;
3180 } read_buffer;
3181 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003182} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003183
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003184struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003185 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003186 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003187 uint32_t writes;
3188 uint32_t history_size;
3189 uint32_t last_boot;
3190 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003191 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003192 uint16_t codes[EC_PORT80_SIZE_MAX];
3193 } data;
3194 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003195} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003196
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003197struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003198 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003199} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003200
3201/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003202/* Temporary secure storage for host verified boot use */
3203
3204/* Number of bytes in a vstore slot */
3205#define EC_VSTORE_SLOT_SIZE 64
3206
3207/* Maximum number of vstore slots */
3208#define EC_VSTORE_SLOT_MAX 32
3209
3210/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003211#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003212struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003213 /* Indicates which slots are locked */
3214 uint32_t slot_locked;
3215 /* Total number of slots available */
3216 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003217} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003218
3219/*
3220 * Read temporary secure storage
3221 *
3222 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3223 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003224#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003225
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003226struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003227 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003228} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003229
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003230struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003231 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003232} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003233
3234/*
3235 * Write temporary secure storage and lock it.
3236 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003237#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003238
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003239struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003240 uint8_t slot; /* Slot to write to */
3241 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003242} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003243
3244/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003245/* Thermal engine commands. Note that there are two implementations. We'll
3246 * reuse the command number, but the data and behavior is incompatible.
3247 * Version 0 is what originally shipped on Link.
3248 * Version 1 separates the CPU thermal limits from the fan control.
3249 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003250
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003251#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3252#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003253
Duncan Laurie93e24442014-01-06 12:30:52 -08003254/* The version 0 structs are opaque. You have to know what they are for
3255 * the get/set commands to make any sense.
3256 */
3257
3258/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003259struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003260 uint8_t sensor_type;
3261 uint8_t threshold_id;
3262 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003263} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003264
Duncan Laurie93e24442014-01-06 12:30:52 -08003265/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003266struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003267 uint8_t sensor_type;
3268 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003269} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003270
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003271struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003272 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003273} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003274
Duncan Laurie93e24442014-01-06 12:30:52 -08003275
3276/* The version 1 structs are visible. */
3277enum ec_temp_thresholds {
3278 EC_TEMP_THRESH_WARN = 0,
3279 EC_TEMP_THRESH_HIGH,
3280 EC_TEMP_THRESH_HALT,
3281
3282 EC_TEMP_THRESH_COUNT
3283};
3284
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003285/*
3286 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003287 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003288 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003289 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3290 * hysteresis.
3291 * For example,
3292 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3293 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3294 * EC will throttle ap when temperature >= 301 K, and release throttling when
3295 * temperature <= 299 K.
3296 *
3297 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3298 * For example,
3299 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3300 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3301 * EC will throttle ap when temperature >= 301 K, and release throttling when
3302 * temperature <= 294 K.
3303 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003304 * Note that this structure is a sub-structure of
3305 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003306 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003307struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003308 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003309 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003310 uint32_t temp_fan_off; /* no active cooling needed */
3311 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003312} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003313
3314/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003315struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003316 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003317} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003318/* This returns a struct ec_thermal_config */
3319
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003320/*
3321 * Version 1 - set config for one sensor.
3322 * Use read-modify-write for best results!
3323 */
3324struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003325 uint32_t sensor_num;
3326 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003327} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003328/* This returns no data */
3329
3330/****************************************************************************/
3331
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003332/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003333#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003334
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003335/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003336struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003337 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003338} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003339
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003340/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003341#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3342#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003343
3344/*
3345 * The original TMP006 calibration only needed four params, but now we need
3346 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3347 * the params opaque. The v1 "get" response will include the algorithm number
3348 * and how many params it requires. That way we can change the EC code without
3349 * needing to update this file. We can also use a different algorithm on each
3350 * sensor.
3351 */
3352
3353/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003354struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003355 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003356} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003357
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003358/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003359struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003360 float s0;
3361 float b0;
3362 float b1;
3363 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003364} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003365
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003366struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003367 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003368 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003369 float s0;
3370 float b0;
3371 float b1;
3372 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003373} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003374
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003375/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003376struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003377 uint8_t algorithm;
3378 uint8_t num_params;
3379 uint8_t reserved[2];
3380 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003381} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003382
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003383struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003384 uint8_t index;
3385 uint8_t algorithm;
3386 uint8_t num_params;
3387 uint8_t reserved;
3388 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003389} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003390
3391
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003392/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003393#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003394
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003395struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003396 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003397} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003398
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003399struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003400 int32_t t; /* In 1/100 K */
3401 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003402} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003403
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003404/*****************************************************************************/
3405/* MKBP - Matrix KeyBoard Protocol */
3406
3407/*
3408 * Read key state
3409 *
3410 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3411 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003412 *
3413 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3414 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3415 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003416 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003417#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003418
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003419/*
3420 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3421 */
3422#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003423
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003424struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003425 uint32_t rows;
3426 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003427 /* Formerly "switches", which was 0. */
3428 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003429} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003430
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003431struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003432 uint8_t info_type;
3433 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003434} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003435
3436enum ec_mkbp_info_type {
3437 /*
3438 * Info about the keyboard matrix: number of rows and columns.
3439 *
3440 * Returns struct ec_response_mkbp_info.
3441 */
3442 EC_MKBP_INFO_KBD = 0,
3443
3444 /*
3445 * For buttons and switches, info about which specifically are
3446 * supported. event_type must be set to one of the values in enum
3447 * ec_mkbp_event.
3448 *
3449 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3450 * bitmask indicating which buttons or switches are present. See the
3451 * bit inidices below.
3452 */
3453 EC_MKBP_INFO_SUPPORTED = 1,
3454
3455 /*
3456 * Instantaneous state of buttons and switches.
3457 *
3458 * event_type must be set to one of the values in enum ec_mkbp_event.
3459 *
3460 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3461 * indicating the current state of the keyboard matrix.
3462 *
3463 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3464 * event state.
3465 *
3466 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3467 * state of supported buttons.
3468 *
3469 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3470 * state of supported switches.
3471 */
3472 EC_MKBP_INFO_CURRENT = 2,
3473};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003474
3475/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003476#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003477
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003478struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003479 uint8_t col;
3480 uint8_t row;
3481 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003482} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003483
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003484#define EC_CMD_GET_KEYBOARD_ID 0x0063
3485
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003486struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003487 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003488} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003489
3490enum keyboard_id {
3491 KEYBOARD_ID_UNSUPPORTED = 0,
3492 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3493};
3494
Duncan Laurie433432b2013-06-03 10:38:22 -07003495/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003496#define EC_CMD_MKBP_SET_CONFIG 0x0064
3497#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003498
3499/* flags */
3500enum mkbp_config_flags {
3501 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3502};
3503
3504enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003505 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3506 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3507 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3508 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3509 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3510 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3511 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003512};
3513
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003514/*
3515 * Configuration for our key scanning algorithm.
3516 *
3517 * Note that this is used as a sub-structure of
3518 * ec_{params/response}_mkbp_get_config.
3519 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003520struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003521 uint32_t valid_mask; /* valid fields */
3522 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3523 uint8_t valid_flags; /* which flags are valid */
3524 uint16_t scan_period_us; /* period between start of scans */
3525 /* revert to interrupt mode after no activity for this long */
3526 uint32_t poll_timeout_us;
3527 /*
3528 * minimum post-scan relax time. Once we finish a scan we check
3529 * the time until we are due to start the next one. If this time is
3530 * shorter this field, we use this instead.
3531 */
3532 uint16_t min_post_scan_delay_us;
3533 /* delay between setting up output and waiting for it to settle */
3534 uint16_t output_settle_us;
3535 uint16_t debounce_down_us; /* time for debounce on key down */
3536 uint16_t debounce_up_us; /* time for debounce on key up */
3537 /* maximum depth to allow for fifo (0 = no keyscan output) */
3538 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003539} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003541struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003542 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003543} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003544
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003545struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003546 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003547} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003548
3549/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003550#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003551
3552enum ec_keyscan_seq_cmd {
3553 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3554 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3555 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3556 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3557 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3558};
3559
3560enum ec_collect_flags {
3561 /*
3562 * Indicates this scan was processed by the EC. Due to timing, some
3563 * scans may be skipped.
3564 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003565 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003566};
3567
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003568struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003569 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003570} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003571
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003572struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003573 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3574 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003575 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003576 uint8_t active; /* still active */
3577 uint8_t num_items; /* number of items */
3578 /* Current item being presented */
3579 uint8_t cur_item;
3580 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003581 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003582 /*
3583 * Absolute time for this scan, measured from the
3584 * start of the sequence.
3585 */
3586 uint32_t time_us;
3587 uint8_t scan[0]; /* keyscan data */
3588 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003589 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003590 uint8_t start_item; /* First item to return */
3591 uint8_t num_items; /* Number of items to return */
3592 } collect;
3593 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003594} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003595
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003596struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003597 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003598 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003599 uint8_t num_items; /* Number of items */
3600 /* Data for each item */
3601 struct ec_collect_item item[0];
3602 } collect;
3603 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003604} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003605
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003606/*
3607 * Get the next pending MKBP event.
3608 *
3609 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3610 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003611#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003612
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003613#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3614
3615/*
3616 * We use the most significant bit of the event type to indicate to the host
3617 * that the EC has more MKBP events available to provide.
3618 */
3619#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3620
3621/* The mask to apply to get the raw event type */
3622#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3623
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003624enum ec_mkbp_event {
3625 /* Keyboard matrix changed. The event data is the new matrix state. */
3626 EC_MKBP_EVENT_KEY_MATRIX = 0,
3627
3628 /* New host event. The event data is 4 bytes of host event flags. */
3629 EC_MKBP_EVENT_HOST_EVENT = 1,
3630
Duncan Laurieeb316852015-12-01 18:51:18 -08003631 /* New Sensor FIFO data. The event data is fifo_info structure. */
3632 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3633
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003634 /* The state of the non-matrixed buttons have changed. */
3635 EC_MKBP_EVENT_BUTTON = 3,
3636
3637 /* The state of the switches have changed. */
3638 EC_MKBP_EVENT_SWITCH = 4,
3639
3640 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3641 EC_MKBP_EVENT_FINGERPRINT = 5,
3642
3643 /*
3644 * Sysrq event: send emulated sysrq. The event data is sysrq,
3645 * corresponding to the key to be pressed.
3646 */
3647 EC_MKBP_EVENT_SYSRQ = 6,
3648
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003649 /*
3650 * New 64-bit host event.
3651 * The event data is 8 bytes of host event flags.
3652 */
3653 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3654
3655 /* Notify the AP that something happened on CEC */
3656 EC_MKBP_EVENT_CEC_EVENT = 8,
3657
3658 /* Send an incoming CEC message to the AP */
3659 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3660
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003661 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3662 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3663
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003664 /* New online calibration values are available. */
3665 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3666
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003667 /* Number of MKBP events */
3668 EC_MKBP_EVENT_COUNT,
3669};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003670BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003671
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003672union __ec_align_offset1 ec_response_get_next_data {
3673 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003674
3675 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003676 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003677 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003678
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003679 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003680 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003681 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003682 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003683 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003684
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003685 uint32_t buttons;
3686
3687 uint32_t switches;
3688
3689 uint32_t fp_events;
3690
3691 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003692
3693 /* CEC events from enum mkbp_cec_event */
3694 uint32_t cec_events;
3695};
3696
3697union __ec_align_offset1 ec_response_get_next_data_v1 {
3698 uint8_t key_matrix[16];
3699
3700 /* Unaligned */
3701 uint32_t host_event;
3702 uint64_t host_event64;
3703
3704 struct __ec_todo_unpacked {
3705 /* For aligning the fifo_info */
3706 uint8_t reserved[3];
3707 struct ec_response_motion_sense_fifo_info info;
3708 } sensor_fifo;
3709
3710 uint32_t buttons;
3711
3712 uint32_t switches;
3713
3714 uint32_t fp_events;
3715
3716 uint32_t sysrq;
3717
3718 /* CEC events from enum mkbp_cec_event */
3719 uint32_t cec_events;
3720
3721 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003722};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003723BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003724
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003725struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003726 uint8_t event_type;
3727 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003728 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003729} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003731struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003732 uint8_t event_type;
3733 /* Followed by event data if any */
3734 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003735} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003736
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003737/* Bit indices for buttons and switches.*/
3738/* Buttons */
3739#define EC_MKBP_POWER_BUTTON 0
3740#define EC_MKBP_VOL_UP 1
3741#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003742#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003743
3744/* Switches */
3745#define EC_MKBP_LID_OPEN 0
3746#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003747#define EC_MKBP_BASE_ATTACHED 2
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003748
Gwendal Grignou880b4582016-06-20 08:49:25 -07003749/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003750#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003751
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003752struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003753 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003754} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003755
3756/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3757#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003758#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3759#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3760#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3761 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3762#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3763#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3764#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3765 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003766#define EC_MKBP_FP_ENROLL BIT(27)
3767#define EC_MKBP_FP_MATCH BIT(28)
3768#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3769#define EC_MKBP_FP_FINGER_UP BIT(30)
3770#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003771/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3772#define EC_MKBP_FP_ERR_ENROLL_OK 0
3773#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3774#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3775#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3776#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3777/* Can be used to detect if image was usable for enrollment or not. */
3778#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3779/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3780#define EC_MKBP_FP_ERR_MATCH_NO 0
3781#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003782#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003783#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3784#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3785#define EC_MKBP_FP_ERR_MATCH_YES 1
3786#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3787#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3788
Gwendal Grignou880b4582016-06-20 08:49:25 -07003789
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003790#define EC_CMD_MKBP_WAKE_MASK 0x0069
3791enum ec_mkbp_event_mask_action {
3792 /* Retrieve the value of a wake mask. */
3793 GET_WAKE_MASK = 0,
3794
3795 /* Set the value of a wake mask. */
3796 SET_WAKE_MASK,
3797};
3798
3799enum ec_mkbp_mask_type {
3800 /*
3801 * These are host events sent via MKBP.
3802 *
3803 * Some examples are:
3804 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3805 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3806 *
3807 * The only things that should be in this mask are:
3808 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3809 */
3810 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3811
3812 /*
3813 * These are MKBP events. Some examples are:
3814 *
3815 * EC_MKBP_EVENT_KEY_MATRIX
3816 * EC_MKBP_EVENT_SWITCH
3817 *
3818 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3819 */
3820 EC_MKBP_EVENT_WAKE_MASK,
3821};
3822
3823struct ec_params_mkbp_event_wake_mask {
3824 /* One of enum ec_mkbp_event_mask_action */
3825 uint8_t action;
3826
3827 /*
3828 * Which MKBP mask are you interested in acting upon? This is one of
3829 * ec_mkbp_mask_type.
3830 */
3831 uint8_t mask_type;
3832
3833 /* If setting a new wake mask, this contains the mask to set. */
3834 uint32_t new_wake_mask;
3835};
3836
3837struct ec_response_mkbp_event_wake_mask {
3838 uint32_t wake_mask;
3839};
3840
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003841/*****************************************************************************/
3842/* Temperature sensor commands */
3843
3844/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003845#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003846
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003847struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003848 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003849} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003850
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003851struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003852 char sensor_name[32];
3853 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003854} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003855
3856/*****************************************************************************/
3857
3858/*
3859 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3860 * commands accidentally sent to the wrong interface. See the ACPI section
3861 * below.
3862 */
3863
3864/*****************************************************************************/
3865/* Host event commands */
3866
Jenny TC1dfc2c32017-12-14 14:24:39 +05303867
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003868/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003869/*
3870 * Host event mask params and response structures, shared by all of the host
3871 * event commands below.
3872 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003873struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003874 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003875} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003876
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003877struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003878 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003879} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003880
3881/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003882#define EC_CMD_HOST_EVENT_GET_B 0x0087
3883#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3884#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3885#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003886
3887/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003888#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3889#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3890#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3891#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3892#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003893
Jenny TC1dfc2c32017-12-14 14:24:39 +05303894/*
3895 * Unified host event programming interface - Should be used by newer versions
3896 * of BIOS/OS to program host events and masks
3897 */
3898
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003899struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303900
3901 /* Action requested by host - one of enum ec_host_event_action. */
3902 uint8_t action;
3903
3904 /*
3905 * Mask type that the host requested the action on - one of
3906 * enum ec_host_event_mask_type.
3907 */
3908 uint8_t mask_type;
3909
3910 /* Set to 0, ignore on read */
3911 uint16_t reserved;
3912
3913 /* Value to be used in case of set operations. */
3914 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003915} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303916
3917/*
3918 * Response structure returned by EC_CMD_HOST_EVENT.
3919 * Update the value on a GET request. Set to 0 on GET/CLEAR
3920 */
3921
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003922struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303923
3924 /* Mask value in case of get operation */
3925 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003926} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303927
3928enum ec_host_event_action {
3929 /*
3930 * params.value is ignored. Value of mask_type populated
3931 * in response.value
3932 */
3933 EC_HOST_EVENT_GET,
3934
3935 /* Bits in params.value are set */
3936 EC_HOST_EVENT_SET,
3937
3938 /* Bits in params.value are cleared */
3939 EC_HOST_EVENT_CLEAR,
3940};
3941
3942enum ec_host_event_mask_type {
3943
3944 /* Main host event copy */
3945 EC_HOST_EVENT_MAIN,
3946
3947 /* Copy B of host events */
3948 EC_HOST_EVENT_B,
3949
3950 /* SCI Mask */
3951 EC_HOST_EVENT_SCI_MASK,
3952
3953 /* SMI Mask */
3954 EC_HOST_EVENT_SMI_MASK,
3955
3956 /* Mask of events that should be always reported in hostevents */
3957 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3958
3959 /* Active wake mask */
3960 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3961
3962 /* Lazy wake mask for S0ix */
3963 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3964
3965 /* Lazy wake mask for S3 */
3966 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3967
3968 /* Lazy wake mask for S5 */
3969 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3970};
3971
3972#define EC_CMD_HOST_EVENT 0x00A4
3973
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003974/*****************************************************************************/
3975/* Switch commands */
3976
3977/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003978#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003979
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003980struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003981 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003982} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003983
3984/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003985#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003986#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003987
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003988/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003989struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003990 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003991} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003992
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003993/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003994struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003995 /* Flags to enable now */
3996 uint8_t now_flags;
3997
3998 /* Which flags to copy from now_flags */
3999 uint8_t now_mask;
4000
4001 /*
4002 * Flags to leave enabled in S3, if they're on at the S0->S3
4003 * transition. (Other flags will be disabled by the S0->S3
4004 * transition.)
4005 */
4006 uint8_t suspend_flags;
4007
4008 /* Which flags to copy from suspend_flags */
4009 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004010} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004011
4012/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004013struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004014 /* Flags to enable now */
4015 uint8_t now_flags;
4016
4017 /* Flags to leave enabled in S3 */
4018 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004019} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004021/*****************************************************************************/
4022/* GPIO commands. Only available on EC if write protect has been disabled. */
4023
4024/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004025#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004026
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004027struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004028 char name[32];
4029 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004030} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004031
4032/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004033#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004034
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004035/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004036struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004037 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004038} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004039
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004040struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004041 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004042} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004043
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004044/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004045struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004046 uint8_t subcmd;
4047 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004048 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004049 char name[32];
4050 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004051 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004052 uint8_t index;
4053 } get_info;
4054 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004055} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004056
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004057struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004058 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004059 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004060 uint8_t val;
4061 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004062 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004063 uint8_t val;
4064 char name[32];
4065 uint32_t flags;
4066 } get_info;
4067 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004068} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004069
4070enum gpio_get_subcmd {
4071 EC_GPIO_GET_BY_NAME = 0,
4072 EC_GPIO_GET_COUNT = 1,
4073 EC_GPIO_GET_INFO = 2,
4074};
4075
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004076/*****************************************************************************/
4077/* I2C commands. Only available when flash write protect is unlocked. */
4078
Duncan Laurie93e24442014-01-06 12:30:52 -08004079/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004080 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4081 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4082 *
4083 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004084 */
4085
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004086/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004087#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004088
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004089struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004090 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004091 uint8_t read_size; /* Either 8 or 16. */
4092 uint8_t port;
4093 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004094} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004095
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004096struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004097 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004098} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004099
4100/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004101#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004102
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004103struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004104 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004105 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004106 uint8_t write_size; /* Either 8 or 16. */
4107 uint8_t port;
4108 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004109} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004110
4111/*****************************************************************************/
4112/* Charge state commands. Only available when flash write protect unlocked. */
4113
Duncan Laurie93e24442014-01-06 12:30:52 -08004114/* Force charge state machine to stop charging the battery or force it to
4115 * discharge the battery.
4116 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004117#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08004118#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004119
Duncan Laurie93e24442014-01-06 12:30:52 -08004120enum ec_charge_control_mode {
4121 CHARGE_CONTROL_NORMAL = 0,
4122 CHARGE_CONTROL_IDLE,
4123 CHARGE_CONTROL_DISCHARGE,
4124};
4125
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004126struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004127 uint32_t mode; /* enum charge_control_mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004128} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004129
4130/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004131
4132/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004133#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004134
4135/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004136 * Read data from the saved snapshot. If the subcmd parameter is
4137 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4138 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4139 * end of the previous snapshot.
4140 *
4141 * The params are only looked at in version >= 1 of this command. Prior
4142 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004143 *
4144 * Response is null-terminated string. Empty string, if there is no more
4145 * remaining output.
4146 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004147#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004148
Duncan Laurieeb316852015-12-01 18:51:18 -08004149enum ec_console_read_subcmd {
4150 CONSOLE_READ_NEXT = 0,
4151 CONSOLE_READ_RECENT
4152};
4153
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004154struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004155 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004156} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004157
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004158/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004159
4160/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004161 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004162 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004163 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4164 * EC_RES_SUCCESS if the command was successful.
4165 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004166 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004167#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004168
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004169#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004170
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004171struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004172 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004173} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004174
Duncan Laurie433432b2013-06-03 10:38:22 -07004175/*****************************************************************************/
4176/* USB port mux control. */
4177
4178/*
4179 * Switch USB mux or return to automatic switching.
4180 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004181#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004182
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004183struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004184 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004185} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004186
4187/*****************************************************************************/
4188/* LDOs / FETs control. */
4189
4190enum ec_ldo_state {
4191 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4192 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4193};
4194
4195/*
4196 * Switch on/off a LDO.
4197 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004198#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004199
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004200struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004201 uint8_t index;
4202 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004203} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004204
4205/*
4206 * Get LDO state.
4207 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004208#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004209
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004210struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004211 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004212} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004213
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004214struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004215 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004216} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004217
4218/*****************************************************************************/
4219/* Power info. */
4220
4221/*
4222 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004223 *
4224 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004225 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004226#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004227
Jett Rinkba2edaf2020-01-14 11:49:06 -07004228/*
4229 * v1 of EC_CMD_POWER_INFO
4230 */
4231enum system_power_source {
4232 /*
4233 * Haven't established which power source is used yet,
4234 * or no presence signals are available
4235 */
4236 POWER_SOURCE_UNKNOWN = 0,
4237 /* System is running on battery alone */
4238 POWER_SOURCE_BATTERY = 1,
4239 /* System is running on A/C alone */
4240 POWER_SOURCE_AC = 2,
4241 /* System is running on A/C and battery */
4242 POWER_SOURCE_AC_BATTERY = 3,
4243};
4244
4245struct ec_response_power_info_v1 {
4246 /* enum system_power_source */
4247 uint8_t system_power_source;
4248 /* Battery state-of-charge, 0-100, 0 if not present */
4249 uint8_t battery_soc;
4250 /* AC Adapter 100% rating, Watts */
4251 uint8_t ac_adapter_100pct;
4252 /* AC Adapter 10ms rating, Watts */
4253 uint8_t ac_adapter_10ms;
4254 /* Battery 1C rating, derated */
4255 uint8_t battery_1cd;
4256 /* Rest of Platform average, Watts */
4257 uint8_t rop_avg;
4258 /* Rest of Platform peak, Watts */
4259 uint8_t rop_peak;
4260 /* Nominal charger efficiency, % */
4261 uint8_t nominal_charger_eff;
4262 /* Rest of Platform VR Average Efficiency, % */
4263 uint8_t rop_avg_eff;
4264 /* Rest of Platform VR Peak Efficiency, % */
4265 uint8_t rop_peak_eff;
4266 /* SoC VR Efficiency at Average level, % */
4267 uint8_t soc_avg_eff;
4268 /* SoC VR Efficiency at Peak level, % */
4269 uint8_t soc_peak_eff;
4270 /* Intel-specific items */
4271 struct {
4272 /* Battery's level of DBPT support: 0, 2 */
4273 uint8_t batt_dbpt_support_level;
4274 /*
4275 * Maximum peak power from battery (10ms), Watts
4276 * If DBPT is not supported, this is 0
4277 */
4278 uint8_t batt_dbpt_max_peak_power;
4279 /*
4280 * Sustained peak power from battery, Watts
4281 * If DBPT is not supported, this is 0
4282 */
4283 uint8_t batt_dbpt_sus_peak_power;
4284 } intel;
4285} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004286
4287/*****************************************************************************/
4288/* I2C passthru command */
4289
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004290#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004291
Duncan Laurie433432b2013-06-03 10:38:22 -07004292/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004293#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004294
4295/* Mask for address */
4296#define EC_I2C_ADDR_MASK 0x3ff
4297
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004298#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4299#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004300
4301/* Any error */
4302#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4303
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004304struct ec_params_i2c_passthru_msg {
4305 uint16_t addr_flags; /* I2C slave address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004306 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004307} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004308
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004309struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004310 uint8_t port; /* I2C port number */
4311 uint8_t num_msgs; /* Number of messages */
4312 struct ec_params_i2c_passthru_msg msg[];
4313 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004314} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004315
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004316struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004317 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4318 uint8_t num_msgs; /* Number of messages processed */
4319 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004320} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004321
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004322/*****************************************************************************/
4323/* Power button hang detect */
4324
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004325#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004326
4327/* Reasons to start hang detection timer */
4328/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004329#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004330
4331/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004332#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004333
4334 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004335#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004336
4337/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004338#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004339
4340/* Reasons to cancel hang detection */
4341
4342/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004343#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004344
4345/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004346#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004347
4348/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004349#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004350
4351/*
4352 * If this flag is set, all the other fields are ignored, and the hang detect
4353 * timer is started. This provides the AP a way to start the hang timer
4354 * without reconfiguring any of the other hang detect settings. Note that
4355 * you must previously have configured the timeouts.
4356 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004357#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004358
4359/*
4360 * If this flag is set, all the other fields are ignored (including
4361 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4362 * without reconfiguring any of the other hang detect settings.
4363 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004364#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004365
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004366struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004367 /* Flags; see EC_HANG_* */
4368 uint32_t flags;
4369
4370 /* Timeout in msec before generating host event, if enabled */
4371 uint16_t host_event_timeout_msec;
4372
4373 /* Timeout in msec before generating warm reboot, if enabled */
4374 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004375} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004376
4377/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004378/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004379
4380/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004381 * This is the single catch-all host command to exchange data regarding the
4382 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004383 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004384#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004385
4386/* Subcommands for this host command */
4387enum charge_state_command {
4388 CHARGE_STATE_CMD_GET_STATE,
4389 CHARGE_STATE_CMD_GET_PARAM,
4390 CHARGE_STATE_CMD_SET_PARAM,
4391 CHARGE_STATE_NUM_CMDS
4392};
4393
4394/*
4395 * Known param numbers are defined here. Ranges are reserved for board-specific
4396 * params, which are handled by the particular implementations.
4397 */
4398enum charge_state_params {
4399 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4400 CS_PARAM_CHG_CURRENT, /* charger current limit */
4401 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4402 CS_PARAM_CHG_STATUS, /* charger-specific status */
4403 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004404 CS_PARAM_LIMIT_POWER, /*
4405 * Check if power is limited due to
4406 * low battery and / or a weak external
4407 * charger. READ ONLY.
4408 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004409 /* How many so far? */
4410 CS_NUM_BASE_PARAMS,
4411
4412 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4413 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4414 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4415
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004416 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4417 CS_PARAM_DEBUG_MIN = 0x20000,
4418 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4419 CS_PARAM_DEBUG_MANUAL_MODE,
4420 CS_PARAM_DEBUG_SEEMS_DEAD,
4421 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4422 CS_PARAM_DEBUG_BATT_REMOVED,
4423 CS_PARAM_DEBUG_MANUAL_CURRENT,
4424 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4425 CS_PARAM_DEBUG_MAX = 0x2ffff,
4426
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004427 /* Other custom param ranges go here... */
4428};
4429
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004430struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004431 uint8_t cmd; /* enum charge_state_command */
4432 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004433 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004434
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004435 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004436 uint32_t param; /* enum charge_state_param */
4437 } get_param;
4438
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004439 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004440 uint32_t param; /* param to set */
4441 uint32_t value; /* value to set */
4442 } set_param;
4443 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004444} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004446struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004447 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004448 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004449 int ac;
4450 int chg_voltage;
4451 int chg_current;
4452 int chg_input_current;
4453 int batt_state_of_charge;
4454 } get_state;
4455
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004456 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004457 uint32_t value;
4458 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004459
4460 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004461 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004462} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004463
Duncan Laurie433432b2013-06-03 10:38:22 -07004464
4465/*
4466 * Set maximum battery charging current.
4467 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004468#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004469
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004470struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004471 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004472} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004473
4474/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004475 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004476 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004477#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004478
Duncan Laurieeb316852015-12-01 18:51:18 -08004479/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004480struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004481 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4482 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004483} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004484
Duncan Laurieeb316852015-12-01 18:51:18 -08004485#define EC_POWER_LIMIT_NONE 0xffff
4486
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004487/*
4488 * Set maximum voltage & current of a dedicated charge port
4489 */
4490#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4491
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004492struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004493 uint16_t current_lim; /* in mA */
4494 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004495} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004496
Duncan Laurieeb316852015-12-01 18:51:18 -08004497/*****************************************************************************/
4498/* Hibernate/Deep Sleep Commands */
4499
4500/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004501#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004502
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004503struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004504 /*
4505 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4506 * current settings without changing them.
4507 */
4508 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004509} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004510
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004511struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004512 /*
4513 * The current time in seconds in which the system has been in the G3
4514 * state. This value is reset if the EC transitions out of G3.
4515 */
4516 uint32_t time_g3;
4517
4518 /*
4519 * The current time remaining in seconds until the EC should hibernate.
4520 * This value is also reset if the EC transitions out of G3.
4521 */
4522 uint32_t time_remaining;
4523
4524 /*
4525 * The current time in seconds that the EC should wait in G3 before
4526 * hibernating.
4527 */
4528 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004529} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004530
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004531/* Inform the EC when entering a sleep state */
4532#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4533
4534enum host_sleep_event {
4535 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4536 HOST_SLEEP_EVENT_S3_RESUME = 2,
4537 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004538 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4539 /* S3 suspend with additional enabled wake sources */
4540 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004541};
4542
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004543struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004544 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004545} __ec_align1;
4546
4547/*
4548 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4549 * transition failures
4550 */
4551#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4552
4553/* Disable timeout detection for this sleep transition */
4554#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4555
4556struct ec_params_host_sleep_event_v1 {
4557 /* The type of sleep being entered or exited. */
4558 uint8_t sleep_event;
4559
4560 /* Padding */
4561 uint8_t reserved;
4562 union {
4563 /* Parameters that apply for suspend messages. */
4564 struct {
4565 /*
4566 * The timeout in milliseconds between when this message
4567 * is received and when the EC will declare sleep
4568 * transition failure if the sleep signal is not
4569 * asserted.
4570 */
4571 uint16_t sleep_timeout_ms;
4572 } suspend_params;
4573
4574 /* No parameters for non-suspend messages. */
4575 };
4576} __ec_align2;
4577
4578/* A timeout occurred when this bit is set */
4579#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4580
4581/*
4582 * The mask defining which bits correspond to the number of sleep transitions,
4583 * as well as the maximum number of suspend line transitions that will be
4584 * reported back to the host.
4585 */
4586#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4587
4588struct ec_response_host_sleep_event_v1 {
4589 union {
4590 /* Response fields that apply for resume messages. */
4591 struct {
4592 /*
4593 * The number of sleep power signal transitions that
4594 * occurred since the suspend message. The high bit
4595 * indicates a timeout occurred.
4596 */
4597 uint32_t sleep_transitions;
4598 } resume_response;
4599
4600 /* No response fields for non-resume messages. */
4601 };
4602} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004603
4604/*****************************************************************************/
4605/* Device events */
4606#define EC_CMD_DEVICE_EVENT 0x00AA
4607
4608enum ec_device_event {
4609 EC_DEVICE_EVENT_TRACKPAD,
4610 EC_DEVICE_EVENT_DSP,
4611 EC_DEVICE_EVENT_WIFI,
4612};
4613
4614enum ec_device_event_param {
4615 /* Get and clear pending device events */
4616 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4617 /* Get device event mask */
4618 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4619 /* Set device event mask */
4620 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4621};
4622
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004623#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004625struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004626 uint32_t event_mask;
4627 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004628} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004629
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004630struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004631 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004632} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004633
Duncan Laurie433432b2013-06-03 10:38:22 -07004634/*****************************************************************************/
4635/* Smart battery pass-through */
4636
4637/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004638#define EC_CMD_SB_READ_WORD 0x00B0
4639#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004640
4641/* Get / Set string smart battery parameters
4642 * formatted as SMBUS "block".
4643 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004644#define EC_CMD_SB_READ_BLOCK 0x00B2
4645#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004646
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004647struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004648 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004649} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004650
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004651struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004652 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004653} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004654
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004655struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004656 uint8_t reg;
4657 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004658} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004659
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004660struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004661 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004662} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004663
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004664struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004665 uint8_t reg;
4666 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004667} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004668
4669/*****************************************************************************/
4670/* Battery vendor parameters
4671 *
4672 * Get or set vendor-specific parameters in the battery. Implementations may
4673 * differ between boards or batteries. On a set operation, the response
4674 * contains the actual value set, which may be rounded or clipped from the
4675 * requested value.
4676 */
4677
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004678#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004679
4680enum ec_battery_vendor_param_mode {
4681 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4682 BATTERY_VENDOR_PARAM_MODE_SET,
4683};
4684
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004685struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004686 uint32_t param;
4687 uint32_t value;
4688 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004689} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004690
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004691struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004692 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004693} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004694
4695/*****************************************************************************/
4696/*
4697 * Smart Battery Firmware Update Commands
4698 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004699#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004700
4701enum ec_sb_fw_update_subcmd {
4702 EC_SB_FW_UPDATE_PREPARE = 0x0,
4703 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4704 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4705 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4706 EC_SB_FW_UPDATE_END = 0x4,
4707 EC_SB_FW_UPDATE_STATUS = 0x5,
4708 EC_SB_FW_UPDATE_PROTECT = 0x6,
4709 EC_SB_FW_UPDATE_MAX = 0x7,
4710};
4711
4712#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4713#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4714#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4715
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004716struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004717 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4718 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004719} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004720
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004721struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004722 struct ec_sb_fw_update_header hdr;
4723 union {
4724 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4725 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4726 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4727 /* EC_SB_FW_UPDATE_END = 0x4 */
4728 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4729 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004730 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004731
4732 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004733 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004734 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4735 } write;
4736 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004737} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004738
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004739struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004740 union {
4741 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004742 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004743 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4744 } info;
4745
4746 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004747 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004748 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4749 } status;
4750 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004751} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004752
4753/*
4754 * Entering Verified Boot Mode Command
4755 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4756 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004757 *
4758 * EC no longer needs to know what mode vboot has entered,
4759 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004760 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004761#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004762
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004763struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004764 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004765} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004766
4767#define VBOOT_MODE_NORMAL 0
4768#define VBOOT_MODE_DEVELOPER 1
4769#define VBOOT_MODE_RECOVERY 2
4770
Duncan Laurie433432b2013-06-03 10:38:22 -07004771/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004772/*
4773 * I2C passthru protection command: Protects I2C tunnels against access on
4774 * certain addresses (board-specific).
4775 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004776#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004777
4778enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004779 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
4780 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
4781 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07004782};
4783
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004784struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004785 uint8_t subcmd;
4786 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004787} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004788
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004789struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004790 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004791} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004792
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004793
4794/*****************************************************************************/
4795/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004796 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004797 *
4798 * These commands are for sending and receiving message via HDMI CEC
4799 */
4800
4801#define MAX_CEC_MSG_LEN 16
4802
4803/* CEC message from the AP to be written on the CEC bus */
4804#define EC_CMD_CEC_WRITE_MSG 0x00B8
4805
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004806/**
4807 * struct ec_params_cec_write - Message to write to the CEC bus
4808 * @msg: message content to write to the CEC bus
4809 */
4810struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004811 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004812} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004813
4814/* Set various CEC parameters */
4815#define EC_CMD_CEC_SET 0x00BA
4816
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004817/**
4818 * struct ec_params_cec_set - CEC parameters set
4819 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4820 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4821 * or 1 to enable CEC functionality, in case cmd is
4822 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4823 * address between 0 and 15 or 0xff to unregister
4824 */
4825struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004826 uint8_t cmd; /* enum cec_command */
4827 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004828} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004829
4830/* Read various CEC parameters */
4831#define EC_CMD_CEC_GET 0x00BB
4832
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004833/**
4834 * struct ec_params_cec_get - CEC parameters get
4835 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4836 */
4837struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004838 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004839} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004840
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004841/**
4842 * struct ec_response_cec_get - CEC parameters get response
4843 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4844 * disabled or 1 if CEC functionality is enabled,
4845 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4846 * configured logical address between 0 and 15 or 0xff if unregistered
4847 */
4848struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004849 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004850} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004851
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004852/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004853enum cec_command {
4854 /* CEC reading, writing and events enable */
4855 CEC_CMD_ENABLE,
4856 /* CEC logical address */
4857 CEC_CMD_LOGICAL_ADDRESS,
4858};
4859
4860/* Events from CEC to AP */
4861enum mkbp_cec_event {
4862 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004863 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004864 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004865 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004866};
4867
Gwendal Grignou880b4582016-06-20 08:49:25 -07004868/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004869
Jett Rinkba2edaf2020-01-14 11:49:06 -07004870/* Commands for audio codec. */
4871#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004872
Jett Rinkba2edaf2020-01-14 11:49:06 -07004873enum ec_codec_subcmd {
4874 EC_CODEC_GET_CAPABILITIES = 0x0,
4875 EC_CODEC_GET_SHM_ADDR = 0x1,
4876 EC_CODEC_SET_SHM_ADDR = 0x2,
4877 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004878};
4879
Jett Rinkba2edaf2020-01-14 11:49:06 -07004880enum ec_codec_cap {
4881 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
4882 EC_CODEC_CAP_WOV_LANG_SHM = 1,
4883 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004884};
4885
Jett Rinkba2edaf2020-01-14 11:49:06 -07004886enum ec_codec_shm_id {
4887 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
4888 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
4889 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004890};
4891
Jett Rinkba2edaf2020-01-14 11:49:06 -07004892enum ec_codec_shm_type {
4893 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
4894 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004895};
4896
Jett Rinkba2edaf2020-01-14 11:49:06 -07004897struct __ec_align1 ec_param_ec_codec_get_shm_addr {
4898 uint8_t shm_id;
4899 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004900};
4901
Jett Rinkba2edaf2020-01-14 11:49:06 -07004902struct __ec_align4 ec_param_ec_codec_set_shm_addr {
4903 uint64_t phys_addr;
4904 uint32_t len;
4905 uint8_t shm_id;
4906 uint8_t reserved[3];
4907};
4908
4909struct __ec_align4 ec_param_ec_codec {
4910 uint8_t cmd; /* enum ec_codec_subcmd */
4911 uint8_t reserved[3];
4912
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004913 union {
Jett Rinkba2edaf2020-01-14 11:49:06 -07004914 struct ec_param_ec_codec_get_shm_addr
4915 get_shm_addr_param;
4916 struct ec_param_ec_codec_set_shm_addr
4917 set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004918 };
4919};
4920
Jett Rinkba2edaf2020-01-14 11:49:06 -07004921struct __ec_align4 ec_response_ec_codec_get_capabilities {
4922 uint32_t capabilities;
4923};
4924
4925struct __ec_align4 ec_response_ec_codec_get_shm_addr {
4926 uint64_t phys_addr;
4927 uint32_t len;
4928 uint8_t type;
4929 uint8_t reserved[3];
4930};
4931
4932/*****************************************************************************/
4933
4934/* Commands for DMIC on audio codec. */
4935#define EC_CMD_EC_CODEC_DMIC 0x00BD
4936
4937enum ec_codec_dmic_subcmd {
4938 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
4939 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
4940 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
4941 EC_CODEC_DMIC_SUBCMD_COUNT,
4942};
4943
4944enum ec_codec_dmic_channel {
4945 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
4946 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
4947 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
4948 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
4949 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
4950 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
4951 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
4952 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
4953 EC_CODEC_DMIC_CHANNEL_COUNT,
4954};
4955
4956struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
4957 uint8_t channel; /* enum ec_codec_dmic_channel */
4958 uint8_t gain;
4959 uint8_t reserved[2];
4960};
4961
4962struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
4963 uint8_t channel; /* enum ec_codec_dmic_channel */
4964 uint8_t reserved[3];
4965};
4966
4967struct __ec_align4 ec_param_ec_codec_dmic {
4968 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
4969 uint8_t reserved[3];
4970
4971 union {
4972 struct ec_param_ec_codec_dmic_set_gain_idx
4973 set_gain_idx_param;
4974 struct ec_param_ec_codec_dmic_get_gain_idx
4975 get_gain_idx_param;
4976 };
4977};
4978
4979struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
4980 uint8_t max_gain;
4981};
4982
4983struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
4984 uint8_t gain;
4985};
4986
4987/*****************************************************************************/
4988
4989/* Commands for I2S RX on audio codec. */
4990
4991#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
4992
4993enum ec_codec_i2s_rx_subcmd {
4994 EC_CODEC_I2S_RX_ENABLE = 0x0,
4995 EC_CODEC_I2S_RX_DISABLE = 0x1,
4996 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
4997 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
4998 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
4999 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5000};
5001
5002enum ec_codec_i2s_rx_sample_depth {
5003 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5004 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5005 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5006};
5007
5008enum ec_codec_i2s_rx_daifmt {
5009 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5010 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5011 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5012 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5013};
5014
5015struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5016 uint8_t depth;
5017 uint8_t reserved[3];
5018};
5019
5020struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5021 uint8_t left;
5022 uint8_t right;
5023 uint8_t reserved[2];
5024};
5025
5026struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5027 uint8_t daifmt;
5028 uint8_t reserved[3];
5029};
5030
5031struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5032 uint32_t bclk;
5033};
5034
5035struct __ec_align4 ec_param_ec_codec_i2s_rx {
5036 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5037 uint8_t reserved[3];
5038
5039 union {
5040 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5041 set_sample_depth_param;
5042 struct ec_param_ec_codec_i2s_rx_set_daifmt
5043 set_daifmt_param;
5044 struct ec_param_ec_codec_i2s_rx_set_bclk
5045 set_bclk_param;
5046 };
5047};
5048
5049/*****************************************************************************/
5050/* Commands for WoV on audio codec. */
5051
5052#define EC_CMD_EC_CODEC_WOV 0x00BF
5053
5054enum ec_codec_wov_subcmd {
5055 EC_CODEC_WOV_SET_LANG = 0x0,
5056 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5057 EC_CODEC_WOV_GET_LANG = 0x2,
5058 EC_CODEC_WOV_ENABLE = 0x3,
5059 EC_CODEC_WOV_DISABLE = 0x4,
5060 EC_CODEC_WOV_READ_AUDIO = 0x5,
5061 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5062 EC_CODEC_WOV_SUBCMD_COUNT,
5063};
5064
5065/*
5066 * @hash is SHA256 of the whole language model.
5067 * @total_len indicates the length of whole language model.
5068 * @offset is the cursor from the beginning of the model.
5069 * @buf is the packet buffer.
5070 * @len denotes how many bytes in the buf.
5071 */
5072struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5073 uint8_t hash[32];
5074 uint32_t total_len;
5075 uint32_t offset;
5076 uint8_t buf[128];
5077 uint32_t len;
5078};
5079
5080struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5081 uint8_t hash[32];
5082 uint32_t total_len;
5083};
5084
5085struct __ec_align4 ec_param_ec_codec_wov {
5086 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5087 uint8_t reserved[3];
5088
5089 union {
5090 struct ec_param_ec_codec_wov_set_lang
5091 set_lang_param;
5092 struct ec_param_ec_codec_wov_set_lang_shm
5093 set_lang_shm_param;
5094 };
5095};
5096
5097struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5098 uint8_t hash[32];
5099};
5100
5101struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5102 uint8_t buf[128];
5103 uint32_t len;
5104};
5105
5106struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5107 uint32_t offset;
5108 uint32_t len;
5109};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005110
5111/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005112/* System commands */
5113
5114/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005115 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5116 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005117 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005118#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005119
5120/* Command */
5121enum ec_reboot_cmd {
5122 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005123 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005124 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005125 /* (command 3 was jump to RW-B) */
5126 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005127 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08005128 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
5129 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005130};
5131
5132/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005133#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5134#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5135#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005136
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005137struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005138 uint8_t cmd; /* enum ec_reboot_cmd */
5139 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005140} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005141
Duncan Laurie433432b2013-06-03 10:38:22 -07005142/*
5143 * Get information on last EC panic.
5144 *
5145 * Returns variable-length platform-dependent panic information. See panic.h
5146 * for details.
5147 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005148#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005149
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005150/*****************************************************************************/
5151/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005152 * Special commands
5153 *
5154 * These do not follow the normal rules for commands. See each command for
5155 * details.
5156 */
5157
5158/*
5159 * Reboot NOW
5160 *
5161 * This command will work even when the EC LPC interface is busy, because the
5162 * reboot command is processed at interrupt level. Note that when the EC
5163 * reboots, the host will reboot too, so there is no response to this command.
5164 *
5165 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5166 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005167#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005168
5169/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005170 * Resend last response (not supported on LPC).
5171 *
5172 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5173 * there was no previous command, or the previous command's response was too
5174 * big to save.
5175 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005176#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005177
5178/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005179 * This header byte on a command indicate version 0. Any header byte less
5180 * than this means that we are talking to an old EC which doesn't support
5181 * versioning. In that case, we assume version 0.
5182 *
5183 * Header bytes greater than this indicate a later version. For example,
5184 * EC_CMD_VERSION0 + 1 means we are using version 1.
5185 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005186 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005187 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005188#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005189
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005190/*****************************************************************************/
5191/*
5192 * PD commands
5193 *
5194 * These commands are for PD MCU communication.
5195 */
5196
5197/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005198#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005199#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005200
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005201enum pd_charge_state {
5202 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
5203 PD_CHARGE_NONE, /* No charging allowed */
5204 PD_CHARGE_5V, /* 5V charging only */
5205 PD_CHARGE_MAX /* Charge at max voltage */
5206};
5207
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005208/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005209#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005210
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005211struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005212 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005213 int8_t batt_soc; /* battery state of charge */
5214 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005215} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005216
5217/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005218#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5219#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
5220#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
5221#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5222#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5223#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5224#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08005225#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
5226 PD_STATUS_TCPC_ALERT_1 | \
5227 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005228struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005229 uint32_t curr_lim_ma; /* input current limit */
5230 uint16_t status; /* PD MCU status */
5231 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005232} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005233
5234/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005235#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005236
5237/* PD MCU host event status bits */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005238#define PD_EVENT_UPDATE_DEVICE BIT(0)
5239#define PD_EVENT_POWER_CHANGE BIT(1)
5240#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5241#define PD_EVENT_DATA_SWAP BIT(3)
5242struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005243 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005244} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005245
5246/* Set USB type-C port role and muxes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005247#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005248
5249enum usb_pd_control_role {
5250 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5251 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5252 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5253 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5254 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005255 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005256 USB_PD_CTRL_ROLE_COUNT
5257};
5258
5259enum usb_pd_control_mux {
5260 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5261 USB_PD_CTRL_MUX_NONE = 1,
5262 USB_PD_CTRL_MUX_USB = 2,
5263 USB_PD_CTRL_MUX_DP = 3,
5264 USB_PD_CTRL_MUX_DOCK = 4,
5265 USB_PD_CTRL_MUX_AUTO = 5,
5266 USB_PD_CTRL_MUX_COUNT
5267};
5268
Duncan Laurieeb316852015-12-01 18:51:18 -08005269enum usb_pd_control_swap {
5270 USB_PD_CTRL_SWAP_NONE = 0,
5271 USB_PD_CTRL_SWAP_DATA = 1,
5272 USB_PD_CTRL_SWAP_POWER = 2,
5273 USB_PD_CTRL_SWAP_VCONN = 3,
5274 USB_PD_CTRL_SWAP_COUNT
5275};
5276
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005277struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005278 uint8_t port;
5279 uint8_t role;
5280 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005281 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005282} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005283
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005284#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5285#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
5286#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005287
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005288#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5289#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5290#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5291#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5292#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5293#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005294#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */
Duncan Laurieeb316852015-12-01 18:51:18 -08005295
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005296struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005297 uint8_t enabled;
5298 uint8_t role;
5299 uint8_t polarity;
5300 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005301} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005302
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005303struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005304 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005305 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005306 uint8_t polarity;
5307 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005308} __ec_align1;
5309
Jett Rinkba2edaf2020-01-14 11:49:06 -07005310/* Possible port partner connections based on CC line states */
5311enum pd_cc_states {
5312 PD_CC_NONE = 0, /* No port partner attached */
5313
5314 /* From DFP perspective */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005315 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005316 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5317 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5318 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
5319
5320 /* From UFP perspective */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005321 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005322 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005323};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005324
Jett Rinkba2edaf2020-01-14 11:49:06 -07005325/* Active/Passive Cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005326#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005327/* Optical/Non-optical cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005328#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005329/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005330#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
5331/* Active Link Uni-Direction */
5332#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005333
5334/*
5335 * Underdevelopement :
5336 * Please remove this tag if using _v2 outside platform/ec
5337 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005338struct ec_response_usb_pd_control_v2 {
5339 uint8_t enabled;
5340 uint8_t role;
5341 uint8_t polarity;
5342 char state[32];
Jett Rinkba2edaf2020-01-14 11:49:06 -07005343 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5344 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005345 uint8_t reserved; /* Reserved for future use */
5346 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5347 uint8_t cable_speed; /* TBT_SS_* cable speed */
5348 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005349} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005350
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005351#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005352
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005353/* Maximum number of PD ports on a device, num_ports will be <= this */
5354#define EC_USB_PD_MAX_PORTS 8
5355
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005356struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005357 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005358} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005359
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005360#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005361
5362#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005363struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005364 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005365} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005366
5367enum usb_chg_type {
5368 USB_CHG_TYPE_NONE,
5369 USB_CHG_TYPE_PD,
5370 USB_CHG_TYPE_C,
5371 USB_CHG_TYPE_PROPRIETARY,
5372 USB_CHG_TYPE_BC12_DCP,
5373 USB_CHG_TYPE_BC12_CDP,
5374 USB_CHG_TYPE_BC12_SDP,
5375 USB_CHG_TYPE_OTHER,
5376 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005377 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005378 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005379};
5380enum usb_power_roles {
5381 USB_PD_PORT_POWER_DISCONNECTED,
5382 USB_PD_PORT_POWER_SOURCE,
5383 USB_PD_PORT_POWER_SINK,
5384 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5385};
5386
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005387struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005388 uint16_t voltage_max;
5389 uint16_t voltage_now;
5390 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005391 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005392} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005393
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005394struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005395 uint8_t role;
5396 uint8_t type;
5397 uint8_t dualrole;
5398 uint8_t reserved1;
5399 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005400 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005401} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005402
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005403
5404/*
5405 * This command will return the number of USB PD charge port + the number
5406 * of dedicated port present.
5407 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5408 */
5409#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005410struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005411 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005412} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005413
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005414/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005415#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005416
5417enum usb_pd_fw_update_cmds {
5418 USB_PD_FW_REBOOT,
5419 USB_PD_FW_FLASH_ERASE,
5420 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005421 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005422};
5423
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005424struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005425 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005426 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005427 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005428 uint32_t size; /* Size to write in bytes */
5429 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005430} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005431
5432/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005433#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005434/* RW hash is first 20 bytes of SHA-256 of RW section */
5435#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005436struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005437 uint16_t dev_id;
5438 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005439 uint8_t reserved; /*
5440 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005441 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005442 * Should have been reserved[2].
5443 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005444 uint32_t current_image; /* One of ec_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005445} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005446
5447/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005448#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005449
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005450struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005451 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005452} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005453
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005454/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005455#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005456struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005457 uint16_t vid; /* USB-IF VID */
5458 uint16_t pid; /* USB-IF PID */
5459 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005460} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005461
5462/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005463#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005464
5465/* Negative port parameters have special meaning */
5466enum usb_pd_override_ports {
5467 OVERRIDE_DONT_CHARGE = -2,
5468 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005469 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005470};
5471
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005472struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005473 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005474} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005475
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005476/*
5477 * Read (and delete) one entry of PD event log.
5478 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5479 * future non-PD logs that use the same internal EC event_log.
5480 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005481#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005482
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005483struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005484 uint32_t timestamp; /* relative timestamp in milliseconds */
5485 uint8_t type; /* event type : see PD_EVENT_xx below */
5486 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5487 uint16_t data; /* type-defined data payload */
5488 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005489} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005490
5491/* The timestamp is the microsecond counter shifted to get about a ms. */
5492#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5493
Duncan Laurieeb316852015-12-01 18:51:18 -08005494#define PD_LOG_SIZE_MASK 0x1f
5495#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005496#define PD_LOG_PORT_SHIFT 5
5497#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5498 ((size) & PD_LOG_SIZE_MASK))
5499#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5500#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5501
5502/* PD event log : entry types */
5503/* PD MCU events */
5504#define PD_EVENT_MCU_BASE 0x00
5505#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5506#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5507/* Reserved for custom board event */
5508#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5509/* PD generic accessory events */
5510#define PD_EVENT_ACC_BASE 0x20
5511#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5512#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5513/* PD power supply events */
5514#define PD_EVENT_PS_BASE 0x40
5515#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5516/* PD video dongles events */
5517#define PD_EVENT_VIDEO_BASE 0x60
5518#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5519#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5520/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005521#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005522
5523/*
5524 * PD_EVENT_MCU_CHARGE event definition :
5525 * the payload is "struct usb_chg_measures"
5526 * the data field contains the port state flags as defined below :
5527 */
5528/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005529#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005530/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005531#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005532/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005533#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005534/* Charger type */
5535#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005536#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005537/* Power delivery role */
5538#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5539
5540/*
5541 * PD_EVENT_PS_FAULT data field flags definition :
5542 */
5543#define PS_FAULT_OCP 1
5544#define PS_FAULT_FAST_OCP 2
5545#define PS_FAULT_OVP 3
5546#define PS_FAULT_DISCH 4
5547
5548/*
5549 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5550 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005551struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005552 uint8_t major;
5553 uint8_t minor;
5554 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005555} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005556
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005557struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005558 uint8_t family[2];
5559 uint8_t chipid[2];
5560 struct mcdp_version irom;
5561 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005562} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005563
5564/* struct mcdp_info field decoding */
5565#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5566#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5567
5568/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005569#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005570struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005571 uint16_t svid_idx; /* SVID index to get */
5572 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005573} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005574
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005575struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005576 uint16_t svid; /* SVID */
5577 uint16_t opos; /* Object Position */
5578 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005579} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005580
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005581#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005582
5583enum pd_mode_cmd {
5584 PD_EXIT_MODE = 0,
5585 PD_ENTER_MODE = 1,
5586 /* Not a command. Do NOT remove. */
5587 PD_MODE_CMD_COUNT,
5588};
5589
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005590struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005591 uint32_t cmd; /* enum pd_mode_cmd */
5592 uint16_t svid; /* SVID to set */
5593 uint8_t opos; /* Object Position */
5594 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005595} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005596
5597/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005598#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005599
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005600struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005601 uint8_t type; /* event type : see PD_EVENT_xx above */
5602 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005603} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005604
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005605
Gwendal Grignou880b4582016-06-20 08:49:25 -07005606/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005607#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005608
5609enum ec_pd_control_cmd {
5610 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5611 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5612 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005613 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5614 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005615};
5616
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005617struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005618 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005619 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005620} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005621
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005622/* Get info about USB-C SS muxes */
5623#define EC_CMD_USB_PD_MUX_INFO 0x011A
5624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005625struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005626 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005627} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005628
5629/* Flags representing mux state */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005630#define USB_PD_MUX_NONE 0 /* Open switch */
5631#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5632#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5633#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5634#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5635#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
5636#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
5637#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005638#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
5639
5640/* USB-C Dock connected */
5641#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005642
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005643struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005644 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005645} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005646
5647#define EC_CMD_PD_CHIP_INFO 0x011B
5648
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005649struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005650 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005651 /*
5652 * Fetch the live chip info or hard-coded + cached chip info
5653 * 0: hardcoded value for VID/PID, cached value for FW version
5654 * 1: live chip value for VID/PID/FW Version
5655 */
5656 uint8_t live;
5657} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005658
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005659struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005660 uint16_t vendor_id;
5661 uint16_t product_id;
5662 uint16_t device_id;
5663 union {
5664 uint8_t fw_version_string[8];
5665 uint64_t fw_version_number;
5666 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005667} __ec_align2;
5668
5669struct ec_response_pd_chip_info_v1 {
5670 uint16_t vendor_id;
5671 uint16_t product_id;
5672 uint16_t device_id;
5673 union {
5674 uint8_t fw_version_string[8];
5675 uint64_t fw_version_number;
5676 };
5677 union {
5678 uint8_t min_req_fw_version_string[8];
5679 uint64_t min_req_fw_version_number;
5680 };
5681} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005682
5683/* Run RW signature verification and get status */
5684#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5685
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005686struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005687 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005688} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005689
5690/* For controlling RWSIG task */
5691#define EC_CMD_RWSIG_ACTION 0x011D
5692
5693enum rwsig_action {
5694 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5695 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5696};
5697
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005698struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005699 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005700} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005701
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005702/* Run verification on a slot */
5703#define EC_CMD_EFS_VERIFY 0x011E
5704
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005705struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005706 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005707} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005708
5709/*
5710 * Retrieve info from Cros Board Info store. Response is based on the data
5711 * type. Integers return a uint32. Strings return a string, using the response
5712 * size to determine how big it is.
5713 */
5714#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5715/*
5716 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5717 * hardware write-protect enabled.
5718 */
5719#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5720
Daisuke Nojirif984a052018-02-15 12:38:15 -08005721enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005722 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5723 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5724 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005725 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005726 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005727 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005728 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005729 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005730 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005731};
5732
5733/*
5734 * Flags to control read operation
5735 *
5736 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5737 * write was successful without reboot.
5738 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005739#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005740
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005741struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005742 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005743 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005744} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005745
5746/*
5747 * Flags to control write behavior.
5748 *
5749 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5750 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005751 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005752 * will be initialized to zero first.
5753 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005754#define CBI_SET_NO_SYNC BIT(0)
5755#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005756
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005757struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08005758 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005759 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005760 uint32_t size; /* Data size */
5761 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005762} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005763
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005764/*
5765 * Information about resets of the AP by the EC and the EC's own uptime.
5766 */
5767#define EC_CMD_GET_UPTIME_INFO 0x0121
5768
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005769/* Reset causes */
5770#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
5771#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
5772#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
5773#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
5774#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
5775#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
5776#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
5777#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
5778#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
5779#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
5780#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
5781#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
5782#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
5783#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
5784 * previous boot
5785 */
5786#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
5787#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
5788#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
5789#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
5790#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005791#define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This
5792 * enables PD in RO for Chromebox.
5793 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005794
5795struct ec_response_uptime_info {
5796 /*
5797 * Number of milliseconds since the last EC boot. Sysjump resets
5798 * typically do not restart the EC's time_since_boot epoch.
5799 *
5800 * WARNING: The EC's sense of time is much less accurate than the AP's
5801 * sense of time, in both phase and frequency. This timebase is similar
5802 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5803 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005804 uint32_t time_since_ec_boot_ms;
5805
5806 /*
5807 * Number of times the AP was reset by the EC since the last EC boot.
5808 * Note that the AP may be held in reset by the EC during the initial
5809 * boot sequence, such that the very first AP boot may count as more
5810 * than one here.
5811 */
5812 uint32_t ap_resets_since_ec_boot;
5813
5814 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005815 * The set of flags which describe the EC's most recent reset.
5816 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005817 */
5818 uint32_t ec_reset_flags;
5819
5820 /* Empty log entries have both the cause and timestamp set to zero. */
5821 struct ap_reset_log_entry {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005822 /*
5823 * See include/chipset.h: enum chipset_{reset,shutdown}_reason
5824 * for details.
5825 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005826 uint16_t reset_cause;
5827
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005828 /* Reserved for protocol growth. */
5829 uint16_t reserved;
5830
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005831 /*
5832 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005833 * last EC boot, in the same epoch as time_since_ec_boot_ms.
5834 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005835 */
5836 uint32_t reset_time_ms;
5837 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005838} __ec_align4;
5839
5840/*
5841 * Add entropy to the device secret (stored in the rollback region).
5842 *
5843 * Depending on the chip, the operation may take a long time (e.g. to erase
5844 * flash), so the commands are asynchronous.
5845 */
5846#define EC_CMD_ADD_ENTROPY 0x0122
5847
5848enum add_entropy_action {
5849 /* Add entropy to the current secret. */
5850 ADD_ENTROPY_ASYNC = 0,
5851 /*
5852 * Add entropy, and also make sure that the previous secret is erased.
5853 * (this can be implemented by adding entropy multiple times until
5854 * all rolback blocks have been overwritten).
5855 */
5856 ADD_ENTROPY_RESET_ASYNC = 1,
5857 /* Read back result from the previous operation. */
5858 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005859};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005860
5861struct ec_params_rollback_add_entropy {
5862 uint8_t action;
5863} __ec_align1;
5864
5865/*
5866 * Perform a single read of a given ADC channel.
5867 */
5868#define EC_CMD_ADC_READ 0x0123
5869
5870struct ec_params_adc_read {
5871 uint8_t adc_channel;
5872} __ec_align1;
5873
5874struct ec_response_adc_read {
5875 int32_t adc_value;
5876} __ec_align4;
5877
5878/*
5879 * Read back rollback info
5880 */
5881#define EC_CMD_ROLLBACK_INFO 0x0124
5882
5883struct ec_response_rollback_info {
5884 int32_t id; /* Incrementing number to indicate which region to use. */
5885 int32_t rollback_min_version;
5886 int32_t rw_rollback_version;
5887} __ec_align4;
5888
5889
5890/* Issue AP reset */
5891#define EC_CMD_AP_RESET 0x0125
5892
5893/*****************************************************************************/
5894/* Locate peripheral chips
5895 *
5896 * Return values:
5897 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
5898 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
5899 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
5900 */
5901#define EC_CMD_LOCATE_CHIP 0x0126
5902
5903enum ec_chip_type {
5904 EC_CHIP_TYPE_CBI_EEPROM = 0,
5905 EC_CHIP_TYPE_TCPC = 1,
5906 EC_CHIP_TYPE_COUNT,
5907 EC_CHIP_TYPE_MAX = 0xFF,
5908};
5909
5910enum ec_bus_type {
5911 EC_BUS_TYPE_I2C = 0,
5912 EC_BUS_TYPE_EMBEDDED = 1,
5913 EC_BUS_TYPE_COUNT,
5914 EC_BUS_TYPE_MAX = 0xFF,
5915};
5916
5917struct ec_i2c_info {
5918 uint16_t port; /* Physical port for device */
5919 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
5920};
5921
5922struct ec_params_locate_chip {
5923 uint8_t type; /* enum ec_chip_type */
5924 uint8_t index; /* Specifies one instance of chip type */
5925 /* Used for type specific parameters in future */
5926 union {
5927 uint16_t reserved;
5928 };
5929} __ec_align2;
5930
5931
5932struct ec_response_locate_chip {
5933 uint8_t bus_type; /* enum ec_bus_type */
5934 uint8_t reserved; /* Aligning the following union to 2 bytes */
5935 union {
5936 struct ec_i2c_info i2c_info;
5937 };
5938} __ec_align2;
5939
Jett Rinkba2edaf2020-01-14 11:49:06 -07005940/*
5941 * Reboot AP on G3
5942 *
5943 * This command is used for validation purpose, where the AP needs to be
5944 * returned back to S0 state from G3 state without using the servo to trigger
5945 * wake events.For this,there is no request or response struct.
5946 *
5947 * Order of command usage:
5948 * ectool reboot_ap_on_g3 && shutdown -h now
5949 */
5950#define EC_CMD_REBOOT_AP_ON_G3 0x0127
5951
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005952/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07005953/* Get PD port capabilities
5954 *
5955 * Returns the following static *capabilities* of the given port:
5956 * 1) Power role: source, sink, or dual. It is not anticipated that
5957 * future CrOS devices would ever be only a source, so the options are
5958 * sink or dual.
5959 * 2) Try-power role: source, sink, or none (practically speaking, I don't
5960 * believe any CrOS device would support Try.SNK, so this would be source
5961 * or none).
5962 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
5963 * for CrOS devices.
5964 */
5965#define EC_CMD_GET_PD_PORT_CAPS 0x0128
5966
5967enum ec_pd_power_role_caps {
5968 EC_PD_POWER_ROLE_SOURCE = 0,
5969 EC_PD_POWER_ROLE_SINK = 1,
5970 EC_PD_POWER_ROLE_DUAL = 2,
5971};
5972
5973enum ec_pd_try_power_role_caps {
5974 EC_PD_TRY_POWER_ROLE_NONE = 0,
5975 EC_PD_TRY_POWER_ROLE_SINK = 1,
5976 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
5977};
5978
5979enum ec_pd_data_role_caps {
5980 EC_PD_DATA_ROLE_DFP = 0,
5981 EC_PD_DATA_ROLE_UFP = 1,
5982 EC_PD_DATA_ROLE_DUAL = 2,
5983};
5984
5985/* From: power_manager/power_supply_properties.proto */
5986enum ec_pd_port_location {
5987 /* The location of the port is unknown, or there's only one port. */
5988 EC_PD_PORT_LOCATION_UNKNOWN = 0,
5989
5990 /*
5991 * Various positions on the device. The first word describes the side of
5992 * the device where the port is located while the second clarifies the
5993 * position. For example, LEFT_BACK means the farthest-back port on the
5994 * left side, while BACK_LEFT means the leftmost port on the back of the
5995 * device.
5996 */
5997 EC_PD_PORT_LOCATION_LEFT = 1,
5998 EC_PD_PORT_LOCATION_RIGHT = 2,
5999 EC_PD_PORT_LOCATION_BACK = 3,
6000 EC_PD_PORT_LOCATION_FRONT = 4,
6001 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6002 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
6003 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
6004 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6005 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6006 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
6007};
6008
6009struct ec_params_get_pd_port_caps {
6010 uint8_t port; /* Which port to interrogate */
6011} __ec_align1;
6012
6013struct ec_response_get_pd_port_caps {
6014 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6015 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6016 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6017 uint8_t pd_port_location; /* enum ec_pd_port_location */
6018} __ec_align1;
6019
6020/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006021/*
6022 * Button press simulation
6023 *
6024 * This command is used to simulate a button press.
6025 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6026 * Time duration for which button needs to be pressed is an optional parameter.
6027 *
6028 * NOTE: This is only available on unlocked devices for testing purposes only.
6029 */
6030#define EC_CMD_BUTTON 0x0129
6031
6032struct ec_params_button {
6033 /* Button mask aligned to enum keyboard_button_type */
6034 uint32_t btn_mask;
6035
6036 /* Duration in milliseconds button needs to be pressed */
6037 uint32_t press_ms;
6038} __ec_align1;
6039
6040enum keyboard_button_type {
6041 KEYBOARD_BUTTON_POWER = 0,
6042 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
6043 KEYBOARD_BUTTON_VOLUME_UP = 2,
6044 KEYBOARD_BUTTON_RECOVERY = 3,
6045 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6046 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6047 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6048 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6049 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6050 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6051 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6052 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
6053
6054 KEYBOARD_BUTTON_COUNT
6055};
Rajat Jainc0495722020-04-02 23:58:35 -07006056/*****************************************************************************/
6057/*
6058 * "Get the Keyboard Config". An EC implementing this command is expected to be
6059 * vivaldi capable, i.e. can send action codes for the top row keys.
6060 * Additionally, capability to send function codes for the same keys is
6061 * optional and acceptable.
6062 *
6063 * Note: If the top row can generate both function and action codes by
6064 * using a dedicated Fn key, it does not matter whether the key sends
6065 * "function" or "action" codes by default. In both cases, the response
6066 * for this command will look the same.
6067 */
6068#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6069
6070/* Possible values for the top row keys */
6071enum action_key {
6072 TK_ABSENT = 0,
6073 TK_BACK = 1,
6074 TK_FORWARD = 2,
6075 TK_REFRESH = 3,
6076 TK_FULLSCREEN = 4,
6077 TK_OVERVIEW = 5,
6078 TK_BRIGHTNESS_DOWN = 6,
6079 TK_BRIGHTNESS_UP = 7,
6080 TK_VOL_MUTE = 8,
6081 TK_VOL_DOWN = 9,
6082 TK_VOL_UP = 10,
6083 TK_SNAPSHOT = 11,
6084 TK_PRIVACY_SCRN_TOGGLE = 12,
6085 TK_KBD_BKLIGHT_DOWN = 13,
6086 TK_KBD_BKLIGHT_UP = 14,
6087 TK_PLAY_PAUSE = 15,
6088 TK_NEXT_TRACK = 16,
6089 TK_PREV_TRACK = 17,
6090};
6091
6092/*
6093 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6094 * If this needs to change, please create a new version of the command.
6095 */
6096#define MAX_TOP_ROW_KEYS 15
6097#define MIN_TOP_ROW_KEYS 10
6098
6099/*
6100 * Is the keyboard capable of sending function keys *in addition to*
6101 * action keys. This is possible for e.g. if the keyboard has a
6102 * dedicated Fn key.
6103 */
6104#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
6105/*
6106 * Whether the keyboard has a dedicated numeric keyboard.
6107 */
6108#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
6109/*
6110 * Whether the keyboard has a screenlock key.
6111 */
6112#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
6113
6114struct ec_response_keybd_config {
6115 /*
6116 * Number of top row keys, excluding Esc and Screenlock.
6117 * If this is 0, all Vivaldi keyboard code is disabled.
6118 * (i.e. does not expose any tables to the kernel).
6119 */
6120 uint8_t num_top_row_keys;
6121
6122 /*
6123 * The action keys in the top row, in order from left to right.
6124 * The values are filled from enum action_key. Esc and Screenlock
6125 * keys are not considered part of top row keys.
6126 */
6127 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6128
6129 /* Capability flags */
6130 uint8_t capabilities;
6131
6132} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006133
6134/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006135/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08006136
6137/*****************************************************************************/
6138/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006139 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08006140 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006141#define EC_CMD_CR51_BASE 0x0300
6142#define EC_CMD_CR51_LAST 0x03FF
6143
6144/*****************************************************************************/
6145/* Fingerprint MCU commands: range 0x0400-0x040x */
6146
6147/* Fingerprint SPI sensor passthru command: prototyping ONLY */
6148#define EC_CMD_FP_PASSTHRU 0x0400
6149
6150#define EC_FP_FLAG_NOT_COMPLETE 0x1
6151
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006152struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006153 uint16_t len; /* Number of bytes to write then read */
6154 uint16_t flags; /* EC_FP_FLAG_xxx */
6155 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006156} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006157
6158/* Configure the Fingerprint MCU behavior */
6159#define EC_CMD_FP_MODE 0x0402
6160
6161/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006162#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006163/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006164#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006165/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006166#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006167/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006168#define FP_MODE_CAPTURE BIT(3)
6169/* Finger enrollment session on-going */
6170#define FP_MODE_ENROLL_SESSION BIT(4)
6171/* Enroll the current finger image */
6172#define FP_MODE_ENROLL_IMAGE BIT(5)
6173/* Try to match the current finger image */
6174#define FP_MODE_MATCH BIT(6)
6175/* Reset and re-initialize the sensor. */
6176#define FP_MODE_RESET_SENSOR BIT(7)
6177/* special value: don't change anything just read back current mode */
6178#define FP_MODE_DONT_CHANGE BIT(31)
6179
6180#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
6181 FP_MODE_FINGER_DOWN | \
6182 FP_MODE_FINGER_UP | \
6183 FP_MODE_CAPTURE | \
6184 FP_MODE_ENROLL_SESSION | \
6185 FP_MODE_ENROLL_IMAGE | \
6186 FP_MODE_MATCH | \
6187 FP_MODE_RESET_SENSOR | \
6188 FP_MODE_DONT_CHANGE)
6189
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006190/* Capture types defined in bits [30..28] */
6191#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006192#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
6193/*
6194 * This enum must remain ordered, if you add new values you must ensure that
6195 * FP_CAPTURE_TYPE_MAX is still the last one.
6196 */
6197enum fp_capture_type {
6198 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
6199 FP_CAPTURE_VENDOR_FORMAT = 0,
6200 /* Simple raw image capture (produces width x height x bpp bits) */
6201 FP_CAPTURE_SIMPLE_IMAGE = 1,
6202 /* Self test pattern (e.g. checkerboard) */
6203 FP_CAPTURE_PATTERN0 = 2,
6204 /* Self test pattern (e.g. inverted checkerboard) */
6205 FP_CAPTURE_PATTERN1 = 3,
6206 /* Capture for Quality test with fixed contrast */
6207 FP_CAPTURE_QUALITY_TEST = 4,
6208 /* Capture for pixel reset value test */
6209 FP_CAPTURE_RESET_TEST = 5,
6210 FP_CAPTURE_TYPE_MAX,
6211};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006212/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006213#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
6214 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006215
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006216struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006217 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006218} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006219
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006220struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006221 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006222} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006223
6224/* Retrieve Fingerprint sensor information */
6225#define EC_CMD_FP_INFO 0x0403
6226
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006227/* Number of dead pixels detected on the last maintenance */
6228#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006229/* Unknown number of dead pixels detected on the last maintenance */
6230#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006231/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006232#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006233/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006234#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006235/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006236#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006237/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006238#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006239
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006240struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006241 /* Sensor identification */
6242 uint32_t vendor_id;
6243 uint32_t product_id;
6244 uint32_t model_id;
6245 uint32_t version;
6246 /* Image frame characteristics */
6247 uint32_t frame_size;
6248 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
6249 uint16_t width;
6250 uint16_t height;
6251 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006252 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006253} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006254
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006255struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006256 /* Sensor identification */
6257 uint32_t vendor_id;
6258 uint32_t product_id;
6259 uint32_t model_id;
6260 uint32_t version;
6261 /* Image frame characteristics */
6262 uint32_t frame_size;
6263 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
6264 uint16_t width;
6265 uint16_t height;
6266 uint16_t bpp;
6267 uint16_t errors; /* see FP_ERROR_ flags above */
6268 /* Template/finger current information */
6269 uint32_t template_size; /* max template size in bytes */
6270 uint16_t template_max; /* maximum number of fingers/templates */
6271 uint16_t template_valid; /* number of valid fingers/templates */
6272 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006273 uint32_t template_version; /* version of the template format */
6274} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006275
6276/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006277#define EC_CMD_FP_FRAME 0x0404
6278
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006279/* constants defining the 'offset' field which also contains the frame index */
6280#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006281/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006282#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006283/* First frame buffer holding a template */
6284#define FP_FRAME_INDEX_TEMPLATE 1
6285#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006286#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
6287
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006288/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006289#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006290
6291/* Constants for encryption parameters */
6292#define FP_CONTEXT_NONCE_BYTES 12
6293#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
6294#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07006295#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006296#define FP_CONTEXT_TPM_BYTES 32
6297
Jett Rinkba2edaf2020-01-14 11:49:06 -07006298/* Constants for positive match parameters. */
6299#define FP_POSITIVE_MATCH_SALT_BYTES 16
6300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006301struct ec_fp_template_encryption_metadata {
6302 /*
6303 * Version of the structure format (N=3).
6304 */
6305 uint16_t struct_version;
6306 /* Reserved bytes, set to 0. */
6307 uint16_t reserved;
6308 /*
6309 * The salt is *only* ever used for key derivation. The nonce is unique,
6310 * a different one is used for every message.
6311 */
6312 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07006313 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006314 uint8_t tag[FP_CONTEXT_TAG_BYTES];
6315};
6316
6317struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006318 /*
6319 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
6320 * in the high nibble, and the real offset within the frame in
6321 * FP_FRAME_OFFSET_MASK.
6322 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006323 uint32_t offset;
6324 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006325} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006326
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006327/* Load a template into the MCU */
6328#define EC_CMD_FP_TEMPLATE 0x0405
6329
6330/* Flag in the 'size' field indicating that the full template has been sent */
6331#define FP_TEMPLATE_COMMIT 0x80000000
6332
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006333struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006334 uint32_t offset;
6335 uint32_t size;
6336 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006337} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006338
6339/* Clear the current fingerprint user context and set a new one */
6340#define EC_CMD_FP_CONTEXT 0x0406
6341
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006342struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006343 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006344} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006345
Jett Rinkba2edaf2020-01-14 11:49:06 -07006346enum fp_context_action {
6347 FP_CONTEXT_ASYNC = 0,
6348 FP_CONTEXT_GET_RESULT = 1,
6349};
6350
6351/* Version 1 of the command is "asynchronous". */
6352struct ec_params_fp_context_v1 {
6353 uint8_t action; /**< enum fp_context_action */
6354 uint8_t reserved[3]; /**< padding for alignment */
6355 uint32_t userid[FP_CONTEXT_USERID_WORDS];
6356} __ec_align4;
6357
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006358#define EC_CMD_FP_STATS 0x0407
6359
6360#define FPSTATS_CAPTURE_INV BIT(0)
6361#define FPSTATS_MATCHING_INV BIT(1)
6362
6363struct ec_response_fp_stats {
6364 uint32_t capture_time_us;
6365 uint32_t matching_time_us;
6366 uint32_t overall_time_us;
6367 struct {
6368 uint32_t lo;
6369 uint32_t hi;
6370 } overall_t0;
6371 uint8_t timestamps_invalid;
6372 int8_t template_matched;
6373} __ec_align2;
6374
6375#define EC_CMD_FP_SEED 0x0408
6376struct ec_params_fp_seed {
6377 /*
6378 * Version of the structure format (N=3).
6379 */
6380 uint16_t struct_version;
6381 /* Reserved bytes, set to 0. */
6382 uint16_t reserved;
6383 /* Seed from the TPM. */
6384 uint8_t seed[FP_CONTEXT_TPM_BYTES];
6385} __ec_align4;
6386
6387#define EC_CMD_FP_ENC_STATUS 0x0409
6388
6389/* FP TPM seed has been set or not */
6390#define FP_ENC_STATUS_SEED_SET BIT(0)
6391
6392struct ec_response_fp_encryption_status {
6393 /* Used bits in encryption engine status */
6394 uint32_t valid_flags;
6395 /* Encryption engine status */
6396 uint32_t status;
6397} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006398
Jett Rinkba2edaf2020-01-14 11:49:06 -07006399#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
6400struct ec_params_fp_read_match_secret {
6401 uint16_t fgr;
6402} __ec_align4;
6403
6404/* The positive match secret has the length of the SHA256 digest. */
6405#define FP_POSITIVE_MATCH_SECRET_BYTES 32
6406struct ec_response_fp_read_match_secret {
6407 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
6408} __ec_align4;
6409
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006410/*****************************************************************************/
6411/* Touchpad MCU commands: range 0x0500-0x05FF */
6412
6413/* Perform touchpad self test */
6414#define EC_CMD_TP_SELF_TEST 0x0500
6415
6416/* Get number of frame types, and the size of each type */
6417#define EC_CMD_TP_FRAME_INFO 0x0501
6418
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006419struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006420 uint32_t n_frames;
6421 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006422} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006423
6424/* Create a snapshot of current frame readings */
6425#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
6426
6427/* Read the frame */
6428#define EC_CMD_TP_FRAME_GET 0x0503
6429
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006430struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006431 uint32_t frame_index;
6432 uint32_t offset;
6433 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006434} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08006435
6436/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006437/* EC-EC communication commands: range 0x0600-0x06FF */
6438
6439#define EC_COMM_TEXT_MAX 8
6440
6441/*
6442 * Get battery static information, i.e. information that never changes, or
6443 * very infrequently.
6444 */
6445#define EC_CMD_BATTERY_GET_STATIC 0x0600
6446
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006447/**
6448 * struct ec_params_battery_static_info - Battery static info parameters
6449 * @index: Battery index.
6450 */
6451struct ec_params_battery_static_info {
6452 uint8_t index;
6453} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006454
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006455/**
6456 * struct ec_response_battery_static_info - Battery static info response
6457 * @design_capacity: Battery Design Capacity (mAh)
6458 * @design_voltage: Battery Design Voltage (mV)
6459 * @manufacturer: Battery Manufacturer String
6460 * @model: Battery Model Number String
6461 * @serial: Battery Serial Number String
6462 * @type: Battery Type String
6463 * @cycle_count: Battery Cycle Count
6464 */
6465struct ec_response_battery_static_info {
6466 uint16_t design_capacity;
6467 uint16_t design_voltage;
6468 char manufacturer[EC_COMM_TEXT_MAX];
6469 char model[EC_COMM_TEXT_MAX];
6470 char serial[EC_COMM_TEXT_MAX];
6471 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006472 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006473 uint32_t cycle_count;
6474} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006475
6476/*
6477 * Get battery dynamic information, i.e. information that is likely to change
6478 * every time it is read.
6479 */
6480#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
6481
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006482/**
6483 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
6484 * @index: Battery index.
6485 */
6486struct ec_params_battery_dynamic_info {
6487 uint8_t index;
6488} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006489
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006490/**
6491 * struct ec_response_battery_dynamic_info - Battery dynamic info response
6492 * @actual_voltage: Battery voltage (mV)
6493 * @actual_current: Battery current (mA); negative=discharging
6494 * @remaining_capacity: Remaining capacity (mAh)
6495 * @full_capacity: Capacity (mAh, might change occasionally)
6496 * @flags: Flags, see EC_BATT_FLAG_*
6497 * @desired_voltage: Charging voltage desired by battery (mV)
6498 * @desired_current: Charging current desired by battery (mA)
6499 */
6500struct ec_response_battery_dynamic_info {
6501 int16_t actual_voltage;
6502 int16_t actual_current;
6503 int16_t remaining_capacity;
6504 int16_t full_capacity;
6505 int16_t flags;
6506 int16_t desired_voltage;
6507 int16_t desired_current;
6508} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006509
6510/*
6511 * Control charger chip. Used to control charger chip on the slave.
6512 */
6513#define EC_CMD_CHARGER_CONTROL 0x0602
6514
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006515/**
6516 * struct ec_params_charger_control - Charger control parameters
6517 * @max_current: Charger current (mA). Positive to allow base to draw up to
6518 * max_current and (possibly) charge battery, negative to request current
6519 * from base (OTG).
6520 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
6521 * >= 0.
6522 * @allow_charging: Allow base battery charging (only makes sense if
6523 * max_current > 0).
6524 */
6525struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006526 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006527 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006528 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006529} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006530
6531/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08006532/*
6533 * Reserve a range of host commands for board-specific, experimental, or
6534 * special purpose features. These can be (re)used without updating this file.
6535 *
6536 * CAUTION: Don't go nuts with this. Shipping products should document ALL
6537 * their EC commands for easier development, testing, debugging, and support.
6538 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006539 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
6540 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
6541 *
Duncan Laurieeb316852015-12-01 18:51:18 -08006542 * In your experimental code, you may want to do something like this:
6543 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006544 * #define EC_CMD_MAGIC_FOO 0x0000
6545 * #define EC_CMD_MAGIC_BAR 0x0001
6546 * #define EC_CMD_MAGIC_HEY 0x0002
6547 *
6548 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
6549 * EC_VER_MASK(0);
6550 *
6551 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
6552 * EC_VER_MASK(0);
6553 *
6554 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
6555 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08006556 */
6557#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
6558#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
6559
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006560/*
6561 * Given the private host command offset, calculate the true private host
6562 * command value.
6563 */
6564#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
6565 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
6566
Duncan Laurie93e24442014-01-06 12:30:52 -08006567/*****************************************************************************/
6568/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006569 * Passthru commands
6570 *
6571 * Some platforms have sub-processors chained to each other. For example.
6572 *
6573 * AP <--> EC <--> PD MCU
6574 *
6575 * The top 2 bits of the command number are used to indicate which device the
6576 * command is intended for. Device 0 is always the device receiving the
6577 * command; other device mapping is board-specific.
6578 *
6579 * When a device receives a command to be passed to a sub-processor, it passes
6580 * it on with the device number set back to 0. This allows the sub-processor
6581 * to remain blissfully unaware of whether the command originated on the next
6582 * device up the chain, or was passed through from the AP.
6583 *
6584 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
6585 * AP sends command 0x4002 to the EC
6586 * EC sends command 0x0002 to the PD MCU
6587 * EC forwards PD MCU response back to the AP
6588 */
6589
6590/* Offset and max command number for sub-device n */
6591#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
6592#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
6593
6594/*****************************************************************************/
6595/*
Duncan Laurie93e24442014-01-06 12:30:52 -08006596 * Deprecated constants. These constants have been renamed for clarity. The
6597 * meaning and size has not changed. Programs that use the old names should
6598 * switch to the new names soon, as the old names may not be carried forward
6599 * forever.
6600 */
6601#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
6602#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
6603#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
6604
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006605#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006606
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006607#ifdef __cplusplus
6608}
6609#endif
6610
Duncan Laurieeb316852015-12-01 18:51:18 -08006611#endif /* __CROS_EC_EC_COMMANDS_H */