aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mfd
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/mfd')
-rw-r--r--include/linux/mfd/cros_ec.h1
-rw-r--r--include/linux/mfd/cros_ec_commands.h3594
2 files changed, 2884 insertions, 711 deletions
diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h
index 5ddca44be06d..45aba26db964 100644
--- a/include/linux/mfd/cros_ec.h
+++ b/include/linux/mfd/cros_ec.h
@@ -155,6 +155,7 @@ struct cros_ec_device {
155 struct ec_response_get_next_event_v1 event_data; 155 struct ec_response_get_next_event_v1 event_data;
156 int event_size; 156 int event_size;
157 u32 host_event_wake_mask; 157 u32 host_event_wake_mask;
158 u32 last_resume_result;
158}; 159};
159 160
160/** 161/**
diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h
index 114614e20e4d..7ccb8757b79d 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -4,17 +4,20 @@
4 * 4 *
5 * Copyright (C) 2012 Google, Inc 5 * Copyright (C) 2012 Google, Inc
6 * 6 *
7 * The ChromeOS EC multi function device is used to mux all the requests 7 * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
8 * to the EC device for its multiple features: keyboard controller, 8 * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
9 * battery charging and regulator control, firmware update.
10 *
11 * NOTE: This file is copied verbatim from the ChromeOS EC Open Source
12 * project in an attempt to make future updates easy to make.
13 */ 9 */
14 10
11/* Host communication command constants for Chrome EC */
12
15#ifndef __CROS_EC_COMMANDS_H 13#ifndef __CROS_EC_COMMANDS_H
16#define __CROS_EC_COMMANDS_H 14#define __CROS_EC_COMMANDS_H
17 15
16
17
18
19#define BUILD_ASSERT(_cond)
20
18/* 21/*
19 * Current version of this protocol 22 * Current version of this protocol
20 * 23 *
@@ -25,7 +28,7 @@
25#define EC_PROTO_VERSION 0x00000002 28#define EC_PROTO_VERSION 0x00000002
26 29
27/* Command version mask */ 30/* Command version mask */
28#define EC_VER_MASK(version) (1UL << (version)) 31#define EC_VER_MASK(version) BIT(version)
29 32
30/* I/O addresses for ACPI commands */ 33/* I/O addresses for ACPI commands */
31#define EC_LPC_ADDR_ACPI_DATA 0x62 34#define EC_LPC_ADDR_ACPI_DATA 0x62
@@ -39,25 +42,28 @@
39/* Protocol version 2 */ 42/* Protocol version 2 */
40#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */ 43#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
41#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is 44#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
42 * EC_PROTO2_MAX_PARAM_SIZE */ 45 * EC_PROTO2_MAX_PARAM_SIZE
46 */
43/* Protocol version 3 */ 47/* Protocol version 3 */
44#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */ 48#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
45#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */ 49#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
46 50
47/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff 51/*
48 * and they tell the kernel that so we have to think of it as two parts. */ 52 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
53 * and they tell the kernel that so we have to think of it as two parts.
54 */
49#define EC_HOST_CMD_REGION0 0x800 55#define EC_HOST_CMD_REGION0 0x800
50#define EC_HOST_CMD_REGION1 0x880 56#define EC_HOST_CMD_REGION1 0x880
51#define EC_HOST_CMD_REGION_SIZE 0x80 57#define EC_HOST_CMD_REGION_SIZE 0x80
52 58
53/* EC command register bit functions */ 59/* EC command register bit functions */
54#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */ 60#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
55#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */ 61#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
56#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */ 62#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
57#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */ 63#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
58#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */ 64#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
59#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */ 65#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
60#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */ 66#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
61 67
62#define EC_LPC_ADDR_MEMMAP 0x900 68#define EC_LPC_ADDR_MEMMAP 0x900
63#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */ 69#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
@@ -77,13 +83,15 @@
77/* Unused 0x28 - 0x2f */ 83/* Unused 0x28 - 0x2f */
78#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */ 84#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
79/* Unused 0x31 - 0x33 */ 85/* Unused 0x31 - 0x33 */
80#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */ 86#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
81/* Reserve 0x38 - 0x3f for additional host event-related stuff */ 87/* Battery values are all 32 bits, unless otherwise noted. */
82/* Battery values are all 32 bits */
83#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ 88#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
84#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ 89#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
85#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ 90#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
86#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */ 91#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
92#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
93#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
94/* Unused 0x4f */
87#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */ 95#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
88#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ 96#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
89#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ 97#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
@@ -97,15 +105,24 @@
97/* Unused 0x84 - 0x8f */ 105/* Unused 0x84 - 0x8f */
98#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/ 106#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
99/* Unused 0x91 */ 107/* Unused 0x91 */
100#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */ 108#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
109/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
110/* 0x94 - 0x99: 1st Accelerometer */
111/* 0x9a - 0x9f: 2nd Accelerometer */
101#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */ 112#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
102/* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */ 113/* Unused 0xa6 - 0xdf */
103 114
115/*
116 * ACPI is unable to access memory mapped data at or above this offset due to
117 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
118 * which might be needed by ACPI.
119 */
120#define EC_MEMMAP_NO_ACPI 0xe0
104 121
105/* Define the format of the accelerometer mapped memory status byte. */ 122/* Define the format of the accelerometer mapped memory status byte. */
106#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f 123#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
107#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4) 124#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
108#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7) 125#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
109 126
110/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ 127/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
111#define EC_TEMP_SENSOR_ENTRIES 16 128#define EC_TEMP_SENSOR_ENTRIES 16
@@ -149,6 +166,8 @@
149#define EC_BATT_FLAG_DISCHARGING 0x04 166#define EC_BATT_FLAG_DISCHARGING 0x04
150#define EC_BATT_FLAG_CHARGING 0x08 167#define EC_BATT_FLAG_CHARGING 0x08
151#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10 168#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
169/* Set if some of the static/dynamic data is invalid (or outdated). */
170#define EC_BATT_FLAG_INVALID_DATA 0x20
152 171
153/* Switch flags at EC_MEMMAP_SWITCHES */ 172/* Switch flags at EC_MEMMAP_SWITCHES */
154#define EC_SWITCH_LID_OPEN 0x01 173#define EC_SWITCH_LID_OPEN 0x01
@@ -174,20 +193,242 @@
174#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */ 193#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
175#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */ 194#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
176 195
196/*****************************************************************************/
197/*
198 * ACPI commands
199 *
200 * These are valid ONLY on the ACPI command/data port.
201 */
202
203/*
204 * ACPI Read Embedded Controller
205 *
206 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
207 *
208 * Use the following sequence:
209 *
210 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
211 * - Wait for EC_LPC_CMDR_PENDING bit to clear
212 * - Write address to EC_LPC_ADDR_ACPI_DATA
213 * - Wait for EC_LPC_CMDR_DATA bit to set
214 * - Read value from EC_LPC_ADDR_ACPI_DATA
215 */
216#define EC_CMD_ACPI_READ 0x0080
217
218/*
219 * ACPI Write Embedded Controller
220 *
221 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
222 *
223 * Use the following sequence:
224 *
225 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
226 * - Wait for EC_LPC_CMDR_PENDING bit to clear
227 * - Write address to EC_LPC_ADDR_ACPI_DATA
228 * - Wait for EC_LPC_CMDR_PENDING bit to clear
229 * - Write value to EC_LPC_ADDR_ACPI_DATA
230 */
231#define EC_CMD_ACPI_WRITE 0x0081
232
233/*
234 * ACPI Burst Enable Embedded Controller
235 *
236 * This enables burst mode on the EC to allow the host to issue several
237 * commands back-to-back. While in this mode, writes to mapped multi-byte
238 * data are locked out to ensure data consistency.
239 */
240#define EC_CMD_ACPI_BURST_ENABLE 0x0082
241
242/*
243 * ACPI Burst Disable Embedded Controller
244 *
245 * This disables burst mode on the EC and stops preventing EC writes to mapped
246 * multi-byte data.
247 */
248#define EC_CMD_ACPI_BURST_DISABLE 0x0083
249
250/*
251 * ACPI Query Embedded Controller
252 *
253 * This clears the lowest-order bit in the currently pending host events, and
254 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
255 * event 0x80000000 = 32), or 0 if no event was pending.
256 */
257#define EC_CMD_ACPI_QUERY_EVENT 0x0084
258
259/* Valid addresses in ACPI memory space, for read/write commands */
260
261/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
262#define EC_ACPI_MEM_VERSION 0x00
263/*
264 * Test location; writing value here updates test compliment byte to (0xff -
265 * value).
266 */
267#define EC_ACPI_MEM_TEST 0x01
268/* Test compliment; writes here are ignored. */
269#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
270
271/* Keyboard backlight brightness percent (0 - 100) */
272#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
273/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
274#define EC_ACPI_MEM_FAN_DUTY 0x04
275
276/*
277 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
278 * independent thresholds attached to them. The current value of the ID
279 * register determines which sensor is affected by the THRESHOLD and COMMIT
280 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
281 * as the memory-mapped sensors. The COMMIT register applies those settings.
282 *
283 * The spec does not mandate any way to read back the threshold settings
284 * themselves, but when a threshold is crossed the AP needs a way to determine
285 * which sensor(s) are responsible. Each reading of the ID register clears and
286 * returns one sensor ID that has crossed one of its threshold (in either
287 * direction) since the last read. A value of 0xFF means "no new thresholds
288 * have tripped". Setting or enabling the thresholds for a sensor will clear
289 * the unread event count for that sensor.
290 */
291#define EC_ACPI_MEM_TEMP_ID 0x05
292#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
293#define EC_ACPI_MEM_TEMP_COMMIT 0x07
294/*
295 * Here are the bits for the COMMIT register:
296 * bit 0 selects the threshold index for the chosen sensor (0/1)
297 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
298 * Each write to the commit register affects one threshold.
299 */
300#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
301#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
302/*
303 * Example:
304 *
305 * Set the thresholds for sensor 2 to 50 C and 60 C:
306 * write 2 to [0x05] -- select temp sensor 2
307 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
308 * write 0x2 to [0x07] -- enable threshold 0 with this value
309 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
310 * write 0x3 to [0x07] -- enable threshold 1 with this value
311 *
312 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
313 * write 2 to [0x05] -- select temp sensor 2
314 * write 0x1 to [0x07] -- disable threshold 1
315 */
316
317/* DPTF battery charging current limit */
318#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
319
320/* Charging limit is specified in 64 mA steps */
321#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
322/* Value to disable DPTF battery charging limit */
323#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
324
325/*
326 * Report device orientation
327 * Bits Definition
328 * 3:1 Device DPTF Profile Number (DDPN)
329 * 0 = Reserved for backward compatibility (indicates no valid
330 * profile number. Host should fall back to using TBMD).
331 * 1..7 = DPTF Profile number to indicate to host which table needs
332 * to be loaded.
333 * 0 Tablet Mode Device Indicator (TBMD)
334 */
335#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
336#define EC_ACPI_MEM_TBMD_SHIFT 0
337#define EC_ACPI_MEM_TBMD_MASK 0x1
338#define EC_ACPI_MEM_DDPN_SHIFT 1
339#define EC_ACPI_MEM_DDPN_MASK 0x7
340
341/*
342 * Report device features. Uses the same format as the host command, except:
343 *
344 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
345 * of features", which is of limited interest when the system is already
346 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
347 * these are supported, it defaults to 0.
348 * This allows detecting the presence of this field since older versions of
349 * the EC codebase would simply return 0xff to that unknown address. Check
350 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
351 * are valid.
352 */
353#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
354#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
355#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
356#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
357#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
358#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
359#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
360#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
361
362#define EC_ACPI_MEM_BATTERY_INDEX 0x12
363
364/*
365 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
366 * is enabled (1) or disabled (0).
367 * bit 0 USB port ID 0
368 * ...
369 * bit 7 USB port ID 7
370 */
371#define EC_ACPI_MEM_USB_PORT_POWER 0x13
372
373/*
374 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
375 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
376 */
377#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
378#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
379
380/* Current version of ACPI memory address space */
381#define EC_ACPI_MEM_VERSION_CURRENT 2
382
383
177/* 384/*
178 * This header file is used in coreboot both in C and ACPI code. The ACPI code 385 * This header file is used in coreboot both in C and ACPI code. The ACPI code
179 * is pre-processed to handle constants but the ASL compiler is unable to 386 * is pre-processed to handle constants but the ASL compiler is unable to
180 * handle actual C code so keep it separate. 387 * handle actual C code so keep it separate.
181 */ 388 */
182#ifndef __ACPI__ 389
183 390
184/* 391/*
185 * Define __packed if someone hasn't beat us to it. Linux kernel style 392 * Attributes for EC request and response packets. Just defining __packed
186 * checking prefers __packed over __attribute__((packed)). 393 * results in inefficient assembly code on ARM, if the structure is actually
394 * 32-bit aligned, as it should be for all buffers.
395 *
396 * Be very careful when adding these to existing structures. They will round
397 * up the structure size to the specified boundary.
398 *
399 * Also be very careful to make that if a structure is included in some other
400 * parent structure that the alignment will still be true given the packing of
401 * the parent structure. This is particularly important if the sub-structure
402 * will be passed as a pointer to another function, since that function will
403 * not know about the misaligment caused by the parent structure's packing.
404 *
405 * Also be very careful using __packed - particularly when nesting non-packed
406 * structures inside packed ones. In fact, DO NOT use __packed directly;
407 * always use one of these attributes.
408 *
409 * Once everything is annotated properly, the following search strings should
410 * not return ANY matches in this file other than right here:
411 *
412 * "__packed" - generates inefficient code; all sub-structs must also be packed
413 *
414 * "struct [^_]" - all structs should be annotated, except for structs that are
415 * members of other structs/unions (and their original declarations should be
416 * annotated).
417 */
418
419/*
420 * Packed structures make no assumption about alignment, so they do inefficient
421 * byte-wise reads.
187 */ 422 */
188#ifndef __packed 423#define __ec_align1 __packed
189#define __packed __attribute__((packed)) 424#define __ec_align2 __packed
190#endif 425#define __ec_align4 __packed
426#define __ec_align_size1 __packed
427#define __ec_align_offset1 __packed
428#define __ec_align_offset2 __packed
429#define __ec_todo_packed __packed
430#define __ec_todo_unpacked
431
191 432
192/* LPC command status byte masks */ 433/* LPC command status byte masks */
193/* EC has written a byte in the data register and host hasn't read it yet */ 434/* EC has written a byte in the data register and host hasn't read it yet */
@@ -198,7 +439,7 @@
198#define EC_LPC_STATUS_PROCESSING 0x04 439#define EC_LPC_STATUS_PROCESSING 0x04
199/* Last write to EC was a command, not data */ 440/* Last write to EC was a command, not data */
200#define EC_LPC_STATUS_LAST_CMD 0x08 441#define EC_LPC_STATUS_LAST_CMD 0x08
201/* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */ 442/* EC is in burst mode */
202#define EC_LPC_STATUS_BURST_MODE 0x10 443#define EC_LPC_STATUS_BURST_MODE 0x10
203/* SCI event is pending (requesting SCI query) */ 444/* SCI event is pending (requesting SCI query) */
204#define EC_LPC_STATUS_SCI_PENDING 0x20 445#define EC_LPC_STATUS_SCI_PENDING 0x20
@@ -214,7 +455,10 @@
214#define EC_LPC_STATUS_BUSY_MASK \ 455#define EC_LPC_STATUS_BUSY_MASK \
215 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING) 456 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
216 457
217/* Host command response codes */ 458/*
459 * Host command response codes (16-bit). Note that response codes should be
460 * stored in a uint16_t rather than directly in a value of this type.
461 */
218enum ec_status { 462enum ec_status {
219 EC_RES_SUCCESS = 0, 463 EC_RES_SUCCESS = 0,
220 EC_RES_INVALID_COMMAND = 1, 464 EC_RES_INVALID_COMMAND = 1,
@@ -230,7 +474,13 @@ enum ec_status {
230 EC_RES_OVERFLOW = 11, /* Table / data overflow */ 474 EC_RES_OVERFLOW = 11, /* Table / data overflow */
231 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */ 475 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
232 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */ 476 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
233 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */ 477 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
478 EC_RES_BUS_ERROR = 15, /* Communications bus error */
479 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
480 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
481 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
482 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
483 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
234}; 484};
235 485
236/* 486/*
@@ -250,7 +500,8 @@ enum host_event_code {
250 EC_HOST_EVENT_BATTERY_CRITICAL = 7, 500 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
251 EC_HOST_EVENT_BATTERY = 8, 501 EC_HOST_EVENT_BATTERY = 8,
252 EC_HOST_EVENT_THERMAL_THRESHOLD = 9, 502 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
253 EC_HOST_EVENT_THERMAL_OVERLOAD = 10, 503 /* Event generated by a device attached to the EC */
504 EC_HOST_EVENT_DEVICE = 10,
254 EC_HOST_EVENT_THERMAL = 11, 505 EC_HOST_EVENT_THERMAL = 11,
255 EC_HOST_EVENT_USB_CHARGER = 12, 506 EC_HOST_EVENT_USB_CHARGER = 12,
256 EC_HOST_EVENT_KEY_PRESSED = 13, 507 EC_HOST_EVENT_KEY_PRESSED = 13,
@@ -277,15 +528,34 @@ enum host_event_code {
277 EC_HOST_EVENT_HANG_DETECT = 20, 528 EC_HOST_EVENT_HANG_DETECT = 20,
278 /* Hang detect logic detected a hang and warm rebooted the AP */ 529 /* Hang detect logic detected a hang and warm rebooted the AP */
279 EC_HOST_EVENT_HANG_REBOOT = 21, 530 EC_HOST_EVENT_HANG_REBOOT = 21,
531
280 /* PD MCU triggering host event */ 532 /* PD MCU triggering host event */
281 EC_HOST_EVENT_PD_MCU = 22, 533 EC_HOST_EVENT_PD_MCU = 22,
282 534
283 /* EC desires to change state of host-controlled USB mux */ 535 /* Battery Status flags have changed */
284 EC_HOST_EVENT_USB_MUX = 28, 536 EC_HOST_EVENT_BATTERY_STATUS = 23,
537
538 /* EC encountered a panic, triggering a reset */
539 EC_HOST_EVENT_PANIC = 24,
540
541 /* Keyboard fastboot combo has been pressed */
542 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
285 543
286 /* EC RTC event occurred */ 544 /* EC RTC event occurred */
287 EC_HOST_EVENT_RTC = 26, 545 EC_HOST_EVENT_RTC = 26,
288 546
547 /* Emulate MKBP event */
548 EC_HOST_EVENT_MKBP = 27,
549
550 /* EC desires to change state of host-controlled USB mux */
551 EC_HOST_EVENT_USB_MUX = 28,
552
553 /* TABLET/LAPTOP mode or detachable base attach/detach event */
554 EC_HOST_EVENT_MODE_CHANGE = 29,
555
556 /* Keyboard recovery combo with hardware reinitialization */
557 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
558
289 /* 559 /*
290 * The high bit of the event mask is not used as a host event code. If 560 * The high bit of the event mask is not used as a host event code. If
291 * it reads back as set, then the entire event mask should be 561 * it reads back as set, then the entire event mask should be
@@ -296,7 +566,7 @@ enum host_event_code {
296 EC_HOST_EVENT_INVALID = 32 566 EC_HOST_EVENT_INVALID = 32
297}; 567};
298/* Host event mask */ 568/* Host event mask */
299#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1)) 569#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
300 570
301/** 571/**
302 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS 572 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
@@ -311,7 +581,7 @@ struct ec_lpc_host_args {
311 uint8_t command_version; 581 uint8_t command_version;
312 uint8_t data_size; 582 uint8_t data_size;
313 uint8_t checksum; 583 uint8_t checksum;
314} __packed; 584} __ec_align4;
315 585
316/* Flags for ec_lpc_host_args.flags */ 586/* Flags for ec_lpc_host_args.flags */
317/* 587/*
@@ -321,7 +591,7 @@ struct ec_lpc_host_args {
321 * If EC gets a command and this flag is not set, this is an old-style command. 591 * If EC gets a command and this flag is not set, this is an old-style command.
322 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with 592 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
323 * unknown length. EC must respond with an old-style response (that is, 593 * unknown length. EC must respond with an old-style response (that is,
324 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST). 594 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
325 */ 595 */
326#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01 596#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
327/* 597/*
@@ -482,7 +752,7 @@ struct ec_host_request {
482 uint8_t command_version; 752 uint8_t command_version;
483 uint8_t reserved; 753 uint8_t reserved;
484 uint16_t data_len; 754 uint16_t data_len;
485} __packed; 755} __ec_align4;
486 756
487#define EC_HOST_RESPONSE_VERSION 3 757#define EC_HOST_RESPONSE_VERSION 3
488 758
@@ -501,18 +771,151 @@ struct ec_host_response {
501 uint16_t result; 771 uint16_t result;
502 uint16_t data_len; 772 uint16_t data_len;
503 uint16_t reserved; 773 uint16_t reserved;
504} __packed; 774} __ec_align4;
775
776/*****************************************************************************/
777
778/*
779 * Host command protocol V4.
780 *
781 * Packets always start with a request or response header. They are followed
782 * by data_len bytes of data. If the data_crc_present flag is set, the data
783 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
784 * polynomial.
785 *
786 * Host algorithm when sending a request q:
787 *
788 * 101) tries_left=(some value, e.g. 3);
789 * 102) q.seq_num++
790 * 103) q.seq_dup=0
791 * 104) Calculate q.header_crc.
792 * 105) Send request q to EC.
793 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
794 *
795 * 201) If r.struct_version != 4, go to 301.
796 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
797 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
798 * 204) If r.seq_num != q.seq_num, go to 301.
799 * 205) If r.seq_dup == q.seq_dup, return success.
800 * 207) If r.seq_dup == 1, go to 301.
801 * 208) Return error.
802 *
803 * 301) If --tries_left <= 0, return error.
804 * 302) If q.seq_dup == 1, go to 105.
805 * 303) q.seq_dup = 1
806 * 304) Go to 104.
807 *
808 * EC algorithm when receiving a request q.
809 * EC has response buffer r, error buffer e.
810 *
811 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
812 * and go to 301
813 * 102) If q.header_crc mismatches calculated CRC, set e.result =
814 * EC_RES_INVALID_HEADER_CRC and go to 301
815 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
816 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
817 * and go to 301.
818 * 104) If q.seq_dup == 0, go to 201.
819 * 105) If q.seq_num != r.seq_num, go to 201.
820 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
821 *
822 * 201) Process request q into response r.
823 * 202) r.seq_num = q.seq_num
824 * 203) r.seq_dup = q.seq_dup
825 * 204) Calculate r.header_crc
826 * 205) If r.data_len > 0 and data is no longer available, set e.result =
827 * EC_RES_DUP_UNAVAILABLE and go to 301.
828 * 206) Send response r.
829 *
830 * 301) e.seq_num = q.seq_num
831 * 302) e.seq_dup = q.seq_dup
832 * 303) Calculate e.header_crc.
833 * 304) Send error response e.
834 */
835
836/* Version 4 request from host */
837struct ec_host_request4 {
838 /*
839 * bits 0-3: struct_version: Structure version (=4)
840 * bit 4: is_response: Is response (=0)
841 * bits 5-6: seq_num: Sequence number
842 * bit 7: seq_dup: Sequence duplicate flag
843 */
844 uint8_t fields0;
845
846 /*
847 * bits 0-4: command_version: Command version
848 * bits 5-6: Reserved (set 0, ignore on read)
849 * bit 7: data_crc_present: Is data CRC present after data
850 */
851 uint8_t fields1;
852
853 /* Command code (EC_CMD_*) */
854 uint16_t command;
855
856 /* Length of data which follows this header (not including data CRC) */
857 uint16_t data_len;
858
859 /* Reserved (set 0, ignore on read) */
860 uint8_t reserved;
861
862 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
863 uint8_t header_crc;
864} __ec_align4;
865
866/* Version 4 response from EC */
867struct ec_host_response4 {
868 /*
869 * bits 0-3: struct_version: Structure version (=4)
870 * bit 4: is_response: Is response (=1)
871 * bits 5-6: seq_num: Sequence number
872 * bit 7: seq_dup: Sequence duplicate flag
873 */
874 uint8_t fields0;
875
876 /*
877 * bits 0-6: Reserved (set 0, ignore on read)
878 * bit 7: data_crc_present: Is data CRC present after data
879 */
880 uint8_t fields1;
881
882 /* Result code (EC_RES_*) */
883 uint16_t result;
884
885 /* Length of data which follows this header (not including data CRC) */
886 uint16_t data_len;
887
888 /* Reserved (set 0, ignore on read) */
889 uint8_t reserved;
890
891 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
892 uint8_t header_crc;
893} __ec_align4;
894
895/* Fields in fields0 byte */
896#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
897#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
898#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
899#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
900#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
901
902/* Fields in fields1 byte */
903#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
904#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
505 905
506/*****************************************************************************/ 906/*****************************************************************************/
507/* 907/*
508 * Notes on commands: 908 * Notes on commands:
509 * 909 *
510 * Each command is an 16-bit command value. Commands which take params or 910 * Each command is an 16-bit command value. Commands which take params or
511 * return response data specify structs for that data. If no struct is 911 * return response data specify structures for that data. If no structure is
512 * specified, the command does not input or output data, respectively. 912 * specified, the command does not input or output data, respectively.
513 * Parameter/response length is implicit in the structs. Some underlying 913 * Parameter/response length is implicit in the structs. Some underlying
514 * communication protocols (I2C, SPI) may add length or checksum headers, but 914 * communication protocols (I2C, SPI) may add length or checksum headers, but
515 * those are implementation-dependent and not defined here. 915 * those are implementation-dependent and not defined here.
916 *
917 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
918 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
516 */ 919 */
517 920
518/*****************************************************************************/ 921/*****************************************************************************/
@@ -522,7 +925,7 @@ struct ec_host_response {
522 * Get protocol version, used to deal with non-backward compatible protocol 925 * Get protocol version, used to deal with non-backward compatible protocol
523 * changes. 926 * changes.
524 */ 927 */
525#define EC_CMD_PROTO_VERSION 0x00 928#define EC_CMD_PROTO_VERSION 0x0000
526 929
527/** 930/**
528 * struct ec_response_proto_version - Response to the proto version command. 931 * struct ec_response_proto_version - Response to the proto version command.
@@ -530,13 +933,13 @@ struct ec_host_response {
530 */ 933 */
531struct ec_response_proto_version { 934struct ec_response_proto_version {
532 uint32_t version; 935 uint32_t version;
533} __packed; 936} __ec_align4;
534 937
535/* 938/*
536 * Hello. This is a simple command to test the EC is responsive to 939 * Hello. This is a simple command to test the EC is responsive to
537 * commands. 940 * commands.
538 */ 941 */
539#define EC_CMD_HELLO 0x01 942#define EC_CMD_HELLO 0x0001
540 943
541/** 944/**
542 * struct ec_params_hello - Parameters to the hello command. 945 * struct ec_params_hello - Parameters to the hello command.
@@ -544,7 +947,7 @@ struct ec_response_proto_version {
544 */ 947 */
545struct ec_params_hello { 948struct ec_params_hello {
546 uint32_t in_data; 949 uint32_t in_data;
547} __packed; 950} __ec_align4;
548 951
549/** 952/**
550 * struct ec_response_hello - Response to the hello command. 953 * struct ec_response_hello - Response to the hello command.
@@ -552,10 +955,10 @@ struct ec_params_hello {
552 */ 955 */
553struct ec_response_hello { 956struct ec_response_hello {
554 uint32_t out_data; 957 uint32_t out_data;
555} __packed; 958} __ec_align4;
556 959
557/* Get version number */ 960/* Get version number */
558#define EC_CMD_GET_VERSION 0x02 961#define EC_CMD_GET_VERSION 0x0002
559 962
560enum ec_current_image { 963enum ec_current_image {
561 EC_IMAGE_UNKNOWN = 0, 964 EC_IMAGE_UNKNOWN = 0,
@@ -575,10 +978,10 @@ struct ec_response_get_version {
575 char version_string_rw[32]; 978 char version_string_rw[32];
576 char reserved[32]; 979 char reserved[32];
577 uint32_t current_image; 980 uint32_t current_image;
578} __packed; 981} __ec_align4;
579 982
580/* Read test */ 983/* Read test */
581#define EC_CMD_READ_TEST 0x03 984#define EC_CMD_READ_TEST 0x0003
582 985
583/** 986/**
584 * struct ec_params_read_test - Parameters for the read test command. 987 * struct ec_params_read_test - Parameters for the read test command.
@@ -588,7 +991,7 @@ struct ec_response_get_version {
588struct ec_params_read_test { 991struct ec_params_read_test {
589 uint32_t offset; 992 uint32_t offset;
590 uint32_t size; 993 uint32_t size;
591} __packed; 994} __ec_align4;
592 995
593/** 996/**
594 * struct ec_response_read_test - Response to the read test command. 997 * struct ec_response_read_test - Response to the read test command.
@@ -596,17 +999,17 @@ struct ec_params_read_test {
596 */ 999 */
597struct ec_response_read_test { 1000struct ec_response_read_test {
598 uint32_t data[32]; 1001 uint32_t data[32];
599} __packed; 1002} __ec_align4;
600 1003
601/* 1004/*
602 * Get build information 1005 * Get build information
603 * 1006 *
604 * Response is null-terminated string. 1007 * Response is null-terminated string.
605 */ 1008 */
606#define EC_CMD_GET_BUILD_INFO 0x04 1009#define EC_CMD_GET_BUILD_INFO 0x0004
607 1010
608/* Get chip info */ 1011/* Get chip info */
609#define EC_CMD_GET_CHIP_INFO 0x05 1012#define EC_CMD_GET_CHIP_INFO 0x0005
610 1013
611/** 1014/**
612 * struct ec_response_get_chip_info - Response to the get chip info command. 1015 * struct ec_response_get_chip_info - Response to the get chip info command.
@@ -618,10 +1021,10 @@ struct ec_response_get_chip_info {
618 char vendor[32]; 1021 char vendor[32];
619 char name[32]; 1022 char name[32];
620 char revision[32]; 1023 char revision[32];
621} __packed; 1024} __ec_align4;
622 1025
623/* Get board HW version */ 1026/* Get board HW version */
624#define EC_CMD_GET_BOARD_VERSION 0x06 1027#define EC_CMD_GET_BOARD_VERSION 0x0006
625 1028
626/** 1029/**
627 * struct ec_response_board_version - Response to the board version command. 1030 * struct ec_response_board_version - Response to the board version command.
@@ -629,7 +1032,7 @@ struct ec_response_get_chip_info {
629 */ 1032 */
630struct ec_response_board_version { 1033struct ec_response_board_version {
631 uint16_t board_version; 1034 uint16_t board_version;
632} __packed; 1035} __ec_align2;
633 1036
634/* 1037/*
635 * Read memory-mapped data. 1038 * Read memory-mapped data.
@@ -639,7 +1042,7 @@ struct ec_response_board_version {
639 * 1042 *
640 * Response is params.size bytes of data. 1043 * Response is params.size bytes of data.
641 */ 1044 */
642#define EC_CMD_READ_MEMMAP 0x07 1045#define EC_CMD_READ_MEMMAP 0x0007
643 1046
644/** 1047/**
645 * struct ec_params_read_memmap - Parameters for the read memory map command. 1048 * struct ec_params_read_memmap - Parameters for the read memory map command.
@@ -649,10 +1052,10 @@ struct ec_response_board_version {
649struct ec_params_read_memmap { 1052struct ec_params_read_memmap {
650 uint8_t offset; 1053 uint8_t offset;
651 uint8_t size; 1054 uint8_t size;
652} __packed; 1055} __ec_align1;
653 1056
654/* Read versions supported for a command */ 1057/* Read versions supported for a command */
655#define EC_CMD_GET_CMD_VERSIONS 0x08 1058#define EC_CMD_GET_CMD_VERSIONS 0x0008
656 1059
657/** 1060/**
658 * struct ec_params_get_cmd_versions - Parameters for the get command versions. 1061 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
@@ -660,7 +1063,7 @@ struct ec_params_read_memmap {
660 */ 1063 */
661struct ec_params_get_cmd_versions { 1064struct ec_params_get_cmd_versions {
662 uint8_t cmd; 1065 uint8_t cmd;
663} __packed; 1066} __ec_align1;
664 1067
665/** 1068/**
666 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command 1069 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
@@ -669,7 +1072,7 @@ struct ec_params_get_cmd_versions {
669 */ 1072 */
670struct ec_params_get_cmd_versions_v1 { 1073struct ec_params_get_cmd_versions_v1 {
671 uint16_t cmd; 1074 uint16_t cmd;
672} __packed; 1075} __ec_align2;
673 1076
674/** 1077/**
675 * struct ec_response_get_cmd_version - Response to the get command versions. 1078 * struct ec_response_get_cmd_version - Response to the get command versions.
@@ -678,20 +1081,20 @@ struct ec_params_get_cmd_versions_v1 {
678 */ 1081 */
679struct ec_response_get_cmd_versions { 1082struct ec_response_get_cmd_versions {
680 uint32_t version_mask; 1083 uint32_t version_mask;
681} __packed; 1084} __ec_align4;
682 1085
683/* 1086/*
684 * Check EC communcations status (busy). This is needed on i2c/spi but not 1087 * Check EC communications status (busy). This is needed on i2c/spi but not
685 * on lpc since it has its own out-of-band busy indicator. 1088 * on lpc since it has its own out-of-band busy indicator.
686 * 1089 *
687 * lpc must read the status from the command register. Attempting this on 1090 * lpc must read the status from the command register. Attempting this on
688 * lpc will overwrite the args/parameter space and corrupt its data. 1091 * lpc will overwrite the args/parameter space and corrupt its data.
689 */ 1092 */
690#define EC_CMD_GET_COMMS_STATUS 0x09 1093#define EC_CMD_GET_COMMS_STATUS 0x0009
691 1094
692/* Avoid using ec_status which is for return values */ 1095/* Avoid using ec_status which is for return values */
693enum ec_comms_status { 1096enum ec_comms_status {
694 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */ 1097 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
695}; 1098};
696 1099
697/** 1100/**
@@ -701,29 +1104,29 @@ enum ec_comms_status {
701 */ 1104 */
702struct ec_response_get_comms_status { 1105struct ec_response_get_comms_status {
703 uint32_t flags; /* Mask of enum ec_comms_status */ 1106 uint32_t flags; /* Mask of enum ec_comms_status */
704} __packed; 1107} __ec_align4;
705 1108
706/* Fake a variety of responses, purely for testing purposes. */ 1109/* Fake a variety of responses, purely for testing purposes. */
707#define EC_CMD_TEST_PROTOCOL 0x0a 1110#define EC_CMD_TEST_PROTOCOL 0x000A
708 1111
709/* Tell the EC what to send back to us. */ 1112/* Tell the EC what to send back to us. */
710struct ec_params_test_protocol { 1113struct ec_params_test_protocol {
711 uint32_t ec_result; 1114 uint32_t ec_result;
712 uint32_t ret_len; 1115 uint32_t ret_len;
713 uint8_t buf[32]; 1116 uint8_t buf[32];
714} __packed; 1117} __ec_align4;
715 1118
716/* Here it comes... */ 1119/* Here it comes... */
717struct ec_response_test_protocol { 1120struct ec_response_test_protocol {
718 uint8_t buf[32]; 1121 uint8_t buf[32];
719} __packed; 1122} __ec_align4;
720 1123
721/* Get prococol information */ 1124/* Get protocol information */
722#define EC_CMD_GET_PROTOCOL_INFO 0x0b 1125#define EC_CMD_GET_PROTOCOL_INFO 0x000B
723 1126
724/* Flags for ec_response_get_protocol_info.flags */ 1127/* Flags for ec_response_get_protocol_info.flags */
725/* EC_RES_IN_PROGRESS may be returned if a command is slow */ 1128/* EC_RES_IN_PROGRESS may be returned if a command is slow */
726#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0) 1129#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
727 1130
728/** 1131/**
729 * struct ec_response_get_protocol_info - Response to the get protocol info. 1132 * struct ec_response_get_protocol_info - Response to the get protocol info.
@@ -739,7 +1142,7 @@ struct ec_response_get_protocol_info {
739 uint16_t max_request_packet_size; 1142 uint16_t max_request_packet_size;
740 uint16_t max_response_packet_size; 1143 uint16_t max_response_packet_size;
741 uint32_t flags; 1144 uint32_t flags;
742} __packed; 1145} __ec_align4;
743 1146
744 1147
745/*****************************************************************************/ 1148/*****************************************************************************/
@@ -757,19 +1160,19 @@ struct ec_response_get_protocol_info {
757struct ec_params_get_set_value { 1160struct ec_params_get_set_value {
758 uint32_t flags; 1161 uint32_t flags;
759 uint32_t value; 1162 uint32_t value;
760} __packed; 1163} __ec_align4;
761 1164
762struct ec_response_get_set_value { 1165struct ec_response_get_set_value {
763 uint32_t flags; 1166 uint32_t flags;
764 uint32_t value; 1167 uint32_t value;
765} __packed; 1168} __ec_align4;
766 1169
767/* More than one command can use these structs to get/set paramters. */ 1170/* More than one command can use these structs to get/set parameters. */
768#define EC_CMD_GSV_PAUSE_IN_S5 0x0c 1171#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
769 1172
770/*****************************************************************************/ 1173/*****************************************************************************/
771/* List the features supported by the firmware */ 1174/* List the features supported by the firmware */
772#define EC_CMD_GET_FEATURES 0x0d 1175#define EC_CMD_GET_FEATURES 0x000D
773 1176
774/* Supported features */ 1177/* Supported features */
775enum ec_feature_code { 1178enum ec_feature_code {
@@ -876,24 +1279,36 @@ enum ec_feature_code {
876 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37, 1279 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
877 /* EC supports audio codec. */ 1280 /* EC supports audio codec. */
878 EC_FEATURE_AUDIO_CODEC = 38, 1281 EC_FEATURE_AUDIO_CODEC = 38,
879 /* EC Supports SCP. */ 1282 /* The MCU is a System Companion Processor (SCP). */
880 EC_FEATURE_SCP = 39, 1283 EC_FEATURE_SCP = 39,
881 /* The MCU is an Integrated Sensor Hub */ 1284 /* The MCU is an Integrated Sensor Hub */
882 EC_FEATURE_ISH = 40, 1285 EC_FEATURE_ISH = 40,
883}; 1286};
884 1287
885#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32)) 1288#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
886#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32)) 1289#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
887 1290
888struct ec_response_get_features { 1291struct ec_response_get_features {
889 uint32_t flags[2]; 1292 uint32_t flags[2];
890} __packed; 1293} __ec_align4;
1294
1295/*****************************************************************************/
1296/* Get the board's SKU ID from EC */
1297#define EC_CMD_GET_SKU_ID 0x000E
1298
1299/* Set SKU ID from AP */
1300#define EC_CMD_SET_SKU_ID 0x000F
1301
1302struct ec_sku_id_info {
1303 uint32_t sku_id;
1304} __ec_align4;
891 1305
892/*****************************************************************************/ 1306/*****************************************************************************/
893/* Flash commands */ 1307/* Flash commands */
894 1308
895/* Get flash info */ 1309/* Get flash info */
896#define EC_CMD_FLASH_INFO 0x10 1310#define EC_CMD_FLASH_INFO 0x0010
1311#define EC_VER_FLASH_INFO 2
897 1312
898/** 1313/**
899 * struct ec_response_flash_info - Response to the flash info command. 1314 * struct ec_response_flash_info - Response to the flash info command.
@@ -912,11 +1327,22 @@ struct ec_response_flash_info {
912 uint32_t write_block_size; 1327 uint32_t write_block_size;
913 uint32_t erase_block_size; 1328 uint32_t erase_block_size;
914 uint32_t protect_block_size; 1329 uint32_t protect_block_size;
915} __packed; 1330} __ec_align4;
916 1331
917/* Flags for version 1+ flash info command */ 1332/*
918/* EC flash erases bits to 0 instead of 1 */ 1333 * Flags for version 1+ flash info command
919#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0) 1334 * EC flash erases bits to 0 instead of 1.
1335 */
1336#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
1337
1338/*
1339 * Flash must be selected for read/write/erase operations to succeed. This may
1340 * be necessary on a chip where write/erase can be corrupted by other board
1341 * activity, or where the chip needs to enable some sort of programming voltage,
1342 * or where the read/write/erase operations require cleanly suspending other
1343 * chip functionality.
1344 */
1345#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
920 1346
921/** 1347/**
922 * struct ec_response_flash_info_1 - Response to the flash info v1 command. 1348 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
@@ -938,7 +1364,14 @@ struct ec_response_flash_info {
938 * fields following. 1364 * fields following.
939 * 1365 *
940 * gcc anonymous structs don't seem to get along with the __packed directive; 1366 * gcc anonymous structs don't seem to get along with the __packed directive;
941 * if they did we'd define the version 0 struct as a sub-struct of this one. 1367 * if they did we'd define the version 0 structure as a sub-structure of this
1368 * one.
1369 *
1370 * Version 2 supports flash banks of different sizes:
1371 * The caller specified the number of banks it has preallocated
1372 * (num_banks_desc)
1373 * The EC returns the number of banks describing the flash memory.
1374 * It adds banks descriptions up to num_banks_desc.
942 */ 1375 */
943struct ec_response_flash_info_1 { 1376struct ec_response_flash_info_1 {
944 /* Version 0 fields; see above for description */ 1377 /* Version 0 fields; see above for description */
@@ -950,14 +1383,50 @@ struct ec_response_flash_info_1 {
950 /* Version 1 adds these fields: */ 1383 /* Version 1 adds these fields: */
951 uint32_t write_ideal_size; 1384 uint32_t write_ideal_size;
952 uint32_t flags; 1385 uint32_t flags;
953} __packed; 1386} __ec_align4;
1387
1388struct ec_params_flash_info_2 {
1389 /* Number of banks to describe */
1390 uint16_t num_banks_desc;
1391 /* Reserved; set 0; ignore on read */
1392 uint8_t reserved[2];
1393} __ec_align4;
1394
1395struct ec_flash_bank {
1396 /* Number of sector is in this bank. */
1397 uint16_t count;
1398 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1399 uint8_t size_exp;
1400 /* Minimal write size for the sectors in this bank */
1401 uint8_t write_size_exp;
1402 /* Erase size for the sectors in this bank */
1403 uint8_t erase_size_exp;
1404 /* Size for write protection, usually identical to erase size. */
1405 uint8_t protect_size_exp;
1406 /* Reserved; set 0; ignore on read */
1407 uint8_t reserved[2];
1408};
1409
1410struct ec_response_flash_info_2 {
1411 /* Total flash in the EC. */
1412 uint32_t flash_size;
1413 /* Flags; see EC_FLASH_INFO_* */
1414 uint32_t flags;
1415 /* Maximum size to use to send data to write to the EC. */
1416 uint32_t write_ideal_size;
1417 /* Number of banks present in the EC. */
1418 uint16_t num_banks_total;
1419 /* Number of banks described in banks array. */
1420 uint16_t num_banks_desc;
1421 struct ec_flash_bank banks[0];
1422} __ec_align4;
954 1423
955/* 1424/*
956 * Read flash 1425 * Read flash
957 * 1426 *
958 * Response is params.size bytes of data. 1427 * Response is params.size bytes of data.
959 */ 1428 */
960#define EC_CMD_FLASH_READ 0x11 1429#define EC_CMD_FLASH_READ 0x0011
961 1430
962/** 1431/**
963 * struct ec_params_flash_read - Parameters for the flash read command. 1432 * struct ec_params_flash_read - Parameters for the flash read command.
@@ -967,10 +1436,10 @@ struct ec_response_flash_info_1 {
967struct ec_params_flash_read { 1436struct ec_params_flash_read {
968 uint32_t offset; 1437 uint32_t offset;
969 uint32_t size; 1438 uint32_t size;
970} __packed; 1439} __ec_align4;
971 1440
972/* Write flash */ 1441/* Write flash */
973#define EC_CMD_FLASH_WRITE 0x12 1442#define EC_CMD_FLASH_WRITE 0x0012
974#define EC_VER_FLASH_WRITE 1 1443#define EC_VER_FLASH_WRITE 1
975 1444
976/* Version 0 of the flash command supported only 64 bytes of data */ 1445/* Version 0 of the flash command supported only 64 bytes of data */
@@ -985,20 +1454,57 @@ struct ec_params_flash_write {
985 uint32_t offset; 1454 uint32_t offset;
986 uint32_t size; 1455 uint32_t size;
987 /* Followed by data to write */ 1456 /* Followed by data to write */
988} __packed; 1457} __ec_align4;
989 1458
990/* Erase flash */ 1459/* Erase flash */
991#define EC_CMD_FLASH_ERASE 0x13 1460#define EC_CMD_FLASH_ERASE 0x0013
992 1461
993/** 1462/**
994 * struct ec_params_flash_erase - Parameters for the flash erase command. 1463 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
995 * @offset: Byte offset to erase. 1464 * @offset: Byte offset to erase.
996 * @size: Size to erase in bytes. 1465 * @size: Size to erase in bytes.
997 */ 1466 */
998struct ec_params_flash_erase { 1467struct ec_params_flash_erase {
999 uint32_t offset; 1468 uint32_t offset;
1000 uint32_t size; 1469 uint32_t size;
1001} __packed; 1470} __ec_align4;
1471
1472/*
1473 * v1 add async erase:
1474 * subcommands can returns:
1475 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1476 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1477 * EC_RES_ERROR : other errors.
1478 * EC_RES_BUSY : an existing erase operation is in progress.
1479 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1480 *
1481 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1482 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1483 * the proper result.
1484 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1485 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1486 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1487 * permitted while erasing. (For instance, STM32F4).
1488 */
1489enum ec_flash_erase_cmd {
1490 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1491 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1492 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1493};
1494
1495/**
1496 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1497 * @cmd: One of ec_flash_erase_cmd.
1498 * @reserved: Pad byte; currently always contains 0.
1499 * @flag: No flags defined yet; set to 0.
1500 * @params: Same as v0 parameters.
1501 */
1502struct ec_params_flash_erase_v1 {
1503 uint8_t cmd;
1504 uint8_t reserved;
1505 uint16_t flag;
1506 struct ec_params_flash_erase params;
1507} __ec_align4;
1002 1508
1003/* 1509/*
1004 * Get/set flash protection. 1510 * Get/set flash protection.
@@ -1010,31 +1516,40 @@ struct ec_params_flash_erase {
1010 * 1516 *
1011 * If mask=0, simply returns the current flags state. 1517 * If mask=0, simply returns the current flags state.
1012 */ 1518 */
1013#define EC_CMD_FLASH_PROTECT 0x15 1519#define EC_CMD_FLASH_PROTECT 0x0015
1014#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */ 1520#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1015 1521
1016/* Flags for flash protection */ 1522/* Flags for flash protection */
1017/* RO flash code protected when the EC boots */ 1523/* RO flash code protected when the EC boots */
1018#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0) 1524#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
1019/* 1525/*
1020 * RO flash code protected now. If this bit is set, at-boot status cannot 1526 * RO flash code protected now. If this bit is set, at-boot status cannot
1021 * be changed. 1527 * be changed.
1022 */ 1528 */
1023#define EC_FLASH_PROTECT_RO_NOW (1 << 1) 1529#define EC_FLASH_PROTECT_RO_NOW BIT(1)
1024/* Entire flash code protected now, until reboot. */ 1530/* Entire flash code protected now, until reboot. */
1025#define EC_FLASH_PROTECT_ALL_NOW (1 << 2) 1531#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
1026/* Flash write protect GPIO is asserted now */ 1532/* Flash write protect GPIO is asserted now */
1027#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3) 1533#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
1028/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */ 1534/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1029#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4) 1535#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
1030/* 1536/*
1031 * Error - flash protection is in inconsistent state. At least one bank of 1537 * Error - flash protection is in inconsistent state. At least one bank of
1032 * flash which should be protected is not protected. Usually fixed by 1538 * flash which should be protected is not protected. Usually fixed by
1033 * re-requesting the desired flags, or by a hard reset if that fails. 1539 * re-requesting the desired flags, or by a hard reset if that fails.
1034 */ 1540 */
1035#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5) 1541#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
1036/* Entile flash code protected when the EC boots */ 1542/* Entire flash code protected when the EC boots */
1037#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6) 1543#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
1544/* RW flash code protected when the EC boots */
1545#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
1546/* RW flash code protected now. */
1547#define EC_FLASH_PROTECT_RW_NOW BIT(8)
1548/* Rollback information flash region protected when the EC boots */
1549#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
1550/* Rollback information flash region protected now */
1551#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
1552
1038 1553
1039/** 1554/**
1040 * struct ec_params_flash_protect - Parameters for the flash protect command. 1555 * struct ec_params_flash_protect - Parameters for the flash protect command.
@@ -1044,7 +1559,7 @@ struct ec_params_flash_erase {
1044struct ec_params_flash_protect { 1559struct ec_params_flash_protect {
1045 uint32_t mask; 1560 uint32_t mask;
1046 uint32_t flags; 1561 uint32_t flags;
1047} __packed; 1562} __ec_align4;
1048 1563
1049/** 1564/**
1050 * struct ec_response_flash_protect - Response to the flash protect command. 1565 * struct ec_response_flash_protect - Response to the flash protect command.
@@ -1059,7 +1574,7 @@ struct ec_response_flash_protect {
1059 uint32_t flags; 1574 uint32_t flags;
1060 uint32_t valid_flags; 1575 uint32_t valid_flags;
1061 uint32_t writable_flags; 1576 uint32_t writable_flags;
1062} __packed; 1577} __ec_align4;
1063 1578
1064/* 1579/*
1065 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash 1580 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
@@ -1067,22 +1582,37 @@ struct ec_response_flash_protect {
1067 */ 1582 */
1068 1583
1069/* Get the region offset/size */ 1584/* Get the region offset/size */
1070#define EC_CMD_FLASH_REGION_INFO 0x16 1585#define EC_CMD_FLASH_REGION_INFO 0x0016
1071#define EC_VER_FLASH_REGION_INFO 1 1586#define EC_VER_FLASH_REGION_INFO 1
1072 1587
1073enum ec_flash_region { 1588enum ec_flash_region {
1074 /* Region which holds read-only EC image */ 1589 /* Region which holds read-only EC image */
1075 EC_FLASH_REGION_RO = 0, 1590 EC_FLASH_REGION_RO = 0,
1076 /* Region which holds rewritable EC image */ 1591 /*
1077 EC_FLASH_REGION_RW, 1592 * Region which holds active RW image. 'Active' is different from
1593 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1594 * scheduled to run, active/non-active applies only to RW images (for
1595 * the same reason 'update' applies only to RW images. It's a state of
1596 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1597 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1598 * doesn't enter 'running' state but it's still active on a flash.
1599 */
1600 EC_FLASH_REGION_ACTIVE,
1078 /* 1601 /*
1079 * Region which should be write-protected in the factory (a superset of 1602 * Region which should be write-protected in the factory (a superset of
1080 * EC_FLASH_REGION_RO) 1603 * EC_FLASH_REGION_RO)
1081 */ 1604 */
1082 EC_FLASH_REGION_WP_RO, 1605 EC_FLASH_REGION_WP_RO,
1606 /* Region which holds updatable (non-active) RW image */
1607 EC_FLASH_REGION_UPDATE,
1083 /* Number of regions */ 1608 /* Number of regions */
1084 EC_FLASH_REGION_COUNT, 1609 EC_FLASH_REGION_COUNT,
1085}; 1610};
1611/*
1612 * 'RW' is vague if there are multiple RW images; we mean the active one,
1613 * so the old constant is deprecated.
1614 */
1615#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
1086 1616
1087/** 1617/**
1088 * struct ec_params_flash_region_info - Parameters for the flash region info 1618 * struct ec_params_flash_region_info - Parameters for the flash region info
@@ -1091,15 +1621,15 @@ enum ec_flash_region {
1091 */ 1621 */
1092struct ec_params_flash_region_info { 1622struct ec_params_flash_region_info {
1093 uint32_t region; 1623 uint32_t region;
1094} __packed; 1624} __ec_align4;
1095 1625
1096struct ec_response_flash_region_info { 1626struct ec_response_flash_region_info {
1097 uint32_t offset; 1627 uint32_t offset;
1098 uint32_t size; 1628 uint32_t size;
1099} __packed; 1629} __ec_align4;
1100 1630
1101/* Read/write VbNvContext */ 1631/* Read/write VbNvContext */
1102#define EC_CMD_VBNV_CONTEXT 0x17 1632#define EC_CMD_VBNV_CONTEXT 0x0017
1103#define EC_VER_VBNV_CONTEXT 1 1633#define EC_VER_VBNV_CONTEXT 1
1104#define EC_VBNV_BLOCK_SIZE 16 1634#define EC_VBNV_BLOCK_SIZE 16
1105 1635
@@ -1111,52 +1641,99 @@ enum ec_vbnvcontext_op {
1111struct ec_params_vbnvcontext { 1641struct ec_params_vbnvcontext {
1112 uint32_t op; 1642 uint32_t op;
1113 uint8_t block[EC_VBNV_BLOCK_SIZE]; 1643 uint8_t block[EC_VBNV_BLOCK_SIZE];
1114} __packed; 1644} __ec_align4;
1115 1645
1116struct ec_response_vbnvcontext { 1646struct ec_response_vbnvcontext {
1117 uint8_t block[EC_VBNV_BLOCK_SIZE]; 1647 uint8_t block[EC_VBNV_BLOCK_SIZE];
1118} __packed; 1648} __ec_align4;
1649
1650
1651/* Get SPI flash information */
1652#define EC_CMD_FLASH_SPI_INFO 0x0018
1653
1654struct ec_response_flash_spi_info {
1655 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1656 uint8_t jedec[3];
1657
1658 /* Pad byte; currently always contains 0 */
1659 uint8_t reserved0;
1660
1661 /* Manufacturer / device ID from command 0x90 */
1662 uint8_t mfr_dev_id[2];
1663
1664 /* Status registers from command 0x05 and 0x35 */
1665 uint8_t sr1, sr2;
1666} __ec_align1;
1667
1668
1669/* Select flash during flash operations */
1670#define EC_CMD_FLASH_SELECT 0x0019
1671
1672/**
1673 * struct ec_params_flash_select - Parameters for the flash select command.
1674 * @select: 1 to select flash, 0 to deselect flash
1675 */
1676struct ec_params_flash_select {
1677 uint8_t select;
1678} __ec_align4;
1679
1119 1680
1120/*****************************************************************************/ 1681/*****************************************************************************/
1121/* PWM commands */ 1682/* PWM commands */
1122 1683
1123/* Get fan target RPM */ 1684/* Get fan target RPM */
1124#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20 1685#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1125 1686
1126struct ec_response_pwm_get_fan_rpm { 1687struct ec_response_pwm_get_fan_rpm {
1127 uint32_t rpm; 1688 uint32_t rpm;
1128} __packed; 1689} __ec_align4;
1129 1690
1130/* Set target fan RPM */ 1691/* Set target fan RPM */
1131#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21 1692#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1693
1694/* Version 0 of input params */
1695struct ec_params_pwm_set_fan_target_rpm_v0 {
1696 uint32_t rpm;
1697} __ec_align4;
1132 1698
1133struct ec_params_pwm_set_fan_target_rpm { 1699/* Version 1 of input params */
1700struct ec_params_pwm_set_fan_target_rpm_v1 {
1134 uint32_t rpm; 1701 uint32_t rpm;
1135} __packed; 1702 uint8_t fan_idx;
1703} __ec_align_size1;
1136 1704
1137/* Get keyboard backlight */ 1705/* Get keyboard backlight */
1138#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22 1706/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1707#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1139 1708
1140struct ec_response_pwm_get_keyboard_backlight { 1709struct ec_response_pwm_get_keyboard_backlight {
1141 uint8_t percent; 1710 uint8_t percent;
1142 uint8_t enabled; 1711 uint8_t enabled;
1143} __packed; 1712} __ec_align1;
1144 1713
1145/* Set keyboard backlight */ 1714/* Set keyboard backlight */
1146#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23 1715/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1716#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1147 1717
1148struct ec_params_pwm_set_keyboard_backlight { 1718struct ec_params_pwm_set_keyboard_backlight {
1149 uint8_t percent; 1719 uint8_t percent;
1150} __packed; 1720} __ec_align1;
1151 1721
1152/* Set target fan PWM duty cycle */ 1722/* Set target fan PWM duty cycle */
1153#define EC_CMD_PWM_SET_FAN_DUTY 0x24 1723#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1724
1725/* Version 0 of input params */
1726struct ec_params_pwm_set_fan_duty_v0 {
1727 uint32_t percent;
1728} __ec_align4;
1154 1729
1155struct ec_params_pwm_set_fan_duty { 1730/* Version 1 of input params */
1731struct ec_params_pwm_set_fan_duty_v1 {
1156 uint32_t percent; 1732 uint32_t percent;
1157} __packed; 1733 uint8_t fan_idx;
1734} __ec_align_size1;
1158 1735
1159#define EC_CMD_PWM_SET_DUTY 0x25 1736#define EC_CMD_PWM_SET_DUTY 0x0025
1160/* 16 bit duty cycle, 0xffff = 100% */ 1737/* 16 bit duty cycle, 0xffff = 100% */
1161#define EC_PWM_MAX_DUTY 0xffff 1738#define EC_PWM_MAX_DUTY 0xffff
1162 1739
@@ -1174,18 +1751,18 @@ struct ec_params_pwm_set_duty {
1174 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ 1751 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1175 uint8_t pwm_type; /* ec_pwm_type */ 1752 uint8_t pwm_type; /* ec_pwm_type */
1176 uint8_t index; /* Type-specific index, or 0 if unique */ 1753 uint8_t index; /* Type-specific index, or 0 if unique */
1177} __packed; 1754} __ec_align4;
1178 1755
1179#define EC_CMD_PWM_GET_DUTY 0x26 1756#define EC_CMD_PWM_GET_DUTY 0x0026
1180 1757
1181struct ec_params_pwm_get_duty { 1758struct ec_params_pwm_get_duty {
1182 uint8_t pwm_type; /* ec_pwm_type */ 1759 uint8_t pwm_type; /* ec_pwm_type */
1183 uint8_t index; /* Type-specific index, or 0 if unique */ 1760 uint8_t index; /* Type-specific index, or 0 if unique */
1184} __packed; 1761} __ec_align1;
1185 1762
1186struct ec_response_pwm_get_duty { 1763struct ec_response_pwm_get_duty {
1187 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */ 1764 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1188} __packed; 1765} __ec_align2;
1189 1766
1190/*****************************************************************************/ 1767/*****************************************************************************/
1191/* 1768/*
@@ -1194,11 +1771,11 @@ struct ec_response_pwm_get_duty {
1194 * into a subcommand. We'll make separate structs for subcommands with 1771 * into a subcommand. We'll make separate structs for subcommands with
1195 * different input args, so that we know how much to expect. 1772 * different input args, so that we know how much to expect.
1196 */ 1773 */
1197#define EC_CMD_LIGHTBAR_CMD 0x28 1774#define EC_CMD_LIGHTBAR_CMD 0x0028
1198 1775
1199struct rgb_s { 1776struct rgb_s {
1200 uint8_t r, g, b; 1777 uint8_t r, g, b;
1201}; 1778} __ec_todo_unpacked;
1202 1779
1203#define LB_BATTERY_LEVELS 4 1780#define LB_BATTERY_LEVELS 4
1204 1781
@@ -1238,7 +1815,7 @@ struct lightbar_params_v0 {
1238 1815
1239 /* Color palette */ 1816 /* Color palette */
1240 struct rgb_s color[8]; /* 0-3 are Google colors */ 1817 struct rgb_s color[8]; /* 0-3 are Google colors */
1241} __packed; 1818} __ec_todo_packed;
1242 1819
1243struct lightbar_params_v1 { 1820struct lightbar_params_v1 {
1244 /* Timing */ 1821 /* Timing */
@@ -1251,7 +1828,10 @@ struct lightbar_params_v1 {
1251 int32_t s3_sleep_for; 1828 int32_t s3_sleep_for;
1252 int32_t s3_ramp_up; 1829 int32_t s3_ramp_up;
1253 int32_t s3_ramp_down; 1830 int32_t s3_ramp_down;
1831 int32_t s5_ramp_up;
1832 int32_t s5_ramp_down;
1254 int32_t tap_tick_delay; 1833 int32_t tap_tick_delay;
1834 int32_t tap_gate_delay;
1255 int32_t tap_display_time; 1835 int32_t tap_display_time;
1256 1836
1257 /* Tap-for-battery params */ 1837 /* Tap-for-battery params */
@@ -1279,84 +1859,182 @@ struct lightbar_params_v1 {
1279 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */ 1859 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1280 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */ 1860 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1281 1861
1862 /* s5: single color pulse on inhibited power-up */
1863 uint8_t s5_idx;
1864
1282 /* Color palette */ 1865 /* Color palette */
1283 struct rgb_s color[8]; /* 0-3 are Google colors */ 1866 struct rgb_s color[8]; /* 0-3 are Google colors */
1284} __packed; 1867} __ec_todo_packed;
1868
1869/* Lightbar command params v2
1870 * crbug.com/467716
1871 *
1872 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1873 * logical groups to make it more manageable ( < 120 bytes).
1874 *
1875 * NOTE: Each of these groups must be less than 120 bytes.
1876 */
1877
1878struct lightbar_params_v2_timing {
1879 /* Timing */
1880 int32_t google_ramp_up;
1881 int32_t google_ramp_down;
1882 int32_t s3s0_ramp_up;
1883 int32_t s0_tick_delay[2]; /* AC=0/1 */
1884 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1885 int32_t s0s3_ramp_down;
1886 int32_t s3_sleep_for;
1887 int32_t s3_ramp_up;
1888 int32_t s3_ramp_down;
1889 int32_t s5_ramp_up;
1890 int32_t s5_ramp_down;
1891 int32_t tap_tick_delay;
1892 int32_t tap_gate_delay;
1893 int32_t tap_display_time;
1894} __ec_todo_packed;
1895
1896struct lightbar_params_v2_tap {
1897 /* Tap-for-battery params */
1898 uint8_t tap_pct_red;
1899 uint8_t tap_pct_green;
1900 uint8_t tap_seg_min_on;
1901 uint8_t tap_seg_max_on;
1902 uint8_t tap_seg_osc;
1903 uint8_t tap_idx[3];
1904} __ec_todo_packed;
1905
1906struct lightbar_params_v2_oscillation {
1907 /* Oscillation */
1908 uint8_t osc_min[2]; /* AC=0/1 */
1909 uint8_t osc_max[2]; /* AC=0/1 */
1910 uint8_t w_ofs[2]; /* AC=0/1 */
1911} __ec_todo_packed;
1912
1913struct lightbar_params_v2_brightness {
1914 /* Brightness limits based on the backlight and AC. */
1915 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1916 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1917 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1918} __ec_todo_packed;
1919
1920struct lightbar_params_v2_thresholds {
1921 /* Battery level thresholds */
1922 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1923} __ec_todo_packed;
1285 1924
1286/* Lightbar program */ 1925struct lightbar_params_v2_colors {
1926 /* Map [AC][battery_level] to color index */
1927 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1928 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1929
1930 /* s5: single color pulse on inhibited power-up */
1931 uint8_t s5_idx;
1932
1933 /* Color palette */
1934 struct rgb_s color[8]; /* 0-3 are Google colors */
1935} __ec_todo_packed;
1936
1937/* Lightbar program. */
1287#define EC_LB_PROG_LEN 192 1938#define EC_LB_PROG_LEN 192
1288struct lightbar_program { 1939struct lightbar_program {
1289 uint8_t size; 1940 uint8_t size;
1290 uint8_t data[EC_LB_PROG_LEN]; 1941 uint8_t data[EC_LB_PROG_LEN];
1291}; 1942} __ec_todo_unpacked;
1292 1943
1293struct ec_params_lightbar { 1944struct ec_params_lightbar {
1294 uint8_t cmd; /* Command (see enum lightbar_command) */ 1945 uint8_t cmd; /* Command (see enum lightbar_command) */
1295 union { 1946 union {
1296 struct { 1947 /*
1297 /* no args */ 1948 * The following commands have no args:
1298 } dump, off, on, init, get_seq, get_params_v0, get_params_v1, 1949 *
1299 version, get_brightness, get_demo, suspend, resume; 1950 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1951 * version, get_brightness, get_demo, suspend, resume,
1952 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
1953 * get_params_v2_bright, get_params_v2_thlds,
1954 * get_params_v2_colors
1955 *
1956 * Don't use an empty struct, because C++ hates that.
1957 */
1300 1958
1301 struct { 1959 struct __ec_todo_unpacked {
1302 uint8_t num; 1960 uint8_t num;
1303 } set_brightness, seq, demo; 1961 } set_brightness, seq, demo;
1304 1962
1305 struct { 1963 struct __ec_todo_unpacked {
1306 uint8_t ctrl, reg, value; 1964 uint8_t ctrl, reg, value;
1307 } reg; 1965 } reg;
1308 1966
1309 struct { 1967 struct __ec_todo_unpacked {
1310 uint8_t led, red, green, blue; 1968 uint8_t led, red, green, blue;
1311 } set_rgb; 1969 } set_rgb;
1312 1970
1313 struct { 1971 struct __ec_todo_unpacked {
1314 uint8_t led; 1972 uint8_t led;
1315 } get_rgb; 1973 } get_rgb;
1316 1974
1317 struct { 1975 struct __ec_todo_unpacked {
1318 uint8_t enable; 1976 uint8_t enable;
1319 } manual_suspend_ctrl; 1977 } manual_suspend_ctrl;
1320 1978
1321 struct lightbar_params_v0 set_params_v0; 1979 struct lightbar_params_v0 set_params_v0;
1322 struct lightbar_params_v1 set_params_v1; 1980 struct lightbar_params_v1 set_params_v1;
1981
1982 struct lightbar_params_v2_timing set_v2par_timing;
1983 struct lightbar_params_v2_tap set_v2par_tap;
1984 struct lightbar_params_v2_oscillation set_v2par_osc;
1985 struct lightbar_params_v2_brightness set_v2par_bright;
1986 struct lightbar_params_v2_thresholds set_v2par_thlds;
1987 struct lightbar_params_v2_colors set_v2par_colors;
1988
1323 struct lightbar_program set_program; 1989 struct lightbar_program set_program;
1324 }; 1990 };
1325} __packed; 1991} __ec_todo_packed;
1326 1992
1327struct ec_response_lightbar { 1993struct ec_response_lightbar {
1328 union { 1994 union {
1329 struct { 1995 struct __ec_todo_unpacked {
1330 struct { 1996 struct __ec_todo_unpacked {
1331 uint8_t reg; 1997 uint8_t reg;
1332 uint8_t ic0; 1998 uint8_t ic0;
1333 uint8_t ic1; 1999 uint8_t ic1;
1334 } vals[23]; 2000 } vals[23];
1335 } dump; 2001 } dump;
1336 2002
1337 struct { 2003 struct __ec_todo_unpacked {
1338 uint8_t num; 2004 uint8_t num;
1339 } get_seq, get_brightness, get_demo; 2005 } get_seq, get_brightness, get_demo;
1340 2006
1341 struct lightbar_params_v0 get_params_v0; 2007 struct lightbar_params_v0 get_params_v0;
1342 struct lightbar_params_v1 get_params_v1; 2008 struct lightbar_params_v1 get_params_v1;
1343 2009
1344 struct { 2010
2011 struct lightbar_params_v2_timing get_params_v2_timing;
2012 struct lightbar_params_v2_tap get_params_v2_tap;
2013 struct lightbar_params_v2_oscillation get_params_v2_osc;
2014 struct lightbar_params_v2_brightness get_params_v2_bright;
2015 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2016 struct lightbar_params_v2_colors get_params_v2_colors;
2017
2018 struct __ec_todo_unpacked {
1345 uint32_t num; 2019 uint32_t num;
1346 uint32_t flags; 2020 uint32_t flags;
1347 } version; 2021 } version;
1348 2022
1349 struct { 2023 struct __ec_todo_unpacked {
1350 uint8_t red, green, blue; 2024 uint8_t red, green, blue;
1351 } get_rgb; 2025 } get_rgb;
1352 2026
1353 struct { 2027 /*
1354 /* no return params */ 2028 * The following commands have no response:
1355 } off, on, init, set_brightness, seq, reg, set_rgb, 2029 *
1356 demo, set_params_v0, set_params_v1, 2030 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
1357 set_program, manual_suspend_ctrl, suspend, resume; 2031 * set_params_v0, set_params_v1, set_program,
2032 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2033 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2034 * set_v2par_thlds, set_v2par_colors
2035 */
1358 }; 2036 };
1359} __packed; 2037} __ec_todo_packed;
1360 2038
1361/* Lightbar commands */ 2039/* Lightbar commands */
1362enum lightbar_command { 2040enum lightbar_command {
@@ -1382,13 +2060,25 @@ enum lightbar_command {
1382 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19, 2060 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1383 LIGHTBAR_CMD_SUSPEND = 20, 2061 LIGHTBAR_CMD_SUSPEND = 20,
1384 LIGHTBAR_CMD_RESUME = 21, 2062 LIGHTBAR_CMD_RESUME = 21,
2063 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2064 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2065 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2066 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2067 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2068 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2069 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2070 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2071 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2072 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2073 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2074 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
1385 LIGHTBAR_NUM_CMDS 2075 LIGHTBAR_NUM_CMDS
1386}; 2076};
1387 2077
1388/*****************************************************************************/ 2078/*****************************************************************************/
1389/* LED control commands */ 2079/* LED control commands */
1390 2080
1391#define EC_CMD_LED_CONTROL 0x29 2081#define EC_CMD_LED_CONTROL 0x0029
1392 2082
1393enum ec_led_id { 2083enum ec_led_id {
1394 /* LED to indicate battery state of charge */ 2084 /* LED to indicate battery state of charge */
@@ -1400,13 +2090,21 @@ enum ec_led_id {
1400 EC_LED_ID_POWER_LED, 2090 EC_LED_ID_POWER_LED,
1401 /* LED on power adapter or its plug */ 2091 /* LED on power adapter or its plug */
1402 EC_LED_ID_ADAPTER_LED, 2092 EC_LED_ID_ADAPTER_LED,
2093 /* LED to indicate left side */
2094 EC_LED_ID_LEFT_LED,
2095 /* LED to indicate right side */
2096 EC_LED_ID_RIGHT_LED,
2097 /* LED to indicate recovery mode with HW_REINIT */
2098 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2099 /* LED to indicate sysrq debug mode. */
2100 EC_LED_ID_SYSRQ_DEBUG_LED,
1403 2101
1404 EC_LED_ID_COUNT 2102 EC_LED_ID_COUNT
1405}; 2103};
1406 2104
1407/* LED control flags */ 2105/* LED control flags */
1408#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */ 2106#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
1409#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */ 2107#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
1410 2108
1411enum ec_led_colors { 2109enum ec_led_colors {
1412 EC_LED_COLOR_RED = 0, 2110 EC_LED_COLOR_RED = 0,
@@ -1414,6 +2112,7 @@ enum ec_led_colors {
1414 EC_LED_COLOR_BLUE, 2112 EC_LED_COLOR_BLUE,
1415 EC_LED_COLOR_YELLOW, 2113 EC_LED_COLOR_YELLOW,
1416 EC_LED_COLOR_WHITE, 2114 EC_LED_COLOR_WHITE,
2115 EC_LED_COLOR_AMBER,
1417 2116
1418 EC_LED_COLOR_COUNT 2117 EC_LED_COLOR_COUNT
1419}; 2118};
@@ -1423,7 +2122,7 @@ struct ec_params_led_control {
1423 uint8_t flags; /* Control flags */ 2122 uint8_t flags; /* Control flags */
1424 2123
1425 uint8_t brightness[EC_LED_COLOR_COUNT]; 2124 uint8_t brightness[EC_LED_COLOR_COUNT];
1426} __packed; 2125} __ec_align1;
1427 2126
1428struct ec_response_led_control { 2127struct ec_response_led_control {
1429 /* 2128 /*
@@ -1434,7 +2133,7 @@ struct ec_response_led_control {
1434 * Other values means the LED is control by PWM. 2133 * Other values means the LED is control by PWM.
1435 */ 2134 */
1436 uint8_t brightness_range[EC_LED_COLOR_COUNT]; 2135 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1437} __packed; 2136} __ec_align1;
1438 2137
1439/*****************************************************************************/ 2138/*****************************************************************************/
1440/* Verified boot commands */ 2139/* Verified boot commands */
@@ -1445,7 +2144,7 @@ struct ec_response_led_control {
1445 */ 2144 */
1446 2145
1447/* Verified boot hash command */ 2146/* Verified boot hash command */
1448#define EC_CMD_VBOOT_HASH 0x2A 2147#define EC_CMD_VBOOT_HASH 0x002A
1449 2148
1450struct ec_params_vboot_hash { 2149struct ec_params_vboot_hash {
1451 uint8_t cmd; /* enum ec_vboot_hash_cmd */ 2150 uint8_t cmd; /* enum ec_vboot_hash_cmd */
@@ -1455,7 +2154,7 @@ struct ec_params_vboot_hash {
1455 uint32_t offset; /* Offset in flash to hash */ 2154 uint32_t offset; /* Offset in flash to hash */
1456 uint32_t size; /* Number of bytes to hash */ 2155 uint32_t size; /* Number of bytes to hash */
1457 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */ 2156 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1458} __packed; 2157} __ec_align4;
1459 2158
1460struct ec_response_vboot_hash { 2159struct ec_response_vboot_hash {
1461 uint8_t status; /* enum ec_vboot_hash_status */ 2160 uint8_t status; /* enum ec_vboot_hash_status */
@@ -1465,7 +2164,7 @@ struct ec_response_vboot_hash {
1465 uint32_t offset; /* Offset in flash which was hashed */ 2164 uint32_t offset; /* Offset in flash which was hashed */
1466 uint32_t size; /* Number of bytes hashed */ 2165 uint32_t size; /* Number of bytes hashed */
1467 uint8_t hash_digest[64]; /* Hash digest data */ 2166 uint8_t hash_digest[64]; /* Hash digest data */
1468} __packed; 2167} __ec_align4;
1469 2168
1470enum ec_vboot_hash_cmd { 2169enum ec_vboot_hash_cmd {
1471 EC_VBOOT_HASH_GET = 0, /* Get current hash status */ 2170 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
@@ -1489,15 +2188,22 @@ enum ec_vboot_hash_status {
1489 * If one of these is specified, the EC will automatically update offset and 2188 * If one of these is specified, the EC will automatically update offset and
1490 * size to the correct values for the specified image (RO or RW). 2189 * size to the correct values for the specified image (RO or RW).
1491 */ 2190 */
1492#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe 2191#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1493#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd 2192#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2193#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2194
2195/*
2196 * 'RW' is vague if there are multiple RW images; we mean the active one,
2197 * so the old constant is deprecated.
2198 */
2199#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
1494 2200
1495/*****************************************************************************/ 2201/*****************************************************************************/
1496/* 2202/*
1497 * Motion sense commands. We'll make separate structs for sub-commands with 2203 * Motion sense commands. We'll make separate structs for sub-commands with
1498 * different input args, so that we know how much to expect. 2204 * different input args, so that we know how much to expect.
1499 */ 2205 */
1500#define EC_CMD_MOTION_SENSE_CMD 0x2B 2206#define EC_CMD_MOTION_SENSE_CMD 0x002B
1501 2207
1502/* Motion sense commands */ 2208/* Motion sense commands */
1503enum motionsense_command { 2209enum motionsense_command {
@@ -1516,7 +2222,13 @@ enum motionsense_command {
1516 2222
1517 /* 2223 /*
1518 * EC Rate command is a setter/getter command for the EC sampling rate 2224 * EC Rate command is a setter/getter command for the EC sampling rate
1519 * of all motion sensors in milliseconds. 2225 * in milliseconds.
2226 * It is per sensor, the EC run sample task at the minimum of all
2227 * sensors EC_RATE.
2228 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2229 * to collect all the sensor samples.
2230 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2231 * to process of all motion sensors in milliseconds.
1520 */ 2232 */
1521 MOTIONSENSE_CMD_EC_RATE = 2, 2233 MOTIONSENSE_CMD_EC_RATE = 2,
1522 2234
@@ -1547,32 +2259,76 @@ enum motionsense_command {
1547 MOTIONSENSE_CMD_DATA = 6, 2259 MOTIONSENSE_CMD_DATA = 6,
1548 2260
1549 /* 2261 /*
1550 * Perform low level calibration.. On sensors that support it, ask to 2262 * Return sensor fifo info.
1551 * do offset calibration. 2263 */
2264 MOTIONSENSE_CMD_FIFO_INFO = 7,
2265
2266 /*
2267 * Insert a flush element in the fifo and return sensor fifo info.
2268 * The host can use that element to synchronize its operation.
2269 */
2270 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2271
2272 /*
2273 * Return a portion of the fifo.
2274 */
2275 MOTIONSENSE_CMD_FIFO_READ = 9,
2276
2277 /*
2278 * Perform low level calibration.
2279 * On sensors that support it, ask to do offset calibration.
1552 */ 2280 */
1553 MOTIONSENSE_CMD_PERFORM_CALIB = 10, 2281 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1554 2282
1555 /* 2283 /*
1556 * Sensor Offset command is a setter/getter command for the offset used 2284 * Sensor Offset command is a setter/getter command for the offset
1557 * for calibration. The offsets can be calculated by the host, or via 2285 * used for calibration.
2286 * The offsets can be calculated by the host, or via
1558 * PERFORM_CALIB command. 2287 * PERFORM_CALIB command.
1559 */ 2288 */
1560 MOTIONSENSE_CMD_SENSOR_OFFSET = 11, 2289 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1561 2290
1562 /* Number of motionsense sub-commands. */ 2291 /*
1563 MOTIONSENSE_NUM_CMDS 2292 * List available activities for a MOTION sensor.
1564}; 2293 * Indicates if they are enabled or disabled.
2294 */
2295 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2296
2297 /*
2298 * Activity management
2299 * Enable/Disable activity recognition.
2300 */
2301 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2302
2303 /*
2304 * Lid Angle
2305 */
2306 MOTIONSENSE_CMD_LID_ANGLE = 14,
2307
2308 /*
2309 * Allow the FIFO to trigger interrupt via MKBP events.
2310 * By default the FIFO does not send interrupt to process the FIFO
2311 * until the AP is ready or it is coming from a wakeup sensor.
2312 */
2313 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2314
2315 /*
2316 * Spoof the readings of the sensors. The spoofed readings can be set
2317 * to arbitrary values, or will lock to the last read actual values.
2318 */
2319 MOTIONSENSE_CMD_SPOOF = 16,
1565 2320
1566enum motionsensor_id { 2321 /* Set lid angle for tablet mode detection. */
1567 EC_MOTION_SENSOR_ACCEL_BASE = 0, 2322 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
1568 EC_MOTION_SENSOR_ACCEL_LID = 1,
1569 EC_MOTION_SENSOR_GYRO = 2,
1570 2323
1571 /* 2324 /*
1572 * Note, if more sensors are added and this count changes, the padding 2325 * Sensor Scale command is a setter/getter command for the calibration
1573 * in ec_response_motion_sense dump command must be modified. 2326 * scale.
1574 */ 2327 */
1575 EC_MOTION_SENSOR_COUNT = 3 2328 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2329
2330 /* Number of motionsense sub-commands. */
2331 MOTIONSENSE_NUM_CMDS
1576}; 2332};
1577 2333
1578/* List of motion sensor types. */ 2334/* List of motion sensor types. */
@@ -1584,6 +2340,7 @@ enum motionsensor_type {
1584 MOTIONSENSE_TYPE_LIGHT = 4, 2340 MOTIONSENSE_TYPE_LIGHT = 4,
1585 MOTIONSENSE_TYPE_ACTIVITY = 5, 2341 MOTIONSENSE_TYPE_ACTIVITY = 5,
1586 MOTIONSENSE_TYPE_BARO = 6, 2342 MOTIONSENSE_TYPE_BARO = 6,
2343 MOTIONSENSE_TYPE_SYNC = 7,
1587 MOTIONSENSE_TYPE_MAX, 2344 MOTIONSENSE_TYPE_MAX,
1588}; 2345};
1589 2346
@@ -1591,19 +2348,116 @@ enum motionsensor_type {
1591enum motionsensor_location { 2348enum motionsensor_location {
1592 MOTIONSENSE_LOC_BASE = 0, 2349 MOTIONSENSE_LOC_BASE = 0,
1593 MOTIONSENSE_LOC_LID = 1, 2350 MOTIONSENSE_LOC_LID = 1,
2351 MOTIONSENSE_LOC_CAMERA = 2,
1594 MOTIONSENSE_LOC_MAX, 2352 MOTIONSENSE_LOC_MAX,
1595}; 2353};
1596 2354
1597/* List of motion sensor chips. */ 2355/* List of motion sensor chips. */
1598enum motionsensor_chip { 2356enum motionsensor_chip {
1599 MOTIONSENSE_CHIP_KXCJ9 = 0, 2357 MOTIONSENSE_CHIP_KXCJ9 = 0,
2358 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2359 MOTIONSENSE_CHIP_BMI160 = 2,
2360 MOTIONSENSE_CHIP_SI1141 = 3,
2361 MOTIONSENSE_CHIP_SI1142 = 4,
2362 MOTIONSENSE_CHIP_SI1143 = 5,
2363 MOTIONSENSE_CHIP_KX022 = 6,
2364 MOTIONSENSE_CHIP_L3GD20H = 7,
2365 MOTIONSENSE_CHIP_BMA255 = 8,
2366 MOTIONSENSE_CHIP_BMP280 = 9,
2367 MOTIONSENSE_CHIP_OPT3001 = 10,
2368 MOTIONSENSE_CHIP_BH1730 = 11,
2369 MOTIONSENSE_CHIP_GPIO = 12,
2370 MOTIONSENSE_CHIP_LIS2DH = 13,
2371 MOTIONSENSE_CHIP_LSM6DSM = 14,
2372 MOTIONSENSE_CHIP_LIS2DE = 15,
2373 MOTIONSENSE_CHIP_LIS2MDL = 16,
2374 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2375 MOTIONSENSE_CHIP_LSM6DSO = 18,
2376 MOTIONSENSE_CHIP_LNG2DM = 19,
2377 MOTIONSENSE_CHIP_MAX,
2378};
2379
2380/* List of orientation positions */
2381enum motionsensor_orientation {
2382 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2383 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2384 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2385 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2386 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
2387};
2388
2389struct ec_response_motion_sensor_data {
2390 /* Flags for each sensor. */
2391 uint8_t flags;
2392 /* Sensor number the data comes from. */
2393 uint8_t sensor_num;
2394 /* Each sensor is up to 3-axis. */
2395 union {
2396 int16_t data[3];
2397 struct __ec_todo_packed {
2398 uint16_t reserved;
2399 uint32_t timestamp;
2400 };
2401 struct __ec_todo_unpacked {
2402 uint8_t activity; /* motionsensor_activity */
2403 uint8_t state;
2404 int16_t add_info[2];
2405 };
2406 };
2407} __ec_todo_packed;
2408
2409/* Note: used in ec_response_get_next_data */
2410struct ec_response_motion_sense_fifo_info {
2411 /* Size of the fifo */
2412 uint16_t size;
2413 /* Amount of space used in the fifo */
2414 uint16_t count;
2415 /* Timestamp recorded in us.
2416 * aka accurate timestamp when host event was triggered.
2417 */
2418 uint32_t timestamp;
2419 /* Total amount of vector lost */
2420 uint16_t total_lost;
2421 /* Lost events since the last fifo_info, per sensors */
2422 uint16_t lost[0];
2423} __ec_todo_packed;
2424
2425struct ec_response_motion_sense_fifo_data {
2426 uint32_t number_data;
2427 struct ec_response_motion_sensor_data data[0];
2428} __ec_todo_packed;
2429
2430/* List supported activity recognition */
2431enum motionsensor_activity {
2432 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2433 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2434 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2435 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
1600}; 2436};
1601 2437
2438struct ec_motion_sense_activity {
2439 uint8_t sensor_num;
2440 uint8_t activity; /* one of enum motionsensor_activity */
2441 uint8_t enable; /* 1: enable, 0: disable */
2442 uint8_t reserved;
2443 uint16_t parameters[3]; /* activity dependent parameters */
2444} __ec_todo_unpacked;
2445
1602/* Module flag masks used for the dump sub-command. */ 2446/* Module flag masks used for the dump sub-command. */
1603#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0) 2447#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
1604 2448
1605/* Sensor flag masks used for the dump sub-command. */ 2449/* Sensor flag masks used for the dump sub-command. */
1606#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0) 2450#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
2451
2452/*
2453 * Flush entry for synchronization.
2454 * data contains time stamp
2455 */
2456#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2457#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2458#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2459#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2460#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
1607 2461
1608/* 2462/*
1609 * Send this value for the data element to only perform a read. If you 2463 * Send this value for the data element to only perform a read. If you
@@ -1614,48 +2468,79 @@ enum motionsensor_chip {
1614 2468
1615#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000 2469#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1616 2470
2471/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
1617/* Set Calibration information */ 2472/* Set Calibration information */
1618#define MOTION_SENSE_SET_OFFSET 1 2473#define MOTION_SENSE_SET_OFFSET BIT(0)
1619 2474
1620struct ec_response_motion_sensor_data { 2475/* Default Scale value, factor 1. */
1621 /* Flags for each sensor. */ 2476#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
1622 uint8_t flags; 2477
1623 /* Sensor number the data comes from */ 2478#define LID_ANGLE_UNRELIABLE 500
1624 uint8_t sensor_num; 2479
1625 /* Each sensor is up to 3-axis. */ 2480enum motionsense_spoof_mode {
1626 union { 2481 /* Disable spoof mode. */
1627 int16_t data[3]; 2482 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
1628 struct { 2483
1629 uint16_t rsvd; 2484 /* Enable spoof mode, but use provided component values. */
1630 uint32_t timestamp; 2485 MOTIONSENSE_SPOOF_MODE_CUSTOM,
1631 } __packed; 2486
1632 struct { 2487 /* Enable spoof mode, but use the current sensor values. */
1633 uint8_t activity; /* motionsensor_activity */ 2488 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
1634 uint8_t state; 2489
1635 int16_t add_info[2]; 2490 /* Query the current spoof mode status for the sensor. */
1636 }; 2491 MOTIONSENSE_SPOOF_MODE_QUERY,
1637 }; 2492};
1638} __packed;
1639 2493
1640struct ec_params_motion_sense { 2494struct ec_params_motion_sense {
1641 uint8_t cmd; 2495 uint8_t cmd;
1642 union { 2496 union {
1643 /* Used for MOTIONSENSE_CMD_DUMP. */ 2497 /* Used for MOTIONSENSE_CMD_DUMP. */
1644 struct { 2498 struct __ec_todo_unpacked {
1645 /* no args */ 2499 /*
2500 * Maximal number of sensor the host is expecting.
2501 * 0 means the host is only interested in the number
2502 * of sensors controlled by the EC.
2503 */
2504 uint8_t max_sensor_count;
1646 } dump; 2505 } dump;
1647 2506
1648 /* 2507 /*
1649 * Used for MOTIONSENSE_CMD_EC_RATE and 2508 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1650 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1651 */ 2509 */
1652 struct { 2510 struct __ec_todo_unpacked {
1653 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ 2511 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2512 * kb_wake_angle: angle to wakup AP.
2513 */
1654 int16_t data; 2514 int16_t data;
1655 } ec_rate, kb_wake_angle; 2515 } kb_wake_angle;
2516
2517 /*
2518 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2519 * and MOTIONSENSE_CMD_PERFORM_CALIB.
2520 */
2521 struct __ec_todo_unpacked {
2522 uint8_t sensor_num;
2523 } info, info_3, data, fifo_flush, perform_calib,
2524 list_activities;
2525
2526 /*
2527 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2528 * and MOTIONSENSE_CMD_SENSOR_RANGE.
2529 */
2530 struct __ec_todo_unpacked {
2531 uint8_t sensor_num;
2532
2533 /* Rounding flag, true for round-up, false for down. */
2534 uint8_t roundup;
2535
2536 uint16_t reserved;
2537
2538 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2539 int32_t data;
2540 } ec_rate, sensor_odr, sensor_range;
1656 2541
1657 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ 2542 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1658 struct { 2543 struct __ec_todo_packed {
1659 uint8_t sensor_num; 2544 uint8_t sensor_num;
1660 2545
1661 /* 2546 /*
@@ -1681,36 +2566,102 @@ struct ec_params_motion_sense {
1681 * Compass: 1/16 uT 2566 * Compass: 1/16 uT
1682 */ 2567 */
1683 int16_t offset[3]; 2568 int16_t offset[3];
1684 } __packed sensor_offset; 2569 } sensor_offset;
1685 2570
1686 /* Used for MOTIONSENSE_CMD_INFO. */ 2571 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
1687 struct { 2572 struct __ec_todo_packed {
1688 uint8_t sensor_num; 2573 uint8_t sensor_num;
1689 } info;
1690 2574
1691 /* 2575 /*
1692 * Used for MOTIONSENSE_CMD_SENSOR_ODR and 2576 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1693 * MOTIONSENSE_CMD_SENSOR_RANGE. 2577 * the calibration information in the EC.
1694 */ 2578 * If unset, just retrieve calibration information.
1695 struct { 2579 */
1696 /* Should be element of enum motionsensor_id. */ 2580 uint16_t flags;
1697 uint8_t sensor_num;
1698 2581
1699 /* Rounding flag, true for round-up, false for down. */ 2582 /*
1700 uint8_t roundup; 2583 * Temperature at calibration, in units of 0.01 C
2584 * 0x8000: invalid / unknown.
2585 * 0x0: 0C
2586 * 0x7fff: +327.67C
2587 */
2588 int16_t temp;
1701 2589
1702 uint16_t reserved; 2590 /*
2591 * Scale for calibration:
2592 * By default scale is 1, it is encoded on 16bits:
2593 * 1 = BIT(15)
2594 * ~2 = 0xFFFF
2595 * ~0 = 0.
2596 */
2597 uint16_t scale[3];
2598 } sensor_scale;
1703 2599
1704 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */ 2600
1705 int32_t data; 2601 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
1706 } sensor_odr, sensor_range; 2602 /* (no params) */
2603
2604 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2605 struct __ec_todo_unpacked {
2606 /*
2607 * Number of expected vector to return.
2608 * EC may return less or 0 if none available.
2609 */
2610 uint32_t max_data_vector;
2611 } fifo_read;
2612
2613 struct ec_motion_sense_activity set_activity;
2614
2615 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2616 /* (no params) */
2617
2618 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2619 struct __ec_todo_unpacked {
2620 /*
2621 * 1: enable, 0 disable fifo,
2622 * EC_MOTION_SENSE_NO_VALUE return value.
2623 */
2624 int8_t enable;
2625 } fifo_int_enable;
2626
2627 /* Used for MOTIONSENSE_CMD_SPOOF */
2628 struct __ec_todo_packed {
2629 uint8_t sensor_id;
2630
2631 /* See enum motionsense_spoof_mode. */
2632 uint8_t spoof_enable;
2633
2634 /* Ignored, used for alignment. */
2635 uint8_t reserved;
2636
2637 /* Individual component values to spoof. */
2638 int16_t components[3];
2639 } spoof;
2640
2641 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2642 struct __ec_todo_unpacked {
2643 /*
2644 * Lid angle threshold for switching between tablet and
2645 * clamshell mode.
2646 */
2647 int16_t lid_angle;
2648
2649 /*
2650 * Hysteresis degree to prevent fluctuations between
2651 * clamshell and tablet mode if lid angle keeps
2652 * changing around the threshold. Lid motion driver will
2653 * use lid_angle + hys_degree to trigger tablet mode and
2654 * lid_angle - hys_degree to trigger clamshell mode.
2655 */
2656 int16_t hys_degree;
2657 } tablet_mode_threshold;
1707 }; 2658 };
1708} __packed; 2659} __ec_todo_packed;
1709 2660
1710struct ec_response_motion_sense { 2661struct ec_response_motion_sense {
1711 union { 2662 union {
1712 /* Used for MOTIONSENSE_CMD_DUMP. */ 2663 /* Used for MOTIONSENSE_CMD_DUMP */
1713 struct { 2664 struct __ec_todo_unpacked {
1714 /* Flags representing the motion sensor module. */ 2665 /* Flags representing the motion sensor module. */
1715 uint8_t module_flags; 2666 uint8_t module_flags;
1716 2667
@@ -1725,7 +2676,7 @@ struct ec_response_motion_sense {
1725 } dump; 2676 } dump;
1726 2677
1727 /* Used for MOTIONSENSE_CMD_INFO. */ 2678 /* Used for MOTIONSENSE_CMD_INFO. */
1728 struct { 2679 struct __ec_todo_unpacked {
1729 /* Should be element of enum motionsensor_type. */ 2680 /* Should be element of enum motionsensor_type. */
1730 uint8_t type; 2681 uint8_t type;
1731 2682
@@ -1736,37 +2687,129 @@ struct ec_response_motion_sense {
1736 uint8_t chip; 2687 uint8_t chip;
1737 } info; 2688 } info;
1738 2689
2690 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2691 struct __ec_todo_unpacked {
2692 /* Should be element of enum motionsensor_type. */
2693 uint8_t type;
2694
2695 /* Should be element of enum motionsensor_location. */
2696 uint8_t location;
2697
2698 /* Should be element of enum motionsensor_chip. */
2699 uint8_t chip;
2700
2701 /* Minimum sensor sampling frequency */
2702 uint32_t min_frequency;
2703
2704 /* Maximum sensor sampling frequency */
2705 uint32_t max_frequency;
2706
2707 /* Max number of sensor events that could be in fifo */
2708 uint32_t fifo_max_event_count;
2709 } info_3;
2710
1739 /* Used for MOTIONSENSE_CMD_DATA */ 2711 /* Used for MOTIONSENSE_CMD_DATA */
1740 struct ec_response_motion_sensor_data data; 2712 struct ec_response_motion_sensor_data data;
1741 2713
1742 /* 2714 /*
1743 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR, 2715 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1744 * MOTIONSENSE_CMD_SENSOR_RANGE, and 2716 * MOTIONSENSE_CMD_SENSOR_RANGE,
1745 * MOTIONSENSE_CMD_KB_WAKE_ANGLE. 2717 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2718 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2719 * MOTIONSENSE_CMD_SPOOF.
1746 */ 2720 */
1747 struct { 2721 struct __ec_todo_unpacked {
1748 /* Current value of the parameter queried. */ 2722 /* Current value of the parameter queried. */
1749 int32_t ret; 2723 int32_t ret;
1750 } ec_rate, sensor_odr, sensor_range, kb_wake_angle; 2724 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2725 fifo_int_enable, spoof;
1751 2726
1752 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */ 2727 /*
1753 struct { 2728 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
2729 * PERFORM_CALIB.
2730 */
2731 struct __ec_todo_unpacked {
1754 int16_t temp; 2732 int16_t temp;
1755 int16_t offset[3]; 2733 int16_t offset[3];
1756 } sensor_offset, perform_calib; 2734 } sensor_offset, perform_calib;
2735
2736 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2737 struct __ec_todo_unpacked {
2738 int16_t temp;
2739 uint16_t scale[3];
2740 } sensor_scale;
2741
2742 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2743
2744 struct ec_response_motion_sense_fifo_data fifo_read;
2745
2746 struct __ec_todo_packed {
2747 uint16_t reserved;
2748 uint32_t enabled;
2749 uint32_t disabled;
2750 } list_activities;
2751
2752 /* No params for set activity */
2753
2754 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2755 struct __ec_todo_unpacked {
2756 /*
2757 * Angle between 0 and 360 degree if available,
2758 * LID_ANGLE_UNRELIABLE otherwise.
2759 */
2760 uint16_t value;
2761 } lid_angle;
2762
2763 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2764 struct __ec_todo_unpacked {
2765 /*
2766 * Lid angle threshold for switching between tablet and
2767 * clamshell mode.
2768 */
2769 uint16_t lid_angle;
2770
2771 /* Hysteresis degree. */
2772 uint16_t hys_degree;
2773 } tablet_mode_threshold;
2774
1757 }; 2775 };
1758} __packed; 2776} __ec_todo_packed;
2777
2778/*****************************************************************************/
2779/* Force lid open command */
2780
2781/* Make lid event always open */
2782#define EC_CMD_FORCE_LID_OPEN 0x002C
2783
2784struct ec_params_force_lid_open {
2785 uint8_t enabled;
2786} __ec_align1;
2787
2788/*****************************************************************************/
2789/* Configure the behavior of the power button */
2790#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2791
2792enum ec_config_power_button_flags {
2793 /* Enable/Disable power button pulses for x86 devices */
2794 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
2795};
2796
2797struct ec_params_config_power_button {
2798 /* See enum ec_config_power_button_flags */
2799 uint8_t flags;
2800} __ec_align1;
1759 2801
1760/*****************************************************************************/ 2802/*****************************************************************************/
1761/* USB charging control commands */ 2803/* USB charging control commands */
1762 2804
1763/* Set USB port charging mode */ 2805/* Set USB port charging mode */
1764#define EC_CMD_USB_CHARGE_SET_MODE 0x30 2806#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
1765 2807
1766struct ec_params_usb_charge_set_mode { 2808struct ec_params_usb_charge_set_mode {
1767 uint8_t usb_port_id; 2809 uint8_t usb_port_id;
1768 uint8_t mode; 2810 uint8_t mode:7;
1769} __packed; 2811 uint8_t inhibit_charge:1;
2812} __ec_align1;
1770 2813
1771/*****************************************************************************/ 2814/*****************************************************************************/
1772/* Persistent storage for host */ 2815/* Persistent storage for host */
@@ -1775,35 +2818,35 @@ struct ec_params_usb_charge_set_mode {
1775#define EC_PSTORE_SIZE_MAX 64 2818#define EC_PSTORE_SIZE_MAX 64
1776 2819
1777/* Get persistent storage info */ 2820/* Get persistent storage info */
1778#define EC_CMD_PSTORE_INFO 0x40 2821#define EC_CMD_PSTORE_INFO 0x0040
1779 2822
1780struct ec_response_pstore_info { 2823struct ec_response_pstore_info {
1781 /* Persistent storage size, in bytes */ 2824 /* Persistent storage size, in bytes */
1782 uint32_t pstore_size; 2825 uint32_t pstore_size;
1783 /* Access size; read/write offset and size must be a multiple of this */ 2826 /* Access size; read/write offset and size must be a multiple of this */
1784 uint32_t access_size; 2827 uint32_t access_size;
1785} __packed; 2828} __ec_align4;
1786 2829
1787/* 2830/*
1788 * Read persistent storage 2831 * Read persistent storage
1789 * 2832 *
1790 * Response is params.size bytes of data. 2833 * Response is params.size bytes of data.
1791 */ 2834 */
1792#define EC_CMD_PSTORE_READ 0x41 2835#define EC_CMD_PSTORE_READ 0x0041
1793 2836
1794struct ec_params_pstore_read { 2837struct ec_params_pstore_read {
1795 uint32_t offset; /* Byte offset to read */ 2838 uint32_t offset; /* Byte offset to read */
1796 uint32_t size; /* Size to read in bytes */ 2839 uint32_t size; /* Size to read in bytes */
1797} __packed; 2840} __ec_align4;
1798 2841
1799/* Write persistent storage */ 2842/* Write persistent storage */
1800#define EC_CMD_PSTORE_WRITE 0x42 2843#define EC_CMD_PSTORE_WRITE 0x0042
1801 2844
1802struct ec_params_pstore_write { 2845struct ec_params_pstore_write {
1803 uint32_t offset; /* Byte offset to write */ 2846 uint32_t offset; /* Byte offset to write */
1804 uint32_t size; /* Size to write in bytes */ 2847 uint32_t size; /* Size to write in bytes */
1805 uint8_t data[EC_PSTORE_SIZE_MAX]; 2848 uint8_t data[EC_PSTORE_SIZE_MAX];
1806} __packed; 2849} __ec_align4;
1807 2850
1808/*****************************************************************************/ 2851/*****************************************************************************/
1809/* Real-time clock */ 2852/* Real-time clock */
@@ -1811,21 +2854,21 @@ struct ec_params_pstore_write {
1811/* RTC params and response structures */ 2854/* RTC params and response structures */
1812struct ec_params_rtc { 2855struct ec_params_rtc {
1813 uint32_t time; 2856 uint32_t time;
1814} __packed; 2857} __ec_align4;
1815 2858
1816struct ec_response_rtc { 2859struct ec_response_rtc {
1817 uint32_t time; 2860 uint32_t time;
1818} __packed; 2861} __ec_align4;
1819 2862
1820/* These use ec_response_rtc */ 2863/* These use ec_response_rtc */
1821#define EC_CMD_RTC_GET_VALUE 0x44 2864#define EC_CMD_RTC_GET_VALUE 0x0044
1822#define EC_CMD_RTC_GET_ALARM 0x45 2865#define EC_CMD_RTC_GET_ALARM 0x0045
1823 2866
1824/* These all use ec_params_rtc */ 2867/* These all use ec_params_rtc */
1825#define EC_CMD_RTC_SET_VALUE 0x46 2868#define EC_CMD_RTC_SET_VALUE 0x0046
1826#define EC_CMD_RTC_SET_ALARM 0x47 2869#define EC_CMD_RTC_SET_ALARM 0x0047
1827 2870
1828/* Pass as param to SET_ALARM to clear the current alarm */ 2871/* Pass as time param to SET_ALARM to clear the current alarm */
1829#define EC_RTC_ALARM_CLEAR 0 2872#define EC_RTC_ALARM_CLEAR 0
1830 2873
1831/*****************************************************************************/ 2874/*****************************************************************************/
@@ -1835,8 +2878,8 @@ struct ec_response_rtc {
1835#define EC_PORT80_SIZE_MAX 32 2878#define EC_PORT80_SIZE_MAX 32
1836 2879
1837/* Get last port80 code from previous boot */ 2880/* Get last port80 code from previous boot */
1838#define EC_CMD_PORT80_LAST_BOOT 0x48 2881#define EC_CMD_PORT80_LAST_BOOT 0x0048
1839#define EC_CMD_PORT80_READ 0x48 2882#define EC_CMD_PORT80_READ 0x0048
1840 2883
1841enum ec_port80_subcmd { 2884enum ec_port80_subcmd {
1842 EC_PORT80_GET_INFO = 0, 2885 EC_PORT80_GET_INFO = 0,
@@ -1846,29 +2889,72 @@ enum ec_port80_subcmd {
1846struct ec_params_port80_read { 2889struct ec_params_port80_read {
1847 uint16_t subcmd; 2890 uint16_t subcmd;
1848 union { 2891 union {
1849 struct { 2892 struct __ec_todo_unpacked {
1850 uint32_t offset; 2893 uint32_t offset;
1851 uint32_t num_entries; 2894 uint32_t num_entries;
1852 } read_buffer; 2895 } read_buffer;
1853 }; 2896 };
1854} __packed; 2897} __ec_todo_packed;
1855 2898
1856struct ec_response_port80_read { 2899struct ec_response_port80_read {
1857 union { 2900 union {
1858 struct { 2901 struct __ec_todo_unpacked {
1859 uint32_t writes; 2902 uint32_t writes;
1860 uint32_t history_size; 2903 uint32_t history_size;
1861 uint32_t last_boot; 2904 uint32_t last_boot;
1862 } get_info; 2905 } get_info;
1863 struct { 2906 struct __ec_todo_unpacked {
1864 uint16_t codes[EC_PORT80_SIZE_MAX]; 2907 uint16_t codes[EC_PORT80_SIZE_MAX];
1865 } data; 2908 } data;
1866 }; 2909 };
1867} __packed; 2910} __ec_todo_packed;
1868 2911
1869struct ec_response_port80_last_boot { 2912struct ec_response_port80_last_boot {
1870 uint16_t code; 2913 uint16_t code;
1871} __packed; 2914} __ec_align2;
2915
2916/*****************************************************************************/
2917/* Temporary secure storage for host verified boot use */
2918
2919/* Number of bytes in a vstore slot */
2920#define EC_VSTORE_SLOT_SIZE 64
2921
2922/* Maximum number of vstore slots */
2923#define EC_VSTORE_SLOT_MAX 32
2924
2925/* Get persistent storage info */
2926#define EC_CMD_VSTORE_INFO 0x0049
2927struct ec_response_vstore_info {
2928 /* Indicates which slots are locked */
2929 uint32_t slot_locked;
2930 /* Total number of slots available */
2931 uint8_t slot_count;
2932} __ec_align_size1;
2933
2934/*
2935 * Read temporary secure storage
2936 *
2937 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2938 */
2939#define EC_CMD_VSTORE_READ 0x004A
2940
2941struct ec_params_vstore_read {
2942 uint8_t slot; /* Slot to read from */
2943} __ec_align1;
2944
2945struct ec_response_vstore_read {
2946 uint8_t data[EC_VSTORE_SLOT_SIZE];
2947} __ec_align1;
2948
2949/*
2950 * Write temporary secure storage and lock it.
2951 */
2952#define EC_CMD_VSTORE_WRITE 0x004B
2953
2954struct ec_params_vstore_write {
2955 uint8_t slot; /* Slot to write to */
2956 uint8_t data[EC_VSTORE_SLOT_SIZE];
2957} __ec_align1;
1872 2958
1873/*****************************************************************************/ 2959/*****************************************************************************/
1874/* Thermal engine commands. Note that there are two implementations. We'll 2960/* Thermal engine commands. Note that there are two implementations. We'll
@@ -1877,8 +2963,8 @@ struct ec_response_port80_last_boot {
1877 * Version 1 separates the CPU thermal limits from the fan control. 2963 * Version 1 separates the CPU thermal limits from the fan control.
1878 */ 2964 */
1879 2965
1880#define EC_CMD_THERMAL_SET_THRESHOLD 0x50 2966#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
1881#define EC_CMD_THERMAL_GET_THRESHOLD 0x51 2967#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
1882 2968
1883/* The version 0 structs are opaque. You have to know what they are for 2969/* The version 0 structs are opaque. You have to know what they are for
1884 * the get/set commands to make any sense. 2970 * the get/set commands to make any sense.
@@ -1889,17 +2975,17 @@ struct ec_params_thermal_set_threshold {
1889 uint8_t sensor_type; 2975 uint8_t sensor_type;
1890 uint8_t threshold_id; 2976 uint8_t threshold_id;
1891 uint16_t value; 2977 uint16_t value;
1892} __packed; 2978} __ec_align2;
1893 2979
1894/* Version 0 - get */ 2980/* Version 0 - get */
1895struct ec_params_thermal_get_threshold { 2981struct ec_params_thermal_get_threshold {
1896 uint8_t sensor_type; 2982 uint8_t sensor_type;
1897 uint8_t threshold_id; 2983 uint8_t threshold_id;
1898} __packed; 2984} __ec_align1;
1899 2985
1900struct ec_response_thermal_get_threshold { 2986struct ec_response_thermal_get_threshold {
1901 uint16_t value; 2987 uint16_t value;
1902} __packed; 2988} __ec_align2;
1903 2989
1904 2990
1905/* The version 1 structs are visible. */ 2991/* The version 1 structs are visible. */
@@ -1911,71 +2997,124 @@ enum ec_temp_thresholds {
1911 EC_TEMP_THRESH_COUNT 2997 EC_TEMP_THRESH_COUNT
1912}; 2998};
1913 2999
1914/* Thermal configuration for one temperature sensor. Temps are in degrees K. 3000/*
3001 * Thermal configuration for one temperature sensor. Temps are in degrees K.
1915 * Zero values will be silently ignored by the thermal task. 3002 * Zero values will be silently ignored by the thermal task.
3003 *
3004 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3005 * hysteresis.
3006 * For example,
3007 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3008 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3009 * EC will throttle ap when temperature >= 301 K, and release throttling when
3010 * temperature <= 299 K.
3011 *
3012 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3013 * For example,
3014 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3015 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3016 * EC will throttle ap when temperature >= 301 K, and release throttling when
3017 * temperature <= 294 K.
3018 *
3019 * Note that this structure is a sub-structure of
3020 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
1916 */ 3021 */
1917struct ec_thermal_config { 3022struct ec_thermal_config {
1918 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */ 3023 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
3024 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
1919 uint32_t temp_fan_off; /* no active cooling needed */ 3025 uint32_t temp_fan_off; /* no active cooling needed */
1920 uint32_t temp_fan_max; /* max active cooling needed */ 3026 uint32_t temp_fan_max; /* max active cooling needed */
1921} __packed; 3027} __ec_align4;
1922 3028
1923/* Version 1 - get config for one sensor. */ 3029/* Version 1 - get config for one sensor. */
1924struct ec_params_thermal_get_threshold_v1 { 3030struct ec_params_thermal_get_threshold_v1 {
1925 uint32_t sensor_num; 3031 uint32_t sensor_num;
1926} __packed; 3032} __ec_align4;
1927/* This returns a struct ec_thermal_config */ 3033/* This returns a struct ec_thermal_config */
1928 3034
1929/* Version 1 - set config for one sensor. 3035/*
1930 * Use read-modify-write for best results! */ 3036 * Version 1 - set config for one sensor.
3037 * Use read-modify-write for best results!
3038 */
1931struct ec_params_thermal_set_threshold_v1 { 3039struct ec_params_thermal_set_threshold_v1 {
1932 uint32_t sensor_num; 3040 uint32_t sensor_num;
1933 struct ec_thermal_config cfg; 3041 struct ec_thermal_config cfg;
1934} __packed; 3042} __ec_align4;
1935/* This returns no data */ 3043/* This returns no data */
1936 3044
1937/****************************************************************************/ 3045/****************************************************************************/
1938 3046
1939/* Toggle automatic fan control */ 3047/* Toggle automatic fan control */
1940#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52 3048#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
3049
3050/* Version 1 of input params */
3051struct ec_params_auto_fan_ctrl_v1 {
3052 uint8_t fan_idx;
3053} __ec_align1;
1941 3054
1942/* Get TMP006 calibration data */ 3055/* Get/Set TMP006 calibration data */
1943#define EC_CMD_TMP006_GET_CALIBRATION 0x53 3056#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3057#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
1944 3058
3059/*
3060 * The original TMP006 calibration only needed four params, but now we need
3061 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3062 * the params opaque. The v1 "get" response will include the algorithm number
3063 * and how many params it requires. That way we can change the EC code without
3064 * needing to update this file. We can also use a different algorithm on each
3065 * sensor.
3066 */
3067
3068/* This is the same struct for both v0 and v1. */
1945struct ec_params_tmp006_get_calibration { 3069struct ec_params_tmp006_get_calibration {
1946 uint8_t index; 3070 uint8_t index;
1947} __packed; 3071} __ec_align1;
1948 3072
1949struct ec_response_tmp006_get_calibration { 3073/* Version 0 */
3074struct ec_response_tmp006_get_calibration_v0 {
1950 float s0; 3075 float s0;
1951 float b0; 3076 float b0;
1952 float b1; 3077 float b1;
1953 float b2; 3078 float b2;
1954} __packed; 3079} __ec_align4;
1955 3080
1956/* Set TMP006 calibration data */ 3081struct ec_params_tmp006_set_calibration_v0 {
1957#define EC_CMD_TMP006_SET_CALIBRATION 0x54
1958
1959struct ec_params_tmp006_set_calibration {
1960 uint8_t index; 3082 uint8_t index;
1961 uint8_t reserved[3]; /* Reserved; set 0 */ 3083 uint8_t reserved[3];
1962 float s0; 3084 float s0;
1963 float b0; 3085 float b0;
1964 float b1; 3086 float b1;
1965 float b2; 3087 float b2;
1966} __packed; 3088} __ec_align4;
3089
3090/* Version 1 */
3091struct ec_response_tmp006_get_calibration_v1 {
3092 uint8_t algorithm;
3093 uint8_t num_params;
3094 uint8_t reserved[2];
3095 float val[0];
3096} __ec_align4;
3097
3098struct ec_params_tmp006_set_calibration_v1 {
3099 uint8_t index;
3100 uint8_t algorithm;
3101 uint8_t num_params;
3102 uint8_t reserved;
3103 float val[0];
3104} __ec_align4;
3105
1967 3106
1968/* Read raw TMP006 data */ 3107/* Read raw TMP006 data */
1969#define EC_CMD_TMP006_GET_RAW 0x55 3108#define EC_CMD_TMP006_GET_RAW 0x0055
1970 3109
1971struct ec_params_tmp006_get_raw { 3110struct ec_params_tmp006_get_raw {
1972 uint8_t index; 3111 uint8_t index;
1973} __packed; 3112} __ec_align1;
1974 3113
1975struct ec_response_tmp006_get_raw { 3114struct ec_response_tmp006_get_raw {
1976 int32_t t; /* In 1/100 K */ 3115 int32_t t; /* In 1/100 K */
1977 int32_t v; /* In nV */ 3116 int32_t v; /* In nV */
1978}; 3117} __ec_align4;
1979 3118
1980/*****************************************************************************/ 3119/*****************************************************************************/
1981/* MKBP - Matrix KeyBoard Protocol */ 3120/* MKBP - Matrix KeyBoard Protocol */
@@ -1990,24 +3129,24 @@ struct ec_response_tmp006_get_raw {
1990 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type 3129 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1991 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX. 3130 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
1992 */ 3131 */
1993#define EC_CMD_MKBP_STATE 0x60 3132#define EC_CMD_MKBP_STATE 0x0060
1994 3133
1995/* 3134/*
1996 * Provide information about various MKBP things. See enum ec_mkbp_info_type. 3135 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
1997 */ 3136 */
1998#define EC_CMD_MKBP_INFO 0x61 3137#define EC_CMD_MKBP_INFO 0x0061
1999 3138
2000struct ec_response_mkbp_info { 3139struct ec_response_mkbp_info {
2001 uint32_t rows; 3140 uint32_t rows;
2002 uint32_t cols; 3141 uint32_t cols;
2003 /* Formerly "switches", which was 0. */ 3142 /* Formerly "switches", which was 0. */
2004 uint8_t reserved; 3143 uint8_t reserved;
2005} __packed; 3144} __ec_align_size1;
2006 3145
2007struct ec_params_mkbp_info { 3146struct ec_params_mkbp_info {
2008 uint8_t info_type; 3147 uint8_t info_type;
2009 uint8_t event_type; 3148 uint8_t event_type;
2010} __packed; 3149} __ec_align1;
2011 3150
2012enum ec_mkbp_info_type { 3151enum ec_mkbp_info_type {
2013 /* 3152 /*
@@ -2049,17 +3188,28 @@ enum ec_mkbp_info_type {
2049}; 3188};
2050 3189
2051/* Simulate key press */ 3190/* Simulate key press */
2052#define EC_CMD_MKBP_SIMULATE_KEY 0x62 3191#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
2053 3192
2054struct ec_params_mkbp_simulate_key { 3193struct ec_params_mkbp_simulate_key {
2055 uint8_t col; 3194 uint8_t col;
2056 uint8_t row; 3195 uint8_t row;
2057 uint8_t pressed; 3196 uint8_t pressed;
2058} __packed; 3197} __ec_align1;
3198
3199#define EC_CMD_GET_KEYBOARD_ID 0x0063
3200
3201struct ec_response_keyboard_id {
3202 uint32_t keyboard_id;
3203} __ec_align4;
3204
3205enum keyboard_id {
3206 KEYBOARD_ID_UNSUPPORTED = 0,
3207 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3208};
2059 3209
2060/* Configure keyboard scanning */ 3210/* Configure keyboard scanning */
2061#define EC_CMD_MKBP_SET_CONFIG 0x64 3211#define EC_CMD_MKBP_SET_CONFIG 0x0064
2062#define EC_CMD_MKBP_GET_CONFIG 0x65 3212#define EC_CMD_MKBP_GET_CONFIG 0x0065
2063 3213
2064/* flags */ 3214/* flags */
2065enum mkbp_config_flags { 3215enum mkbp_config_flags {
@@ -2067,16 +3217,21 @@ enum mkbp_config_flags {
2067}; 3217};
2068 3218
2069enum mkbp_config_valid { 3219enum mkbp_config_valid {
2070 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0, 3220 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
2071 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1, 3221 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
2072 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3, 3222 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
2073 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4, 3223 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
2074 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5, 3224 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
2075 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6, 3225 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
2076 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7, 3226 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
2077}; 3227};
2078 3228
2079/* Configuration for our key scanning algorithm */ 3229/*
3230 * Configuration for our key scanning algorithm.
3231 *
3232 * Note that this is used as a sub-structure of
3233 * ec_{params/response}_mkbp_get_config.
3234 */
2080struct ec_mkbp_config { 3235struct ec_mkbp_config {
2081 uint32_t valid_mask; /* valid fields */ 3236 uint32_t valid_mask; /* valid fields */
2082 uint8_t flags; /* some flags (enum mkbp_config_flags) */ 3237 uint8_t flags; /* some flags (enum mkbp_config_flags) */
@@ -2096,18 +3251,18 @@ struct ec_mkbp_config {
2096 uint16_t debounce_up_us; /* time for debounce on key up */ 3251 uint16_t debounce_up_us; /* time for debounce on key up */
2097 /* maximum depth to allow for fifo (0 = no keyscan output) */ 3252 /* maximum depth to allow for fifo (0 = no keyscan output) */
2098 uint8_t fifo_max_depth; 3253 uint8_t fifo_max_depth;
2099} __packed; 3254} __ec_align_size1;
2100 3255
2101struct ec_params_mkbp_set_config { 3256struct ec_params_mkbp_set_config {
2102 struct ec_mkbp_config config; 3257 struct ec_mkbp_config config;
2103} __packed; 3258} __ec_align_size1;
2104 3259
2105struct ec_response_mkbp_get_config { 3260struct ec_response_mkbp_get_config {
2106 struct ec_mkbp_config config; 3261 struct ec_mkbp_config config;
2107} __packed; 3262} __ec_align_size1;
2108 3263
2109/* Run the key scan emulation */ 3264/* Run the key scan emulation */
2110#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66 3265#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
2111 3266
2112enum ec_keyscan_seq_cmd { 3267enum ec_keyscan_seq_cmd {
2113 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */ 3268 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
@@ -2122,23 +3277,23 @@ enum ec_collect_flags {
2122 * Indicates this scan was processed by the EC. Due to timing, some 3277 * Indicates this scan was processed by the EC. Due to timing, some
2123 * scans may be skipped. 3278 * scans may be skipped.
2124 */ 3279 */
2125 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0, 3280 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
2126}; 3281};
2127 3282
2128struct ec_collect_item { 3283struct ec_collect_item {
2129 uint8_t flags; /* some flags (enum ec_collect_flags) */ 3284 uint8_t flags; /* some flags (enum ec_collect_flags) */
2130}; 3285} __ec_align1;
2131 3286
2132struct ec_params_keyscan_seq_ctrl { 3287struct ec_params_keyscan_seq_ctrl {
2133 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */ 3288 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2134 union { 3289 union {
2135 struct { 3290 struct __ec_align1 {
2136 uint8_t active; /* still active */ 3291 uint8_t active; /* still active */
2137 uint8_t num_items; /* number of items */ 3292 uint8_t num_items; /* number of items */
2138 /* Current item being presented */ 3293 /* Current item being presented */
2139 uint8_t cur_item; 3294 uint8_t cur_item;
2140 } status; 3295 } status;
2141 struct { 3296 struct __ec_todo_unpacked {
2142 /* 3297 /*
2143 * Absolute time for this scan, measured from the 3298 * Absolute time for this scan, measured from the
2144 * start of the sequence. 3299 * start of the sequence.
@@ -2146,29 +3301,40 @@ struct ec_params_keyscan_seq_ctrl {
2146 uint32_t time_us; 3301 uint32_t time_us;
2147 uint8_t scan[0]; /* keyscan data */ 3302 uint8_t scan[0]; /* keyscan data */
2148 } add; 3303 } add;
2149 struct { 3304 struct __ec_align1 {
2150 uint8_t start_item; /* First item to return */ 3305 uint8_t start_item; /* First item to return */
2151 uint8_t num_items; /* Number of items to return */ 3306 uint8_t num_items; /* Number of items to return */
2152 } collect; 3307 } collect;
2153 }; 3308 };
2154} __packed; 3309} __ec_todo_packed;
2155 3310
2156struct ec_result_keyscan_seq_ctrl { 3311struct ec_result_keyscan_seq_ctrl {
2157 union { 3312 union {
2158 struct { 3313 struct __ec_todo_unpacked {
2159 uint8_t num_items; /* Number of items */ 3314 uint8_t num_items; /* Number of items */
2160 /* Data for each item */ 3315 /* Data for each item */
2161 struct ec_collect_item item[0]; 3316 struct ec_collect_item item[0];
2162 } collect; 3317 } collect;
2163 }; 3318 };
2164} __packed; 3319} __ec_todo_packed;
2165 3320
2166/* 3321/*
2167 * Command for retrieving the next pending MKBP event from the EC device 3322 * Get the next pending MKBP event.
2168 * 3323 *
2169 * The device replies with UNAVAILABLE if there aren't any pending events. 3324 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2170 */ 3325 */
2171#define EC_CMD_GET_NEXT_EVENT 0x67 3326#define EC_CMD_GET_NEXT_EVENT 0x0067
3327
3328#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3329
3330/*
3331 * We use the most significant bit of the event type to indicate to the host
3332 * that the EC has more MKBP events available to provide.
3333 */
3334#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3335
3336/* The mask to apply to get the raw event type */
3337#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
2172 3338
2173enum ec_mkbp_event { 3339enum ec_mkbp_event {
2174 /* Keyboard matrix changed. The event data is the new matrix state. */ 3340 /* Keyboard matrix changed. The event data is the new matrix state. */
@@ -2186,9 +3352,21 @@ enum ec_mkbp_event {
2186 /* The state of the switches have changed. */ 3352 /* The state of the switches have changed. */
2187 EC_MKBP_EVENT_SWITCH = 4, 3353 EC_MKBP_EVENT_SWITCH = 4,
2188 3354
2189 /* EC sent a sysrq command */ 3355 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3356 EC_MKBP_EVENT_FINGERPRINT = 5,
3357
3358 /*
3359 * Sysrq event: send emulated sysrq. The event data is sysrq,
3360 * corresponding to the key to be pressed.
3361 */
2190 EC_MKBP_EVENT_SYSRQ = 6, 3362 EC_MKBP_EVENT_SYSRQ = 6,
2191 3363
3364 /*
3365 * New 64-bit host event.
3366 * The event data is 8 bytes of host event flags.
3367 */
3368 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3369
2192 /* Notify the AP that something happened on CEC */ 3370 /* Notify the AP that something happened on CEC */
2193 EC_MKBP_EVENT_CEC_EVENT = 8, 3371 EC_MKBP_EVENT_CEC_EVENT = 8,
2194 3372
@@ -2198,65 +3376,140 @@ enum ec_mkbp_event {
2198 /* Number of MKBP events */ 3376 /* Number of MKBP events */
2199 EC_MKBP_EVENT_COUNT, 3377 EC_MKBP_EVENT_COUNT,
2200}; 3378};
3379BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
2201 3380
2202union ec_response_get_next_data { 3381union __ec_align_offset1 ec_response_get_next_data {
2203 uint8_t key_matrix[13]; 3382 uint8_t key_matrix[13];
2204 3383
2205 /* Unaligned */ 3384 /* Unaligned */
2206 uint32_t host_event; 3385 uint32_t host_event;
3386 uint64_t host_event64;
3387
3388 struct __ec_todo_unpacked {
3389 /* For aligning the fifo_info */
3390 uint8_t reserved[3];
3391 struct ec_response_motion_sense_fifo_info info;
3392 } sensor_fifo;
3393
3394 uint32_t buttons;
3395
3396 uint32_t switches;
2207 3397
2208 uint32_t buttons; 3398 uint32_t fp_events;
2209 uint32_t switches; 3399
2210 uint32_t sysrq; 3400 uint32_t sysrq;
2211} __packed;
2212 3401
2213union ec_response_get_next_data_v1 { 3402 /* CEC events from enum mkbp_cec_event */
3403 uint32_t cec_events;
3404};
3405
3406union __ec_align_offset1 ec_response_get_next_data_v1 {
2214 uint8_t key_matrix[16]; 3407 uint8_t key_matrix[16];
3408
3409 /* Unaligned */
2215 uint32_t host_event; 3410 uint32_t host_event;
3411 uint64_t host_event64;
3412
3413 struct __ec_todo_unpacked {
3414 /* For aligning the fifo_info */
3415 uint8_t reserved[3];
3416 struct ec_response_motion_sense_fifo_info info;
3417 } sensor_fifo;
3418
2216 uint32_t buttons; 3419 uint32_t buttons;
3420
2217 uint32_t switches; 3421 uint32_t switches;
3422
3423 uint32_t fp_events;
3424
2218 uint32_t sysrq; 3425 uint32_t sysrq;
3426
3427 /* CEC events from enum mkbp_cec_event */
2219 uint32_t cec_events; 3428 uint32_t cec_events;
3429
2220 uint8_t cec_message[16]; 3430 uint8_t cec_message[16];
2221} __packed; 3431};
3432BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
2222 3433
2223struct ec_response_get_next_event { 3434struct ec_response_get_next_event {
2224 uint8_t event_type; 3435 uint8_t event_type;
2225 /* Followed by event data if any */ 3436 /* Followed by event data if any */
2226 union ec_response_get_next_data data; 3437 union ec_response_get_next_data data;
2227} __packed; 3438} __ec_align1;
2228 3439
2229struct ec_response_get_next_event_v1 { 3440struct ec_response_get_next_event_v1 {
2230 uint8_t event_type; 3441 uint8_t event_type;
2231 /* Followed by event data if any */ 3442 /* Followed by event data if any */
2232 union ec_response_get_next_data_v1 data; 3443 union ec_response_get_next_data_v1 data;
2233} __packed; 3444} __ec_align1;
2234 3445
2235/* Bit indices for buttons and switches.*/ 3446/* Bit indices for buttons and switches.*/
2236/* Buttons */ 3447/* Buttons */
2237#define EC_MKBP_POWER_BUTTON 0 3448#define EC_MKBP_POWER_BUTTON 0
2238#define EC_MKBP_VOL_UP 1 3449#define EC_MKBP_VOL_UP 1
2239#define EC_MKBP_VOL_DOWN 2 3450#define EC_MKBP_VOL_DOWN 2
3451#define EC_MKBP_RECOVERY 3
2240 3452
2241/* Switches */ 3453/* Switches */
2242#define EC_MKBP_LID_OPEN 0 3454#define EC_MKBP_LID_OPEN 0
2243#define EC_MKBP_TABLET_MODE 1 3455#define EC_MKBP_TABLET_MODE 1
2244#define EC_MKBP_BASE_ATTACHED 2 3456#define EC_MKBP_BASE_ATTACHED 2
2245 3457
3458/* Run keyboard factory test scanning */
3459#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3460
3461struct ec_response_keyboard_factory_test {
3462 uint16_t shorted; /* Keyboard pins are shorted */
3463} __ec_align2;
3464
3465/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3466#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3467#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3468#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3469#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3470 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3471#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3472#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3473#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3474 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
3475#define EC_MKBP_FP_ENROLL BIT(27)
3476#define EC_MKBP_FP_MATCH BIT(28)
3477#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3478#define EC_MKBP_FP_FINGER_UP BIT(30)
3479#define EC_MKBP_FP_IMAGE_READY BIT(31)
3480/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3481#define EC_MKBP_FP_ERR_ENROLL_OK 0
3482#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3483#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3484#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3485#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3486/* Can be used to detect if image was usable for enrollment or not. */
3487#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3488/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3489#define EC_MKBP_FP_ERR_MATCH_NO 0
3490#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
3491#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
3492#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3493#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3494#define EC_MKBP_FP_ERR_MATCH_YES 1
3495#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3496#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3497
3498
2246/*****************************************************************************/ 3499/*****************************************************************************/
2247/* Temperature sensor commands */ 3500/* Temperature sensor commands */
2248 3501
2249/* Read temperature sensor info */ 3502/* Read temperature sensor info */
2250#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70 3503#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
2251 3504
2252struct ec_params_temp_sensor_get_info { 3505struct ec_params_temp_sensor_get_info {
2253 uint8_t id; 3506 uint8_t id;
2254} __packed; 3507} __ec_align1;
2255 3508
2256struct ec_response_temp_sensor_get_info { 3509struct ec_response_temp_sensor_get_info {
2257 char sensor_name[32]; 3510 char sensor_name[32];
2258 uint8_t sensor_type; 3511 uint8_t sensor_type;
2259} __packed; 3512} __ec_align1;
2260 3513
2261/*****************************************************************************/ 3514/*****************************************************************************/
2262 3515
@@ -2269,49 +3522,131 @@ struct ec_response_temp_sensor_get_info {
2269/*****************************************************************************/ 3522/*****************************************************************************/
2270/* Host event commands */ 3523/* Host event commands */
2271 3524
3525
3526/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
2272/* 3527/*
2273 * Host event mask params and response structures, shared by all of the host 3528 * Host event mask params and response structures, shared by all of the host
2274 * event commands below. 3529 * event commands below.
2275 */ 3530 */
2276struct ec_params_host_event_mask { 3531struct ec_params_host_event_mask {
2277 uint32_t mask; 3532 uint32_t mask;
2278} __packed; 3533} __ec_align4;
2279 3534
2280struct ec_response_host_event_mask { 3535struct ec_response_host_event_mask {
2281 uint32_t mask; 3536 uint32_t mask;
2282} __packed; 3537} __ec_align4;
2283 3538
2284/* These all use ec_response_host_event_mask */ 3539/* These all use ec_response_host_event_mask */
2285#define EC_CMD_HOST_EVENT_GET_B 0x87 3540#define EC_CMD_HOST_EVENT_GET_B 0x0087
2286#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88 3541#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
2287#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89 3542#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
2288#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d 3543#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
2289 3544
2290/* These all use ec_params_host_event_mask */ 3545/* These all use ec_params_host_event_mask */
2291#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a 3546#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
2292#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b 3547#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
2293#define EC_CMD_HOST_EVENT_CLEAR 0x8c 3548#define EC_CMD_HOST_EVENT_CLEAR 0x008C
2294#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e 3549#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
2295#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f 3550#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
3551
3552/*
3553 * Unified host event programming interface - Should be used by newer versions
3554 * of BIOS/OS to program host events and masks
3555 */
3556
3557struct ec_params_host_event {
3558
3559 /* Action requested by host - one of enum ec_host_event_action. */
3560 uint8_t action;
3561
3562 /*
3563 * Mask type that the host requested the action on - one of
3564 * enum ec_host_event_mask_type.
3565 */
3566 uint8_t mask_type;
3567
3568 /* Set to 0, ignore on read */
3569 uint16_t reserved;
3570
3571 /* Value to be used in case of set operations. */
3572 uint64_t value;
3573} __ec_align4;
3574
3575/*
3576 * Response structure returned by EC_CMD_HOST_EVENT.
3577 * Update the value on a GET request. Set to 0 on GET/CLEAR
3578 */
3579
3580struct ec_response_host_event {
3581
3582 /* Mask value in case of get operation */
3583 uint64_t value;
3584} __ec_align4;
3585
3586enum ec_host_event_action {
3587 /*
3588 * params.value is ignored. Value of mask_type populated
3589 * in response.value
3590 */
3591 EC_HOST_EVENT_GET,
3592
3593 /* Bits in params.value are set */
3594 EC_HOST_EVENT_SET,
3595
3596 /* Bits in params.value are cleared */
3597 EC_HOST_EVENT_CLEAR,
3598};
3599
3600enum ec_host_event_mask_type {
3601
3602 /* Main host event copy */
3603 EC_HOST_EVENT_MAIN,
3604
3605 /* Copy B of host events */
3606 EC_HOST_EVENT_B,
3607
3608 /* SCI Mask */
3609 EC_HOST_EVENT_SCI_MASK,
3610
3611 /* SMI Mask */
3612 EC_HOST_EVENT_SMI_MASK,
3613
3614 /* Mask of events that should be always reported in hostevents */
3615 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3616
3617 /* Active wake mask */
3618 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3619
3620 /* Lazy wake mask for S0ix */
3621 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3622
3623 /* Lazy wake mask for S3 */
3624 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3625
3626 /* Lazy wake mask for S5 */
3627 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3628};
3629
3630#define EC_CMD_HOST_EVENT 0x00A4
2296 3631
2297/*****************************************************************************/ 3632/*****************************************************************************/
2298/* Switch commands */ 3633/* Switch commands */
2299 3634
2300/* Enable/disable LCD backlight */ 3635/* Enable/disable LCD backlight */
2301#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90 3636#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
2302 3637
2303struct ec_params_switch_enable_backlight { 3638struct ec_params_switch_enable_backlight {
2304 uint8_t enabled; 3639 uint8_t enabled;
2305} __packed; 3640} __ec_align1;
2306 3641
2307/* Enable/disable WLAN/Bluetooth */ 3642/* Enable/disable WLAN/Bluetooth */
2308#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91 3643#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
2309#define EC_VER_SWITCH_ENABLE_WIRELESS 1 3644#define EC_VER_SWITCH_ENABLE_WIRELESS 1
2310 3645
2311/* Version 0 params; no response */ 3646/* Version 0 params; no response */
2312struct ec_params_switch_enable_wireless_v0 { 3647struct ec_params_switch_enable_wireless_v0 {
2313 uint8_t enabled; 3648 uint8_t enabled;
2314} __packed; 3649} __ec_align1;
2315 3650
2316/* Version 1 params */ 3651/* Version 1 params */
2317struct ec_params_switch_enable_wireless_v1 { 3652struct ec_params_switch_enable_wireless_v1 {
@@ -2330,7 +3665,7 @@ struct ec_params_switch_enable_wireless_v1 {
2330 3665
2331 /* Which flags to copy from suspend_flags */ 3666 /* Which flags to copy from suspend_flags */
2332 uint8_t suspend_mask; 3667 uint8_t suspend_mask;
2333} __packed; 3668} __ec_align1;
2334 3669
2335/* Version 1 response */ 3670/* Version 1 response */
2336struct ec_response_switch_enable_wireless_v1 { 3671struct ec_response_switch_enable_wireless_v1 {
@@ -2339,55 +3674,56 @@ struct ec_response_switch_enable_wireless_v1 {
2339 3674
2340 /* Flags to leave enabled in S3 */ 3675 /* Flags to leave enabled in S3 */
2341 uint8_t suspend_flags; 3676 uint8_t suspend_flags;
2342} __packed; 3677} __ec_align1;
2343 3678
2344/*****************************************************************************/ 3679/*****************************************************************************/
2345/* GPIO commands. Only available on EC if write protect has been disabled. */ 3680/* GPIO commands. Only available on EC if write protect has been disabled. */
2346 3681
2347/* Set GPIO output value */ 3682/* Set GPIO output value */
2348#define EC_CMD_GPIO_SET 0x92 3683#define EC_CMD_GPIO_SET 0x0092
2349 3684
2350struct ec_params_gpio_set { 3685struct ec_params_gpio_set {
2351 char name[32]; 3686 char name[32];
2352 uint8_t val; 3687 uint8_t val;
2353} __packed; 3688} __ec_align1;
2354 3689
2355/* Get GPIO value */ 3690/* Get GPIO value */
2356#define EC_CMD_GPIO_GET 0x93 3691#define EC_CMD_GPIO_GET 0x0093
2357 3692
2358/* Version 0 of input params and response */ 3693/* Version 0 of input params and response */
2359struct ec_params_gpio_get { 3694struct ec_params_gpio_get {
2360 char name[32]; 3695 char name[32];
2361} __packed; 3696} __ec_align1;
3697
2362struct ec_response_gpio_get { 3698struct ec_response_gpio_get {
2363 uint8_t val; 3699 uint8_t val;
2364} __packed; 3700} __ec_align1;
2365 3701
2366/* Version 1 of input params and response */ 3702/* Version 1 of input params and response */
2367struct ec_params_gpio_get_v1 { 3703struct ec_params_gpio_get_v1 {
2368 uint8_t subcmd; 3704 uint8_t subcmd;
2369 union { 3705 union {
2370 struct { 3706 struct __ec_align1 {
2371 char name[32]; 3707 char name[32];
2372 } get_value_by_name; 3708 } get_value_by_name;
2373 struct { 3709 struct __ec_align1 {
2374 uint8_t index; 3710 uint8_t index;
2375 } get_info; 3711 } get_info;
2376 }; 3712 };
2377} __packed; 3713} __ec_align1;
2378 3714
2379struct ec_response_gpio_get_v1 { 3715struct ec_response_gpio_get_v1 {
2380 union { 3716 union {
2381 struct { 3717 struct __ec_align1 {
2382 uint8_t val; 3718 uint8_t val;
2383 } get_value_by_name, get_count; 3719 } get_value_by_name, get_count;
2384 struct { 3720 struct __ec_todo_unpacked {
2385 uint8_t val; 3721 uint8_t val;
2386 char name[32]; 3722 char name[32];
2387 uint32_t flags; 3723 uint32_t flags;
2388 } get_info; 3724 } get_info;
2389 }; 3725 };
2390} __packed; 3726} __ec_todo_packed;
2391 3727
2392enum gpio_get_subcmd { 3728enum gpio_get_subcmd {
2393 EC_GPIO_GET_BY_NAME = 0, 3729 EC_GPIO_GET_BY_NAME = 0,
@@ -2399,25 +3735,28 @@ enum gpio_get_subcmd {
2399/* I2C commands. Only available when flash write protect is unlocked. */ 3735/* I2C commands. Only available when flash write protect is unlocked. */
2400 3736
2401/* 3737/*
2402 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be 3738 * CAUTION: These commands are deprecated, and are not supported anymore in EC
2403 * removed soon. Use EC_CMD_I2C_XFER instead. 3739 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3740 *
3741 * Use EC_CMD_I2C_PASSTHRU instead.
2404 */ 3742 */
2405 3743
2406/* Read I2C bus */ 3744/* Read I2C bus */
2407#define EC_CMD_I2C_READ 0x94 3745#define EC_CMD_I2C_READ 0x0094
2408 3746
2409struct ec_params_i2c_read { 3747struct ec_params_i2c_read {
2410 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */ 3748 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2411 uint8_t read_size; /* Either 8 or 16. */ 3749 uint8_t read_size; /* Either 8 or 16. */
2412 uint8_t port; 3750 uint8_t port;
2413 uint8_t offset; 3751 uint8_t offset;
2414} __packed; 3752} __ec_align_size1;
3753
2415struct ec_response_i2c_read { 3754struct ec_response_i2c_read {
2416 uint16_t data; 3755 uint16_t data;
2417} __packed; 3756} __ec_align2;
2418 3757
2419/* Write I2C bus */ 3758/* Write I2C bus */
2420#define EC_CMD_I2C_WRITE 0x95 3759#define EC_CMD_I2C_WRITE 0x0095
2421 3760
2422struct ec_params_i2c_write { 3761struct ec_params_i2c_write {
2423 uint16_t data; 3762 uint16_t data;
@@ -2425,7 +3764,7 @@ struct ec_params_i2c_write {
2425 uint8_t write_size; /* Either 8 or 16. */ 3764 uint8_t write_size; /* Either 8 or 16. */
2426 uint8_t port; 3765 uint8_t port;
2427 uint8_t offset; 3766 uint8_t offset;
2428} __packed; 3767} __ec_align_size1;
2429 3768
2430/*****************************************************************************/ 3769/*****************************************************************************/
2431/* Charge state commands. Only available when flash write protect unlocked. */ 3770/* Charge state commands. Only available when flash write protect unlocked. */
@@ -2433,7 +3772,7 @@ struct ec_params_i2c_write {
2433/* Force charge state machine to stop charging the battery or force it to 3772/* Force charge state machine to stop charging the battery or force it to
2434 * discharge the battery. 3773 * discharge the battery.
2435 */ 3774 */
2436#define EC_CMD_CHARGE_CONTROL 0x96 3775#define EC_CMD_CHARGE_CONTROL 0x0096
2437#define EC_VER_CHARGE_CONTROL 1 3776#define EC_VER_CHARGE_CONTROL 1
2438 3777
2439enum ec_charge_control_mode { 3778enum ec_charge_control_mode {
@@ -2444,13 +3783,12 @@ enum ec_charge_control_mode {
2444 3783
2445struct ec_params_charge_control { 3784struct ec_params_charge_control {
2446 uint32_t mode; /* enum charge_control_mode */ 3785 uint32_t mode; /* enum charge_control_mode */
2447} __packed; 3786} __ec_align4;
2448 3787
2449/*****************************************************************************/ 3788/*****************************************************************************/
2450/* Console commands. Only available when flash write protect is unlocked. */
2451 3789
2452/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */ 3790/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2453#define EC_CMD_CONSOLE_SNAPSHOT 0x97 3791#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
2454 3792
2455/* 3793/*
2456 * Read data from the saved snapshot. If the subcmd parameter is 3794 * Read data from the saved snapshot. If the subcmd parameter is
@@ -2464,7 +3802,7 @@ struct ec_params_charge_control {
2464 * Response is null-terminated string. Empty string, if there is no more 3802 * Response is null-terminated string. Empty string, if there is no more
2465 * remaining output. 3803 * remaining output.
2466 */ 3804 */
2467#define EC_CMD_CONSOLE_READ 0x98 3805#define EC_CMD_CONSOLE_READ 0x0098
2468 3806
2469enum ec_console_read_subcmd { 3807enum ec_console_read_subcmd {
2470 CONSOLE_READ_NEXT = 0, 3808 CONSOLE_READ_NEXT = 0,
@@ -2473,7 +3811,7 @@ enum ec_console_read_subcmd {
2473 3811
2474struct ec_params_console_read_v1 { 3812struct ec_params_console_read_v1 {
2475 uint8_t subcmd; /* enum ec_console_read_subcmd */ 3813 uint8_t subcmd; /* enum ec_console_read_subcmd */
2476} __packed; 3814} __ec_align1;
2477 3815
2478/*****************************************************************************/ 3816/*****************************************************************************/
2479 3817
@@ -2484,14 +3822,13 @@ struct ec_params_console_read_v1 {
2484 * EC_RES_SUCCESS if the command was successful. 3822 * EC_RES_SUCCESS if the command was successful.
2485 * EC_RES_ERROR if the cut off command failed. 3823 * EC_RES_ERROR if the cut off command failed.
2486 */ 3824 */
3825#define EC_CMD_BATTERY_CUT_OFF 0x0099
2487 3826
2488#define EC_CMD_BATTERY_CUT_OFF 0x99 3827#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
2489
2490#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2491 3828
2492struct ec_params_battery_cutoff { 3829struct ec_params_battery_cutoff {
2493 uint8_t flags; 3830 uint8_t flags;
2494} __packed; 3831} __ec_align1;
2495 3832
2496/*****************************************************************************/ 3833/*****************************************************************************/
2497/* USB port mux control. */ 3834/* USB port mux control. */
@@ -2499,11 +3836,11 @@ struct ec_params_battery_cutoff {
2499/* 3836/*
2500 * Switch USB mux or return to automatic switching. 3837 * Switch USB mux or return to automatic switching.
2501 */ 3838 */
2502#define EC_CMD_USB_MUX 0x9a 3839#define EC_CMD_USB_MUX 0x009A
2503 3840
2504struct ec_params_usb_mux { 3841struct ec_params_usb_mux {
2505 uint8_t mux; 3842 uint8_t mux;
2506} __packed; 3843} __ec_align1;
2507 3844
2508/*****************************************************************************/ 3845/*****************************************************************************/
2509/* LDOs / FETs control. */ 3846/* LDOs / FETs control. */
@@ -2516,25 +3853,25 @@ enum ec_ldo_state {
2516/* 3853/*
2517 * Switch on/off a LDO. 3854 * Switch on/off a LDO.
2518 */ 3855 */
2519#define EC_CMD_LDO_SET 0x9b 3856#define EC_CMD_LDO_SET 0x009B
2520 3857
2521struct ec_params_ldo_set { 3858struct ec_params_ldo_set {
2522 uint8_t index; 3859 uint8_t index;
2523 uint8_t state; 3860 uint8_t state;
2524} __packed; 3861} __ec_align1;
2525 3862
2526/* 3863/*
2527 * Get LDO state. 3864 * Get LDO state.
2528 */ 3865 */
2529#define EC_CMD_LDO_GET 0x9c 3866#define EC_CMD_LDO_GET 0x009C
2530 3867
2531struct ec_params_ldo_get { 3868struct ec_params_ldo_get {
2532 uint8_t index; 3869 uint8_t index;
2533} __packed; 3870} __ec_align1;
2534 3871
2535struct ec_response_ldo_get { 3872struct ec_response_ldo_get {
2536 uint8_t state; 3873 uint8_t state;
2537} __packed; 3874} __ec_align1;
2538 3875
2539/*****************************************************************************/ 3876/*****************************************************************************/
2540/* Power info. */ 3877/* Power info. */
@@ -2542,7 +3879,7 @@ struct ec_response_ldo_get {
2542/* 3879/*
2543 * Get power info. 3880 * Get power info.
2544 */ 3881 */
2545#define EC_CMD_POWER_INFO 0x9d 3882#define EC_CMD_POWER_INFO 0x009D
2546 3883
2547struct ec_response_power_info { 3884struct ec_response_power_info {
2548 uint32_t usb_dev_type; 3885 uint32_t usb_dev_type;
@@ -2550,21 +3887,21 @@ struct ec_response_power_info {
2550 uint16_t voltage_system; 3887 uint16_t voltage_system;
2551 uint16_t current_system; 3888 uint16_t current_system;
2552 uint16_t usb_current_limit; 3889 uint16_t usb_current_limit;
2553} __packed; 3890} __ec_align4;
2554 3891
2555/*****************************************************************************/ 3892/*****************************************************************************/
2556/* I2C passthru command */ 3893/* I2C passthru command */
2557 3894
2558#define EC_CMD_I2C_PASSTHRU 0x9e 3895#define EC_CMD_I2C_PASSTHRU 0x009E
2559 3896
2560/* Read data; if not present, message is a write */ 3897/* Read data; if not present, message is a write */
2561#define EC_I2C_FLAG_READ (1 << 15) 3898#define EC_I2C_FLAG_READ BIT(15)
2562 3899
2563/* Mask for address */ 3900/* Mask for address */
2564#define EC_I2C_ADDR_MASK 0x3ff 3901#define EC_I2C_ADDR_MASK 0x3ff
2565 3902
2566#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */ 3903#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
2567#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */ 3904#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
2568 3905
2569/* Any error */ 3906/* Any error */
2570#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT) 3907#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
@@ -2572,49 +3909,49 @@ struct ec_response_power_info {
2572struct ec_params_i2c_passthru_msg { 3909struct ec_params_i2c_passthru_msg {
2573 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */ 3910 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2574 uint16_t len; /* Number of bytes to read or write */ 3911 uint16_t len; /* Number of bytes to read or write */
2575} __packed; 3912} __ec_align2;
2576 3913
2577struct ec_params_i2c_passthru { 3914struct ec_params_i2c_passthru {
2578 uint8_t port; /* I2C port number */ 3915 uint8_t port; /* I2C port number */
2579 uint8_t num_msgs; /* Number of messages */ 3916 uint8_t num_msgs; /* Number of messages */
2580 struct ec_params_i2c_passthru_msg msg[]; 3917 struct ec_params_i2c_passthru_msg msg[];
2581 /* Data to write for all messages is concatenated here */ 3918 /* Data to write for all messages is concatenated here */
2582} __packed; 3919} __ec_align2;
2583 3920
2584struct ec_response_i2c_passthru { 3921struct ec_response_i2c_passthru {
2585 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */ 3922 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2586 uint8_t num_msgs; /* Number of messages processed */ 3923 uint8_t num_msgs; /* Number of messages processed */
2587 uint8_t data[]; /* Data read by messages concatenated here */ 3924 uint8_t data[]; /* Data read by messages concatenated here */
2588} __packed; 3925} __ec_align1;
2589 3926
2590/*****************************************************************************/ 3927/*****************************************************************************/
2591/* Power button hang detect */ 3928/* Power button hang detect */
2592 3929
2593#define EC_CMD_HANG_DETECT 0x9f 3930#define EC_CMD_HANG_DETECT 0x009F
2594 3931
2595/* Reasons to start hang detection timer */ 3932/* Reasons to start hang detection timer */
2596/* Power button pressed */ 3933/* Power button pressed */
2597#define EC_HANG_START_ON_POWER_PRESS (1 << 0) 3934#define EC_HANG_START_ON_POWER_PRESS BIT(0)
2598 3935
2599/* Lid closed */ 3936/* Lid closed */
2600#define EC_HANG_START_ON_LID_CLOSE (1 << 1) 3937#define EC_HANG_START_ON_LID_CLOSE BIT(1)
2601 3938
2602 /* Lid opened */ 3939 /* Lid opened */
2603#define EC_HANG_START_ON_LID_OPEN (1 << 2) 3940#define EC_HANG_START_ON_LID_OPEN BIT(2)
2604 3941
2605/* Start of AP S3->S0 transition (booting or resuming from suspend) */ 3942/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2606#define EC_HANG_START_ON_RESUME (1 << 3) 3943#define EC_HANG_START_ON_RESUME BIT(3)
2607 3944
2608/* Reasons to cancel hang detection */ 3945/* Reasons to cancel hang detection */
2609 3946
2610/* Power button released */ 3947/* Power button released */
2611#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8) 3948#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
2612 3949
2613/* Any host command from AP received */ 3950/* Any host command from AP received */
2614#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9) 3951#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
2615 3952
2616/* Stop on end of AP S0->S3 transition (suspending or shutting down) */ 3953/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2617#define EC_HANG_STOP_ON_SUSPEND (1 << 10) 3954#define EC_HANG_STOP_ON_SUSPEND BIT(10)
2618 3955
2619/* 3956/*
2620 * If this flag is set, all the other fields are ignored, and the hang detect 3957 * If this flag is set, all the other fields are ignored, and the hang detect
@@ -2622,14 +3959,14 @@ struct ec_response_i2c_passthru {
2622 * without reconfiguring any of the other hang detect settings. Note that 3959 * without reconfiguring any of the other hang detect settings. Note that
2623 * you must previously have configured the timeouts. 3960 * you must previously have configured the timeouts.
2624 */ 3961 */
2625#define EC_HANG_START_NOW (1 << 30) 3962#define EC_HANG_START_NOW BIT(30)
2626 3963
2627/* 3964/*
2628 * If this flag is set, all the other fields are ignored (including 3965 * If this flag is set, all the other fields are ignored (including
2629 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer 3966 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2630 * without reconfiguring any of the other hang detect settings. 3967 * without reconfiguring any of the other hang detect settings.
2631 */ 3968 */
2632#define EC_HANG_STOP_NOW (1 << 31) 3969#define EC_HANG_STOP_NOW BIT(31)
2633 3970
2634struct ec_params_hang_detect { 3971struct ec_params_hang_detect {
2635 /* Flags; see EC_HANG_* */ 3972 /* Flags; see EC_HANG_* */
@@ -2640,7 +3977,7 @@ struct ec_params_hang_detect {
2640 3977
2641 /* Timeout in msec before generating warm reboot, if enabled */ 3978 /* Timeout in msec before generating warm reboot, if enabled */
2642 uint16_t warm_reboot_timeout_msec; 3979 uint16_t warm_reboot_timeout_msec;
2643} __packed; 3980} __ec_align4;
2644 3981
2645/*****************************************************************************/ 3982/*****************************************************************************/
2646/* Commands for battery charging */ 3983/* Commands for battery charging */
@@ -2649,7 +3986,7 @@ struct ec_params_hang_detect {
2649 * This is the single catch-all host command to exchange data regarding the 3986 * This is the single catch-all host command to exchange data regarding the
2650 * charge state machine (v2 and up). 3987 * charge state machine (v2 and up).
2651 */ 3988 */
2652#define EC_CMD_CHARGE_STATE 0xa0 3989#define EC_CMD_CHARGE_STATE 0x00A0
2653 3990
2654/* Subcommands for this host command */ 3991/* Subcommands for this host command */
2655enum charge_state_command { 3992enum charge_state_command {
@@ -2669,6 +4006,11 @@ enum charge_state_params {
2669 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */ 4006 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2670 CS_PARAM_CHG_STATUS, /* charger-specific status */ 4007 CS_PARAM_CHG_STATUS, /* charger-specific status */
2671 CS_PARAM_CHG_OPTION, /* charger-specific options */ 4008 CS_PARAM_CHG_OPTION, /* charger-specific options */
4009 CS_PARAM_LIMIT_POWER, /*
4010 * Check if power is limited due to
4011 * low battery and / or a weak external
4012 * charger. READ ONLY.
4013 */
2672 /* How many so far? */ 4014 /* How many so far? */
2673 CS_NUM_BASE_PARAMS, 4015 CS_NUM_BASE_PARAMS,
2674 4016
@@ -2676,30 +4018,39 @@ enum charge_state_params {
2676 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, 4018 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2677 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, 4019 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2678 4020
4021 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4022 CS_PARAM_DEBUG_MIN = 0x20000,
4023 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4024 CS_PARAM_DEBUG_MANUAL_MODE,
4025 CS_PARAM_DEBUG_SEEMS_DEAD,
4026 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4027 CS_PARAM_DEBUG_BATT_REMOVED,
4028 CS_PARAM_DEBUG_MANUAL_CURRENT,
4029 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4030 CS_PARAM_DEBUG_MAX = 0x2ffff,
4031
2679 /* Other custom param ranges go here... */ 4032 /* Other custom param ranges go here... */
2680}; 4033};
2681 4034
2682struct ec_params_charge_state { 4035struct ec_params_charge_state {
2683 uint8_t cmd; /* enum charge_state_command */ 4036 uint8_t cmd; /* enum charge_state_command */
2684 union { 4037 union {
2685 struct { 4038 /* get_state has no args */
2686 /* no args */
2687 } get_state;
2688 4039
2689 struct { 4040 struct __ec_todo_unpacked {
2690 uint32_t param; /* enum charge_state_param */ 4041 uint32_t param; /* enum charge_state_param */
2691 } get_param; 4042 } get_param;
2692 4043
2693 struct { 4044 struct __ec_todo_unpacked {
2694 uint32_t param; /* param to set */ 4045 uint32_t param; /* param to set */
2695 uint32_t value; /* value to set */ 4046 uint32_t value; /* value to set */
2696 } set_param; 4047 } set_param;
2697 }; 4048 };
2698} __packed; 4049} __ec_todo_packed;
2699 4050
2700struct ec_response_charge_state { 4051struct ec_response_charge_state {
2701 union { 4052 union {
2702 struct { 4053 struct __ec_align4 {
2703 int ac; 4054 int ac;
2704 int chg_voltage; 4055 int chg_voltage;
2705 int chg_current; 4056 int chg_current;
@@ -2707,24 +4058,23 @@ struct ec_response_charge_state {
2707 int batt_state_of_charge; 4058 int batt_state_of_charge;
2708 } get_state; 4059 } get_state;
2709 4060
2710 struct { 4061 struct __ec_align4 {
2711 uint32_t value; 4062 uint32_t value;
2712 } get_param; 4063 } get_param;
2713 struct { 4064
2714 /* no return values */ 4065 /* set_param returns no args */
2715 } set_param;
2716 }; 4066 };
2717} __packed; 4067} __ec_align4;
2718 4068
2719 4069
2720/* 4070/*
2721 * Set maximum battery charging current. 4071 * Set maximum battery charging current.
2722 */ 4072 */
2723#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1 4073#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
2724 4074
2725struct ec_params_current_limit { 4075struct ec_params_current_limit {
2726 uint32_t limit; /* in mA */ 4076 uint32_t limit; /* in mA */
2727} __packed; 4077} __ec_align4;
2728 4078
2729/* 4079/*
2730 * Set maximum external voltage / current. 4080 * Set maximum external voltage / current.
@@ -2735,23 +4085,69 @@ struct ec_params_current_limit {
2735struct ec_params_external_power_limit_v1 { 4085struct ec_params_external_power_limit_v1 {
2736 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */ 4086 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2737 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */ 4087 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2738} __packed; 4088} __ec_align2;
2739 4089
2740#define EC_POWER_LIMIT_NONE 0xffff 4090#define EC_POWER_LIMIT_NONE 0xffff
2741 4091
4092/*
4093 * Set maximum voltage & current of a dedicated charge port
4094 */
4095#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4096
4097struct ec_params_dedicated_charger_limit {
4098 uint16_t current_lim; /* in mA */
4099 uint16_t voltage_lim; /* in mV */
4100} __ec_align2;
4101
4102/*****************************************************************************/
4103/* Hibernate/Deep Sleep Commands */
4104
4105/* Set the delay before going into hibernation. */
4106#define EC_CMD_HIBERNATION_DELAY 0x00A8
4107
4108struct ec_params_hibernation_delay {
4109 /*
4110 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4111 * current settings without changing them.
4112 */
4113 uint32_t seconds;
4114} __ec_align4;
4115
4116struct ec_response_hibernation_delay {
4117 /*
4118 * The current time in seconds in which the system has been in the G3
4119 * state. This value is reset if the EC transitions out of G3.
4120 */
4121 uint32_t time_g3;
4122
4123 /*
4124 * The current time remaining in seconds until the EC should hibernate.
4125 * This value is also reset if the EC transitions out of G3.
4126 */
4127 uint32_t time_remaining;
4128
4129 /*
4130 * The current time in seconds that the EC should wait in G3 before
4131 * hibernating.
4132 */
4133 uint32_t hibernate_delay;
4134} __ec_align4;
4135
2742/* Inform the EC when entering a sleep state */ 4136/* Inform the EC when entering a sleep state */
2743#define EC_CMD_HOST_SLEEP_EVENT 0xa9 4137#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
2744 4138
2745enum host_sleep_event { 4139enum host_sleep_event {
2746 HOST_SLEEP_EVENT_S3_SUSPEND = 1, 4140 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2747 HOST_SLEEP_EVENT_S3_RESUME = 2, 4141 HOST_SLEEP_EVENT_S3_RESUME = 2,
2748 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3, 4142 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2749 HOST_SLEEP_EVENT_S0IX_RESUME = 4 4143 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4144 /* S3 suspend with additional enabled wake sources */
4145 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
2750}; 4146};
2751 4147
2752struct ec_params_host_sleep_event { 4148struct ec_params_host_sleep_event {
2753 uint8_t sleep_event; 4149 uint8_t sleep_event;
2754} __packed; 4150} __ec_align1;
2755 4151
2756/* 4152/*
2757 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep 4153 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
@@ -2782,7 +4178,7 @@ struct ec_params_host_sleep_event_v1 {
2782 4178
2783 /* No parameters for non-suspend messages. */ 4179 /* No parameters for non-suspend messages. */
2784 }; 4180 };
2785} __packed; 4181} __ec_align2;
2786 4182
2787/* A timeout occurred when this bit is set */ 4183/* A timeout occurred when this bit is set */
2788#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000 4184#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
@@ -2808,42 +4204,72 @@ struct ec_response_host_sleep_event_v1 {
2808 4204
2809 /* No response fields for non-resume messages. */ 4205 /* No response fields for non-resume messages. */
2810 }; 4206 };
2811} __packed; 4207} __ec_align4;
4208
4209/*****************************************************************************/
4210/* Device events */
4211#define EC_CMD_DEVICE_EVENT 0x00AA
4212
4213enum ec_device_event {
4214 EC_DEVICE_EVENT_TRACKPAD,
4215 EC_DEVICE_EVENT_DSP,
4216 EC_DEVICE_EVENT_WIFI,
4217};
4218
4219enum ec_device_event_param {
4220 /* Get and clear pending device events */
4221 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4222 /* Get device event mask */
4223 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4224 /* Set device event mask */
4225 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4226};
4227
4228#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
4229
4230struct ec_params_device_event {
4231 uint32_t event_mask;
4232 uint8_t param;
4233} __ec_align_size1;
4234
4235struct ec_response_device_event {
4236 uint32_t event_mask;
4237} __ec_align4;
2812 4238
2813/*****************************************************************************/ 4239/*****************************************************************************/
2814/* Smart battery pass-through */ 4240/* Smart battery pass-through */
2815 4241
2816/* Get / Set 16-bit smart battery registers */ 4242/* Get / Set 16-bit smart battery registers */
2817#define EC_CMD_SB_READ_WORD 0xb0 4243#define EC_CMD_SB_READ_WORD 0x00B0
2818#define EC_CMD_SB_WRITE_WORD 0xb1 4244#define EC_CMD_SB_WRITE_WORD 0x00B1
2819 4245
2820/* Get / Set string smart battery parameters 4246/* Get / Set string smart battery parameters
2821 * formatted as SMBUS "block". 4247 * formatted as SMBUS "block".
2822 */ 4248 */
2823#define EC_CMD_SB_READ_BLOCK 0xb2 4249#define EC_CMD_SB_READ_BLOCK 0x00B2
2824#define EC_CMD_SB_WRITE_BLOCK 0xb3 4250#define EC_CMD_SB_WRITE_BLOCK 0x00B3
2825 4251
2826struct ec_params_sb_rd { 4252struct ec_params_sb_rd {
2827 uint8_t reg; 4253 uint8_t reg;
2828} __packed; 4254} __ec_align1;
2829 4255
2830struct ec_response_sb_rd_word { 4256struct ec_response_sb_rd_word {
2831 uint16_t value; 4257 uint16_t value;
2832} __packed; 4258} __ec_align2;
2833 4259
2834struct ec_params_sb_wr_word { 4260struct ec_params_sb_wr_word {
2835 uint8_t reg; 4261 uint8_t reg;
2836 uint16_t value; 4262 uint16_t value;
2837} __packed; 4263} __ec_align1;
2838 4264
2839struct ec_response_sb_rd_block { 4265struct ec_response_sb_rd_block {
2840 uint8_t data[32]; 4266 uint8_t data[32];
2841} __packed; 4267} __ec_align1;
2842 4268
2843struct ec_params_sb_wr_block { 4269struct ec_params_sb_wr_block {
2844 uint8_t reg; 4270 uint8_t reg;
2845 uint16_t data[32]; 4271 uint16_t data[32];
2846} __packed; 4272} __ec_align1;
2847 4273
2848/*****************************************************************************/ 4274/*****************************************************************************/
2849/* Battery vendor parameters 4275/* Battery vendor parameters
@@ -2854,7 +4280,7 @@ struct ec_params_sb_wr_block {
2854 * requested value. 4280 * requested value.
2855 */ 4281 */
2856 4282
2857#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4 4283#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
2858 4284
2859enum ec_battery_vendor_param_mode { 4285enum ec_battery_vendor_param_mode {
2860 BATTERY_VENDOR_PARAM_MODE_GET = 0, 4286 BATTERY_VENDOR_PARAM_MODE_GET = 0,
@@ -2865,16 +4291,187 @@ struct ec_params_battery_vendor_param {
2865 uint32_t param; 4291 uint32_t param;
2866 uint32_t value; 4292 uint32_t value;
2867 uint8_t mode; 4293 uint8_t mode;
2868} __packed; 4294} __ec_align_size1;
2869 4295
2870struct ec_response_battery_vendor_param { 4296struct ec_response_battery_vendor_param {
2871 uint32_t value; 4297 uint32_t value;
2872} __packed; 4298} __ec_align4;
4299
4300/*****************************************************************************/
4301/*
4302 * Smart Battery Firmware Update Commands
4303 */
4304#define EC_CMD_SB_FW_UPDATE 0x00B5
4305
4306enum ec_sb_fw_update_subcmd {
4307 EC_SB_FW_UPDATE_PREPARE = 0x0,
4308 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4309 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4310 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4311 EC_SB_FW_UPDATE_END = 0x4,
4312 EC_SB_FW_UPDATE_STATUS = 0x5,
4313 EC_SB_FW_UPDATE_PROTECT = 0x6,
4314 EC_SB_FW_UPDATE_MAX = 0x7,
4315};
4316
4317#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4318#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4319#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4320
4321struct ec_sb_fw_update_header {
4322 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4323 uint16_t fw_id; /* firmware id */
4324} __ec_align4;
4325
4326struct ec_params_sb_fw_update {
4327 struct ec_sb_fw_update_header hdr;
4328 union {
4329 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4330 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4331 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4332 /* EC_SB_FW_UPDATE_END = 0x4 */
4333 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4334 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
4335 /* Those have no args */
4336
4337 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
4338 struct __ec_align4 {
4339 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4340 } write;
4341 };
4342} __ec_align4;
4343
4344struct ec_response_sb_fw_update {
4345 union {
4346 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4347 struct __ec_align1 {
4348 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4349 } info;
4350
4351 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4352 struct __ec_align1 {
4353 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4354 } status;
4355 };
4356} __ec_align1;
4357
4358/*
4359 * Entering Verified Boot Mode Command
4360 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4361 * Valid Modes are: normal, developer, and recovery.
4362 */
4363#define EC_CMD_ENTERING_MODE 0x00B6
4364
4365struct ec_params_entering_mode {
4366 int vboot_mode;
4367} __ec_align4;
4368
4369#define VBOOT_MODE_NORMAL 0
4370#define VBOOT_MODE_DEVELOPER 1
4371#define VBOOT_MODE_RECOVERY 2
4372
4373/*****************************************************************************/
4374/*
4375 * I2C passthru protection command: Protects I2C tunnels against access on
4376 * certain addresses (board-specific).
4377 */
4378#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
4379
4380enum ec_i2c_passthru_protect_subcmd {
4381 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
4382 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
4383};
4384
4385struct ec_params_i2c_passthru_protect {
4386 uint8_t subcmd;
4387 uint8_t port; /* I2C port number */
4388} __ec_align1;
4389
4390struct ec_response_i2c_passthru_protect {
4391 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
4392} __ec_align1;
4393
4394
4395/*****************************************************************************/
4396/*
4397 * HDMI CEC commands
4398 *
4399 * These commands are for sending and receiving message via HDMI CEC
4400 */
4401
4402#define MAX_CEC_MSG_LEN 16
4403
4404/* CEC message from the AP to be written on the CEC bus */
4405#define EC_CMD_CEC_WRITE_MSG 0x00B8
4406
4407/**
4408 * struct ec_params_cec_write - Message to write to the CEC bus
4409 * @msg: message content to write to the CEC bus
4410 */
4411struct ec_params_cec_write {
4412 uint8_t msg[MAX_CEC_MSG_LEN];
4413} __ec_align1;
4414
4415/* Set various CEC parameters */
4416#define EC_CMD_CEC_SET 0x00BA
4417
4418/**
4419 * struct ec_params_cec_set - CEC parameters set
4420 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4421 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4422 * or 1 to enable CEC functionality, in case cmd is
4423 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4424 * address between 0 and 15 or 0xff to unregister
4425 */
4426struct ec_params_cec_set {
4427 uint8_t cmd; /* enum cec_command */
4428 uint8_t val;
4429} __ec_align1;
4430
4431/* Read various CEC parameters */
4432#define EC_CMD_CEC_GET 0x00BB
4433
4434/**
4435 * struct ec_params_cec_get - CEC parameters get
4436 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4437 */
4438struct ec_params_cec_get {
4439 uint8_t cmd; /* enum cec_command */
4440} __ec_align1;
4441
4442/**
4443 * struct ec_response_cec_get - CEC parameters get response
4444 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4445 * disabled or 1 if CEC functionality is enabled,
4446 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4447 * configured logical address between 0 and 15 or 0xff if unregistered
4448 */
4449struct ec_response_cec_get {
4450 uint8_t val;
4451} __ec_align1;
4452
4453/* CEC parameters command */
4454enum cec_command {
4455 /* CEC reading, writing and events enable */
4456 CEC_CMD_ENABLE,
4457 /* CEC logical address */
4458 CEC_CMD_LOGICAL_ADDRESS,
4459};
4460
4461/* Events from CEC to AP */
4462enum mkbp_cec_event {
4463 /* Outgoing message was acknowledged by a follower */
4464 EC_MKBP_CEC_SEND_OK = BIT(0),
4465 /* Outgoing message was not acknowledged */
4466 EC_MKBP_CEC_SEND_FAILED = BIT(1),
4467};
2873 4468
2874/*****************************************************************************/ 4469/*****************************************************************************/
4470
2875/* Commands for I2S recording on audio codec. */ 4471/* Commands for I2S recording on audio codec. */
2876 4472
2877#define EC_CMD_CODEC_I2S 0x00BC 4473#define EC_CMD_CODEC_I2S 0x00BC
4474#define EC_WOV_I2S_SAMPLE_RATE 48000
2878 4475
2879enum ec_codec_i2s_subcmd { 4476enum ec_codec_i2s_subcmd {
2880 EC_CODEC_SET_SAMPLE_DEPTH = 0x0, 4477 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
@@ -2884,6 +4481,7 @@ enum ec_codec_i2s_subcmd {
2884 EC_CODEC_I2S_SET_CONFIG = 0x4, 4481 EC_CODEC_I2S_SET_CONFIG = 0x4,
2885 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5, 4482 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2886 EC_CODEC_I2S_SET_BCLK = 0x6, 4483 EC_CODEC_I2S_SET_BCLK = 0x6,
4484 EC_CODEC_I2S_SUBCMD_COUNT = 0x7,
2887}; 4485};
2888 4486
2889enum ec_sample_depth_value { 4487enum ec_sample_depth_value {
@@ -2900,10 +4498,23 @@ enum ec_i2s_config {
2900 EC_DAI_FMT_PCM_TDM = 5, 4498 EC_DAI_FMT_PCM_TDM = 5,
2901}; 4499};
2902 4500
2903struct ec_param_codec_i2s { 4501/*
2904 /* 4502 * For subcommand EC_CODEC_GET_GAIN.
2905 * enum ec_codec_i2s_subcmd 4503 */
2906 */ 4504struct __ec_align1 ec_codec_i2s_gain {
4505 uint8_t left;
4506 uint8_t right;
4507};
4508
4509struct __ec_todo_unpacked ec_param_codec_i2s_tdm {
4510 int16_t ch0_delay; /* 0 to 496 */
4511 int16_t ch1_delay; /* -1 to 496 */
4512 uint8_t adjacent_to_ch0;
4513 uint8_t adjacent_to_ch1;
4514};
4515
4516struct __ec_todo_packed ec_param_codec_i2s {
4517 /* enum ec_codec_i2s_subcmd */
2907 uint8_t cmd; 4518 uint8_t cmd;
2908 union { 4519 union {
2909 /* 4520 /*
@@ -2916,10 +4527,7 @@ struct ec_param_codec_i2s {
2916 * EC_CODEC_SET_GAIN 4527 * EC_CODEC_SET_GAIN
2917 * Value should be 0~43 for both channels. 4528 * Value should be 0~43 for both channels.
2918 */ 4529 */
2919 struct ec_param_codec_i2s_set_gain { 4530 struct ec_codec_i2s_gain gain;
2920 uint8_t left;
2921 uint8_t right;
2922 } __packed gain;
2923 4531
2924 /* 4532 /*
2925 * EC_CODEC_I2S_ENABLE 4533 * EC_CODEC_I2S_ENABLE
@@ -2928,7 +4536,7 @@ struct ec_param_codec_i2s {
2928 uint8_t i2s_enable; 4536 uint8_t i2s_enable;
2929 4537
2930 /* 4538 /*
2931 * EC_CODEC_I2S_SET_COFNIG 4539 * EC_CODEC_I2S_SET_CONFIG
2932 * Value should be one of ec_i2s_config. 4540 * Value should be one of ec_i2s_config.
2933 */ 4541 */
2934 uint8_t i2s_config; 4542 uint8_t i2s_config;
@@ -2937,33 +4545,15 @@ struct ec_param_codec_i2s {
2937 * EC_CODEC_I2S_SET_TDM_CONFIG 4545 * EC_CODEC_I2S_SET_TDM_CONFIG
2938 * Value should be one of ec_i2s_config. 4546 * Value should be one of ec_i2s_config.
2939 */ 4547 */
2940 struct ec_param_codec_i2s_tdm { 4548 struct ec_param_codec_i2s_tdm tdm_param;
2941 /*
2942 * 0 to 496
2943 */
2944 int16_t ch0_delay;
2945 /*
2946 * -1 to 496
2947 */
2948 int16_t ch1_delay;
2949 uint8_t adjacent_to_ch0;
2950 uint8_t adjacent_to_ch1;
2951 } __packed tdm_param;
2952 4549
2953 /* 4550 /*
2954 * EC_CODEC_I2S_SET_BCLK 4551 * EC_CODEC_I2S_SET_BCLK
2955 */ 4552 */
2956 uint32_t bclk; 4553 uint32_t bclk;
2957 }; 4554 };
2958} __packed; 4555};
2959 4556
2960/*
2961 * For subcommand EC_CODEC_GET_GAIN.
2962 */
2963struct ec_response_codec_gain {
2964 uint8_t left;
2965 uint8_t right;
2966} __packed;
2967 4557
2968/*****************************************************************************/ 4558/*****************************************************************************/
2969/* System commands */ 4559/* System commands */
@@ -2972,27 +4562,29 @@ struct ec_response_codec_gain {
2972 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't 4562 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2973 * necessarily reboot the EC. Rename to "image" or something similar? 4563 * necessarily reboot the EC. Rename to "image" or something similar?
2974 */ 4564 */
2975#define EC_CMD_REBOOT_EC 0xd2 4565#define EC_CMD_REBOOT_EC 0x00D2
2976 4566
2977/* Command */ 4567/* Command */
2978enum ec_reboot_cmd { 4568enum ec_reboot_cmd {
2979 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */ 4569 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2980 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */ 4570 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2981 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */ 4571 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
2982 /* (command 3 was jump to RW-B) */ 4572 /* (command 3 was jump to RW-B) */
2983 EC_REBOOT_COLD = 4, /* Cold-reboot */ 4573 EC_REBOOT_COLD = 4, /* Cold-reboot */
2984 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */ 4574 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2985 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */ 4575 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
4576 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
2986}; 4577};
2987 4578
2988/* Flags for ec_params_reboot_ec.reboot_flags */ 4579/* Flags for ec_params_reboot_ec.reboot_flags */
2989#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */ 4580#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
2990#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */ 4581#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
4582#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
2991 4583
2992struct ec_params_reboot_ec { 4584struct ec_params_reboot_ec {
2993 uint8_t cmd; /* enum ec_reboot_cmd */ 4585 uint8_t cmd; /* enum ec_reboot_cmd */
2994 uint8_t flags; /* See EC_REBOOT_FLAG_* */ 4586 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2995} __packed; 4587} __ec_align1;
2996 4588
2997/* 4589/*
2998 * Get information on last EC panic. 4590 * Get information on last EC panic.
@@ -3000,196 +4592,7 @@ struct ec_params_reboot_ec {
3000 * Returns variable-length platform-dependent panic information. See panic.h 4592 * Returns variable-length platform-dependent panic information. See panic.h
3001 * for details. 4593 * for details.
3002 */ 4594 */
3003#define EC_CMD_GET_PANIC_INFO 0xd3 4595#define EC_CMD_GET_PANIC_INFO 0x00D3
3004
3005/*****************************************************************************/
3006/*
3007 * ACPI commands
3008 *
3009 * These are valid ONLY on the ACPI command/data port.
3010 */
3011
3012/*
3013 * ACPI Read Embedded Controller
3014 *
3015 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3016 *
3017 * Use the following sequence:
3018 *
3019 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3020 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3021 * - Write address to EC_LPC_ADDR_ACPI_DATA
3022 * - Wait for EC_LPC_CMDR_DATA bit to set
3023 * - Read value from EC_LPC_ADDR_ACPI_DATA
3024 */
3025#define EC_CMD_ACPI_READ 0x80
3026
3027/*
3028 * ACPI Write Embedded Controller
3029 *
3030 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3031 *
3032 * Use the following sequence:
3033 *
3034 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3035 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3036 * - Write address to EC_LPC_ADDR_ACPI_DATA
3037 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3038 * - Write value to EC_LPC_ADDR_ACPI_DATA
3039 */
3040#define EC_CMD_ACPI_WRITE 0x81
3041
3042/*
3043 * ACPI Query Embedded Controller
3044 *
3045 * This clears the lowest-order bit in the currently pending host events, and
3046 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3047 * event 0x80000000 = 32), or 0 if no event was pending.
3048 */
3049#define EC_CMD_ACPI_QUERY_EVENT 0x84
3050
3051/* Valid addresses in ACPI memory space, for read/write commands */
3052
3053/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3054#define EC_ACPI_MEM_VERSION 0x00
3055/*
3056 * Test location; writing value here updates test compliment byte to (0xff -
3057 * value).
3058 */
3059#define EC_ACPI_MEM_TEST 0x01
3060/* Test compliment; writes here are ignored. */
3061#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
3062
3063/* Keyboard backlight brightness percent (0 - 100) */
3064#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
3065/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3066#define EC_ACPI_MEM_FAN_DUTY 0x04
3067
3068/*
3069 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3070 * independent thresholds attached to them. The current value of the ID
3071 * register determines which sensor is affected by the THRESHOLD and COMMIT
3072 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3073 * as the memory-mapped sensors. The COMMIT register applies those settings.
3074 *
3075 * The spec does not mandate any way to read back the threshold settings
3076 * themselves, but when a threshold is crossed the AP needs a way to determine
3077 * which sensor(s) are responsible. Each reading of the ID register clears and
3078 * returns one sensor ID that has crossed one of its threshold (in either
3079 * direction) since the last read. A value of 0xFF means "no new thresholds
3080 * have tripped". Setting or enabling the thresholds for a sensor will clear
3081 * the unread event count for that sensor.
3082 */
3083#define EC_ACPI_MEM_TEMP_ID 0x05
3084#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3085#define EC_ACPI_MEM_TEMP_COMMIT 0x07
3086/*
3087 * Here are the bits for the COMMIT register:
3088 * bit 0 selects the threshold index for the chosen sensor (0/1)
3089 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3090 * Each write to the commit register affects one threshold.
3091 */
3092#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3093#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3094/*
3095 * Example:
3096 *
3097 * Set the thresholds for sensor 2 to 50 C and 60 C:
3098 * write 2 to [0x05] -- select temp sensor 2
3099 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3100 * write 0x2 to [0x07] -- enable threshold 0 with this value
3101 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3102 * write 0x3 to [0x07] -- enable threshold 1 with this value
3103 *
3104 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3105 * write 2 to [0x05] -- select temp sensor 2
3106 * write 0x1 to [0x07] -- disable threshold 1
3107 */
3108
3109/* DPTF battery charging current limit */
3110#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3111
3112/* Charging limit is specified in 64 mA steps */
3113#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3114/* Value to disable DPTF battery charging limit */
3115#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
3116
3117/* Current version of ACPI memory address space */
3118#define EC_ACPI_MEM_VERSION_CURRENT 1
3119
3120
3121/*****************************************************************************/
3122/*
3123 * HDMI CEC commands
3124 *
3125 * These commands are for sending and receiving message via HDMI CEC
3126 */
3127#define EC_MAX_CEC_MSG_LEN 16
3128
3129/* CEC message from the AP to be written on the CEC bus */
3130#define EC_CMD_CEC_WRITE_MSG 0x00B8
3131
3132/**
3133 * struct ec_params_cec_write - Message to write to the CEC bus
3134 * @msg: message content to write to the CEC bus
3135 */
3136struct ec_params_cec_write {
3137 uint8_t msg[EC_MAX_CEC_MSG_LEN];
3138} __packed;
3139
3140/* Set various CEC parameters */
3141#define EC_CMD_CEC_SET 0x00BA
3142
3143/**
3144 * struct ec_params_cec_set - CEC parameters set
3145 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3146 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3147 * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3148 * this field encodes the requested logical address between 0 and 15
3149 * or 0xff to unregister
3150 */
3151struct ec_params_cec_set {
3152 uint8_t cmd; /* enum cec_command */
3153 uint8_t val;
3154} __packed;
3155
3156/* Read various CEC parameters */
3157#define EC_CMD_CEC_GET 0x00BB
3158
3159/**
3160 * struct ec_params_cec_get - CEC parameters get
3161 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3162 */
3163struct ec_params_cec_get {
3164 uint8_t cmd; /* enum cec_command */
3165} __packed;
3166
3167/**
3168 * struct ec_response_cec_get - CEC parameters get response
3169 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
3170 * disabled or 1 if CEC functionality is enabled,
3171 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
3172 * configured logical address between 0 and 15 or 0xff if unregistered
3173 */
3174struct ec_response_cec_get {
3175 uint8_t val;
3176} __packed;
3177
3178/* CEC parameters command */
3179enum ec_cec_command {
3180 /* CEC reading, writing and events enable */
3181 CEC_CMD_ENABLE,
3182 /* CEC logical address */
3183 CEC_CMD_LOGICAL_ADDRESS,
3184};
3185
3186/* Events from CEC to AP */
3187enum mkbp_cec_event {
3188 /* Outgoing message was acknowledged by a follower */
3189 EC_MKBP_CEC_SEND_OK = BIT(0),
3190 /* Outgoing message was not acknowledged */
3191 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3192};
3193 4596
3194/*****************************************************************************/ 4597/*****************************************************************************/
3195/* 4598/*
@@ -3208,7 +4611,7 @@ enum mkbp_cec_event {
3208 * 4611 *
3209 * Use EC_CMD_REBOOT_EC to reboot the EC more politely. 4612 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3210 */ 4613 */
3211#define EC_CMD_REBOOT 0xd1 /* Think "die" */ 4614#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
3212 4615
3213/* 4616/*
3214 * Resend last response (not supported on LPC). 4617 * Resend last response (not supported on LPC).
@@ -3217,7 +4620,7 @@ enum mkbp_cec_event {
3217 * there was no previous command, or the previous command's response was too 4620 * there was no previous command, or the previous command's response was too
3218 * big to save. 4621 * big to save.
3219 */ 4622 */
3220#define EC_CMD_RESEND_RESPONSE 0xdb 4623#define EC_CMD_RESEND_RESPONSE 0x00DB
3221 4624
3222/* 4625/*
3223 * This header byte on a command indicate version 0. Any header byte less 4626 * This header byte on a command indicate version 0. Any header byte less
@@ -3229,9 +4632,7 @@ enum mkbp_cec_event {
3229 * 4632 *
3230 * The old EC interface must not use commands 0xdc or higher. 4633 * The old EC interface must not use commands 0xdc or higher.
3231 */ 4634 */
3232#define EC_CMD_VERSION0 0xdc 4635#define EC_CMD_VERSION0 0x00DC
3233
3234#endif /* !__ACPI__ */
3235 4636
3236/*****************************************************************************/ 4637/*****************************************************************************/
3237/* 4638/*
@@ -3241,21 +4642,56 @@ enum mkbp_cec_event {
3241 */ 4642 */
3242 4643
3243/* EC to PD MCU exchange status command */ 4644/* EC to PD MCU exchange status command */
3244#define EC_CMD_PD_EXCHANGE_STATUS 0x100 4645#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
4646#define EC_VER_PD_EXCHANGE_STATUS 2
4647
4648enum pd_charge_state {
4649 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
4650 PD_CHARGE_NONE, /* No charging allowed */
4651 PD_CHARGE_5V, /* 5V charging only */
4652 PD_CHARGE_MAX /* Charge at max voltage */
4653};
3245 4654
3246/* Status of EC being sent to PD */ 4655/* Status of EC being sent to PD */
4656#define EC_STATUS_HIBERNATING BIT(0)
4657
3247struct ec_params_pd_status { 4658struct ec_params_pd_status {
3248 int8_t batt_soc; /* battery state of charge */ 4659 uint8_t status; /* EC status */
3249} __packed; 4660 int8_t batt_soc; /* battery state of charge */
4661 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
4662} __ec_align1;
3250 4663
3251/* Status of PD being sent back to EC */ 4664/* Status of PD being sent back to EC */
4665#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
4666#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
4667#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
4668#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
4669#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
4670#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
4671#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
4672#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4673 PD_STATUS_TCPC_ALERT_1 | \
4674 PD_STATUS_HOST_EVENT)
3252struct ec_response_pd_status { 4675struct ec_response_pd_status {
3253 int8_t status; /* PD MCU status */ 4676 uint32_t curr_lim_ma; /* input current limit */
3254 uint32_t curr_lim_ma; /* input current limit */ 4677 uint16_t status; /* PD MCU status */
3255} __packed; 4678 int8_t active_charge_port; /* active charging port */
4679} __ec_align_size1;
4680
4681/* AP to PD MCU host event status command, cleared on read */
4682#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
4683
4684/* PD MCU host event status bits */
4685#define PD_EVENT_UPDATE_DEVICE BIT(0)
4686#define PD_EVENT_POWER_CHANGE BIT(1)
4687#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
4688#define PD_EVENT_DATA_SWAP BIT(3)
4689struct ec_response_host_event_status {
4690 uint32_t status; /* PD MCU host event status */
4691} __ec_align4;
3256 4692
3257/* Set USB type-C port role and muxes */ 4693/* Set USB type-C port role and muxes */
3258#define EC_CMD_USB_PD_CONTROL 0x101 4694#define EC_CMD_USB_PD_CONTROL 0x0101
3259 4695
3260enum usb_pd_control_role { 4696enum usb_pd_control_role {
3261 USB_PD_CTRL_ROLE_NO_CHANGE = 0, 4697 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
@@ -3263,6 +4699,8 @@ enum usb_pd_control_role {
3263 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2, 4699 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3264 USB_PD_CTRL_ROLE_FORCE_SINK = 3, 4700 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3265 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4, 4701 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4702 USB_PD_CTRL_ROLE_FREEZE = 5,
4703 USB_PD_CTRL_ROLE_COUNT
3266}; 4704};
3267 4705
3268enum usb_pd_control_mux { 4706enum usb_pd_control_mux {
@@ -3272,6 +4710,7 @@ enum usb_pd_control_mux {
3272 USB_PD_CTRL_MUX_DP = 3, 4710 USB_PD_CTRL_MUX_DP = 3,
3273 USB_PD_CTRL_MUX_DOCK = 4, 4711 USB_PD_CTRL_MUX_DOCK = 4,
3274 USB_PD_CTRL_MUX_AUTO = 5, 4712 USB_PD_CTRL_MUX_AUTO = 5,
4713 USB_PD_CTRL_MUX_COUNT
3275}; 4714};
3276 4715
3277enum usb_pd_control_swap { 4716enum usb_pd_control_swap {
@@ -3287,11 +4726,11 @@ struct ec_params_usb_pd_control {
3287 uint8_t role; 4726 uint8_t role;
3288 uint8_t mux; 4727 uint8_t mux;
3289 uint8_t swap; 4728 uint8_t swap;
3290} __packed; 4729} __ec_align1;
3291 4730
3292#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */ 4731#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
3293#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */ 4732#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
3294#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */ 4733#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
3295 4734
3296#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */ 4735#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3297#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */ 4736#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
@@ -3301,28 +4740,54 @@ struct ec_params_usb_pd_control {
3301#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */ 4740#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3302#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */ 4741#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3303 4742
4743struct ec_response_usb_pd_control {
4744 uint8_t enabled;
4745 uint8_t role;
4746 uint8_t polarity;
4747 uint8_t state;
4748} __ec_align1;
4749
3304struct ec_response_usb_pd_control_v1 { 4750struct ec_response_usb_pd_control_v1 {
3305 uint8_t enabled; 4751 uint8_t enabled;
3306 uint8_t role; 4752 uint8_t role;
3307 uint8_t polarity; 4753 uint8_t polarity;
3308 char state[32]; 4754 char state[32];
3309} __packed; 4755} __ec_align1;
4756
4757/* Values representing usbc PD CC state */
4758#define USBC_PD_CC_NONE 0 /* No accessory connected */
4759#define USBC_PD_CC_NO_UFP 1 /* No UFP accessory connected */
4760#define USBC_PD_CC_AUDIO_ACC 2 /* Audio accessory connected */
4761#define USBC_PD_CC_DEBUG_ACC 3 /* Debug accessory connected */
4762#define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */
4763#define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */
4764
4765struct ec_response_usb_pd_control_v2 {
4766 uint8_t enabled;
4767 uint8_t role;
4768 uint8_t polarity;
4769 char state[32];
4770 uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
4771 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
4772 /* CL:1500994 Current cable type */
4773 uint8_t reserved_cable_type;
4774} __ec_align1;
3310 4775
3311#define EC_CMD_USB_PD_PORTS 0x102 4776#define EC_CMD_USB_PD_PORTS 0x0102
3312 4777
3313/* Maximum number of PD ports on a device, num_ports will be <= this */ 4778/* Maximum number of PD ports on a device, num_ports will be <= this */
3314#define EC_USB_PD_MAX_PORTS 8 4779#define EC_USB_PD_MAX_PORTS 8
3315 4780
3316struct ec_response_usb_pd_ports { 4781struct ec_response_usb_pd_ports {
3317 uint8_t num_ports; 4782 uint8_t num_ports;
3318} __packed; 4783} __ec_align1;
3319 4784
3320#define EC_CMD_USB_PD_POWER_INFO 0x103 4785#define EC_CMD_USB_PD_POWER_INFO 0x0103
3321 4786
3322#define PD_POWER_CHARGING_PORT 0xff 4787#define PD_POWER_CHARGING_PORT 0xff
3323struct ec_params_usb_pd_power_info { 4788struct ec_params_usb_pd_power_info {
3324 uint8_t port; 4789 uint8_t port;
3325} __packed; 4790} __ec_align1;
3326 4791
3327enum usb_chg_type { 4792enum usb_chg_type {
3328 USB_CHG_TYPE_NONE, 4793 USB_CHG_TYPE_NONE,
@@ -3335,6 +4800,7 @@ enum usb_chg_type {
3335 USB_CHG_TYPE_OTHER, 4800 USB_CHG_TYPE_OTHER,
3336 USB_CHG_TYPE_VBUS, 4801 USB_CHG_TYPE_VBUS,
3337 USB_CHG_TYPE_UNKNOWN, 4802 USB_CHG_TYPE_UNKNOWN,
4803 USB_CHG_TYPE_DEDICATED,
3338}; 4804};
3339enum usb_power_roles { 4805enum usb_power_roles {
3340 USB_PD_PORT_POWER_DISCONNECTED, 4806 USB_PD_PORT_POWER_DISCONNECTED,
@@ -3348,7 +4814,7 @@ struct usb_chg_measures {
3348 uint16_t voltage_now; 4814 uint16_t voltage_now;
3349 uint16_t current_max; 4815 uint16_t current_max;
3350 uint16_t current_lim; 4816 uint16_t current_lim;
3351} __packed; 4817} __ec_align2;
3352 4818
3353struct ec_response_usb_pd_power_info { 4819struct ec_response_usb_pd_power_info {
3354 uint8_t role; 4820 uint8_t role;
@@ -3357,11 +4823,8 @@ struct ec_response_usb_pd_power_info {
3357 uint8_t reserved1; 4823 uint8_t reserved1;
3358 struct usb_chg_measures meas; 4824 struct usb_chg_measures meas;
3359 uint32_t max_power; 4825 uint32_t max_power;
3360} __packed; 4826} __ec_align4;
3361 4827
3362struct ec_params_usb_pd_info_request {
3363 uint8_t port;
3364} __packed;
3365 4828
3366/* 4829/*
3367 * This command will return the number of USB PD charge port + the number 4830 * This command will return the number of USB PD charge port + the number
@@ -3371,7 +4834,47 @@ struct ec_params_usb_pd_info_request {
3371#define EC_CMD_CHARGE_PORT_COUNT 0x0105 4834#define EC_CMD_CHARGE_PORT_COUNT 0x0105
3372struct ec_response_charge_port_count { 4835struct ec_response_charge_port_count {
3373 uint8_t port_count; 4836 uint8_t port_count;
3374} __packed; 4837} __ec_align1;
4838
4839/* Write USB-PD device FW */
4840#define EC_CMD_USB_PD_FW_UPDATE 0x0110
4841
4842enum usb_pd_fw_update_cmds {
4843 USB_PD_FW_REBOOT,
4844 USB_PD_FW_FLASH_ERASE,
4845 USB_PD_FW_FLASH_WRITE,
4846 USB_PD_FW_ERASE_SIG,
4847};
4848
4849struct ec_params_usb_pd_fw_update {
4850 uint16_t dev_id;
4851 uint8_t cmd;
4852 uint8_t port;
4853 uint32_t size; /* Size to write in bytes */
4854 /* Followed by data to write */
4855} __ec_align4;
4856
4857/* Write USB-PD Accessory RW_HASH table entry */
4858#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4859/* RW hash is first 20 bytes of SHA-256 of RW section */
4860#define PD_RW_HASH_SIZE 20
4861struct ec_params_usb_pd_rw_hash_entry {
4862 uint16_t dev_id;
4863 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4864 uint8_t reserved; /*
4865 * For alignment of current_image
4866 * TODO(rspangler) but it's not aligned!
4867 * Should have been reserved[2].
4868 */
4869 uint32_t current_image; /* One of ec_current_image */
4870} __ec_align1;
4871
4872/* Read USB-PD Accessory info */
4873#define EC_CMD_USB_PD_DEV_INFO 0x0112
4874
4875struct ec_params_usb_pd_info_request {
4876 uint8_t port;
4877} __ec_align1;
3375 4878
3376/* Read USB-PD Device discovery info */ 4879/* Read USB-PD Device discovery info */
3377#define EC_CMD_USB_PD_DISCOVERY 0x0113 4880#define EC_CMD_USB_PD_DISCOVERY 0x0113
@@ -3379,7 +4882,7 @@ struct ec_params_usb_pd_discovery_entry {
3379 uint16_t vid; /* USB-IF VID */ 4882 uint16_t vid; /* USB-IF VID */
3380 uint16_t pid; /* USB-IF PID */ 4883 uint16_t pid; /* USB-IF PID */
3381 uint8_t ptype; /* product type (hub,periph,cable,ama) */ 4884 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3382} __packed; 4885} __ec_align_size1;
3383 4886
3384/* Override default charge behavior */ 4887/* Override default charge behavior */
3385#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114 4888#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
@@ -3393,9 +4896,13 @@ enum usb_pd_override_ports {
3393 4896
3394struct ec_params_charge_port_override { 4897struct ec_params_charge_port_override {
3395 int16_t override_port; /* Override port# */ 4898 int16_t override_port; /* Override port# */
3396} __packed; 4899} __ec_align2;
3397 4900
3398/* Read (and delete) one entry of PD event log */ 4901/*
4902 * Read (and delete) one entry of PD event log.
4903 * TODO(crbug.com/751742): Make this host command more generic to accommodate
4904 * future non-PD logs that use the same internal EC event_log.
4905 */
3399#define EC_CMD_PD_GET_LOG_ENTRY 0x0115 4906#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3400 4907
3401struct ec_response_pd_log { 4908struct ec_response_pd_log {
@@ -3404,7 +4911,7 @@ struct ec_response_pd_log {
3404 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */ 4911 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3405 uint16_t data; /* type-defined data payload */ 4912 uint16_t data; /* type-defined data payload */
3406 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */ 4913 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3407} __packed; 4914} __ec_align4;
3408 4915
3409/* The timestamp is the microsecond counter shifted to get about a ms. */ 4916/* The timestamp is the microsecond counter shifted to get about a ms. */
3410#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */ 4917#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
@@ -3470,35 +4977,698 @@ struct mcdp_version {
3470 uint8_t major; 4977 uint8_t major;
3471 uint8_t minor; 4978 uint8_t minor;
3472 uint16_t build; 4979 uint16_t build;
3473} __packed; 4980} __ec_align4;
3474 4981
3475struct mcdp_info { 4982struct mcdp_info {
3476 uint8_t family[2]; 4983 uint8_t family[2];
3477 uint8_t chipid[2]; 4984 uint8_t chipid[2];
3478 struct mcdp_version irom; 4985 struct mcdp_version irom;
3479 struct mcdp_version fw; 4986 struct mcdp_version fw;
3480} __packed; 4987} __ec_align4;
3481 4988
3482/* struct mcdp_info field decoding */ 4989/* struct mcdp_info field decoding */
3483#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1]) 4990#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3484#define MCDP_FAMILY(family) ((family[0] << 8) | family[1]) 4991#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3485 4992
4993/* Get/Set USB-PD Alternate mode info */
4994#define EC_CMD_USB_PD_GET_AMODE 0x0116
4995struct ec_params_usb_pd_get_mode_request {
4996 uint16_t svid_idx; /* SVID index to get */
4997 uint8_t port; /* port */
4998} __ec_align_size1;
4999
5000struct ec_params_usb_pd_get_mode_response {
5001 uint16_t svid; /* SVID */
5002 uint16_t opos; /* Object Position */
5003 uint32_t vdo[6]; /* Mode VDOs */
5004} __ec_align4;
5005
5006#define EC_CMD_USB_PD_SET_AMODE 0x0117
5007
5008enum pd_mode_cmd {
5009 PD_EXIT_MODE = 0,
5010 PD_ENTER_MODE = 1,
5011 /* Not a command. Do NOT remove. */
5012 PD_MODE_CMD_COUNT,
5013};
5014
5015struct ec_params_usb_pd_set_mode_request {
5016 uint32_t cmd; /* enum pd_mode_cmd */
5017 uint16_t svid; /* SVID to set */
5018 uint8_t opos; /* Object Position */
5019 uint8_t port; /* port */
5020} __ec_align4;
5021
5022/* Ask the PD MCU to record a log of a requested type */
5023#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
5024
5025struct ec_params_pd_write_log_entry {
5026 uint8_t type; /* event type : see PD_EVENT_xx above */
5027 uint8_t port; /* port#, or 0 for events unrelated to a given port */
5028} __ec_align1;
5029
5030
5031/* Control USB-PD chip */
5032#define EC_CMD_PD_CONTROL 0x0119
5033
5034enum ec_pd_control_cmd {
5035 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5036 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5037 PD_RESET, /* Force reset the PD chip */
5038 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5039 PD_CHIP_ON, /* Power on the PD chip */
5040};
5041
5042struct ec_params_pd_control {
5043 uint8_t chip; /* chip id */
5044 uint8_t subcmd;
5045} __ec_align1;
5046
3486/* Get info about USB-C SS muxes */ 5047/* Get info about USB-C SS muxes */
3487#define EC_CMD_USB_PD_MUX_INFO 0x11a 5048#define EC_CMD_USB_PD_MUX_INFO 0x011A
3488 5049
3489struct ec_params_usb_pd_mux_info { 5050struct ec_params_usb_pd_mux_info {
3490 uint8_t port; /* USB-C port number */ 5051 uint8_t port; /* USB-C port number */
3491} __packed; 5052} __ec_align1;
3492 5053
3493/* Flags representing mux state */ 5054/* Flags representing mux state */
3494#define USB_PD_MUX_USB_ENABLED (1 << 0) 5055#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
3495#define USB_PD_MUX_DP_ENABLED (1 << 1) 5056#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
3496#define USB_PD_MUX_POLARITY_INVERTED (1 << 2) 5057#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
3497#define USB_PD_MUX_HPD_IRQ (1 << 3) 5058#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5059#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
3498 5060
3499struct ec_response_usb_pd_mux_info { 5061struct ec_response_usb_pd_mux_info {
3500 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */ 5062 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3501} __packed; 5063} __ec_align1;
5064
5065#define EC_CMD_PD_CHIP_INFO 0x011B
5066
5067struct ec_params_pd_chip_info {
5068 uint8_t port; /* USB-C port number */
5069 uint8_t renew; /* Force renewal */
5070} __ec_align1;
5071
5072struct ec_response_pd_chip_info {
5073 uint16_t vendor_id;
5074 uint16_t product_id;
5075 uint16_t device_id;
5076 union {
5077 uint8_t fw_version_string[8];
5078 uint64_t fw_version_number;
5079 };
5080} __ec_align2;
5081
5082struct ec_response_pd_chip_info_v1 {
5083 uint16_t vendor_id;
5084 uint16_t product_id;
5085 uint16_t device_id;
5086 union {
5087 uint8_t fw_version_string[8];
5088 uint64_t fw_version_number;
5089 };
5090 union {
5091 uint8_t min_req_fw_version_string[8];
5092 uint64_t min_req_fw_version_number;
5093 };
5094} __ec_align2;
5095
5096/* Run RW signature verification and get status */
5097#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5098
5099struct ec_response_rwsig_check_status {
5100 uint32_t status;
5101} __ec_align4;
5102
5103/* For controlling RWSIG task */
5104#define EC_CMD_RWSIG_ACTION 0x011D
5105
5106enum rwsig_action {
5107 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5108 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5109};
5110
5111struct ec_params_rwsig_action {
5112 uint32_t action;
5113} __ec_align4;
5114
5115/* Run verification on a slot */
5116#define EC_CMD_EFS_VERIFY 0x011E
5117
5118struct ec_params_efs_verify {
5119 uint8_t region; /* enum ec_flash_region */
5120} __ec_align1;
5121
5122/*
5123 * Retrieve info from Cros Board Info store. Response is based on the data
5124 * type. Integers return a uint32. Strings return a string, using the response
5125 * size to determine how big it is.
5126 */
5127#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5128/*
5129 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5130 * hardware write-protect enabled.
5131 */
5132#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5133
5134enum cbi_data_tag {
5135 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5136 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5137 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
5138 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
5139 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
5140 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
5141 CBI_TAG_COUNT,
5142};
5143
5144/*
5145 * Flags to control read operation
5146 *
5147 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5148 * write was successful without reboot.
5149 */
5150#define CBI_GET_RELOAD BIT(0)
5151
5152struct ec_params_get_cbi {
5153 uint32_t tag; /* enum cbi_data_tag */
5154 uint32_t flag; /* CBI_GET_* */
5155} __ec_align4;
5156
5157/*
5158 * Flags to control write behavior.
5159 *
5160 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5161 * useful when writing multiple fields in a row.
5162 * INIT: Need to be set when creating a new CBI from scratch. All fields
5163 * will be initialized to zero first.
5164 */
5165#define CBI_SET_NO_SYNC BIT(0)
5166#define CBI_SET_INIT BIT(1)
5167
5168struct ec_params_set_cbi {
5169 uint32_t tag; /* enum cbi_data_tag */
5170 uint32_t flag; /* CBI_SET_* */
5171 uint32_t size; /* Data size */
5172 uint8_t data[]; /* For string and raw data */
5173} __ec_align1;
5174
5175/*
5176 * Information about resets of the AP by the EC and the EC's own uptime.
5177 */
5178#define EC_CMD_GET_UPTIME_INFO 0x0121
5179
5180struct ec_response_uptime_info {
5181 /*
5182 * Number of milliseconds since the last EC boot. Sysjump resets
5183 * typically do not restart the EC's time_since_boot epoch.
5184 *
5185 * WARNING: The EC's sense of time is much less accurate than the AP's
5186 * sense of time, in both phase and frequency. This timebase is similar
5187 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5188 */
5189 uint32_t time_since_ec_boot_ms;
5190
5191 /*
5192 * Number of times the AP was reset by the EC since the last EC boot.
5193 * Note that the AP may be held in reset by the EC during the initial
5194 * boot sequence, such that the very first AP boot may count as more
5195 * than one here.
5196 */
5197 uint32_t ap_resets_since_ec_boot;
5198
5199 /*
5200 * The set of flags which describe the EC's most recent reset. See
5201 * include/system.h RESET_FLAG_* for details.
5202 */
5203 uint32_t ec_reset_flags;
5204
5205 /* Empty log entries have both the cause and timestamp set to zero. */
5206 struct ap_reset_log_entry {
5207 /*
5208 * See include/chipset.h: enum chipset_{reset,shutdown}_reason
5209 * for details.
5210 */
5211 uint16_t reset_cause;
5212
5213 /* Reserved for protocol growth. */
5214 uint16_t reserved;
5215
5216 /*
5217 * The time of the reset's assertion, in milliseconds since the
5218 * last EC boot, in the same epoch as time_since_ec_boot_ms.
5219 * Set to zero if the log entry is empty.
5220 */
5221 uint32_t reset_time_ms;
5222 } recent_ap_reset[4];
5223} __ec_align4;
5224
5225/*
5226 * Add entropy to the device secret (stored in the rollback region).
5227 *
5228 * Depending on the chip, the operation may take a long time (e.g. to erase
5229 * flash), so the commands are asynchronous.
5230 */
5231#define EC_CMD_ADD_ENTROPY 0x0122
5232
5233enum add_entropy_action {
5234 /* Add entropy to the current secret. */
5235 ADD_ENTROPY_ASYNC = 0,
5236 /*
5237 * Add entropy, and also make sure that the previous secret is erased.
5238 * (this can be implemented by adding entropy multiple times until
5239 * all rolback blocks have been overwritten).
5240 */
5241 ADD_ENTROPY_RESET_ASYNC = 1,
5242 /* Read back result from the previous operation. */
5243 ADD_ENTROPY_GET_RESULT = 2,
5244};
5245
5246struct ec_params_rollback_add_entropy {
5247 uint8_t action;
5248} __ec_align1;
5249
5250/*
5251 * Perform a single read of a given ADC channel.
5252 */
5253#define EC_CMD_ADC_READ 0x0123
5254
5255struct ec_params_adc_read {
5256 uint8_t adc_channel;
5257} __ec_align1;
5258
5259struct ec_response_adc_read {
5260 int32_t adc_value;
5261} __ec_align4;
5262
5263/*
5264 * Read back rollback info
5265 */
5266#define EC_CMD_ROLLBACK_INFO 0x0124
5267
5268struct ec_response_rollback_info {
5269 int32_t id; /* Incrementing number to indicate which region to use. */
5270 int32_t rollback_min_version;
5271 int32_t rw_rollback_version;
5272} __ec_align4;
5273
5274
5275/* Issue AP reset */
5276#define EC_CMD_AP_RESET 0x0125
5277
5278/*****************************************************************************/
5279/* The command range 0x200-0x2FF is reserved for Rotor. */
5280
5281/*****************************************************************************/
5282/*
5283 * Reserve a range of host commands for the CR51 firmware.
5284 */
5285#define EC_CMD_CR51_BASE 0x0300
5286#define EC_CMD_CR51_LAST 0x03FF
5287
5288/*****************************************************************************/
5289/* Fingerprint MCU commands: range 0x0400-0x040x */
5290
5291/* Fingerprint SPI sensor passthru command: prototyping ONLY */
5292#define EC_CMD_FP_PASSTHRU 0x0400
5293
5294#define EC_FP_FLAG_NOT_COMPLETE 0x1
5295
5296struct ec_params_fp_passthru {
5297 uint16_t len; /* Number of bytes to write then read */
5298 uint16_t flags; /* EC_FP_FLAG_xxx */
5299 uint8_t data[]; /* Data to send */
5300} __ec_align2;
5301
5302/* Configure the Fingerprint MCU behavior */
5303#define EC_CMD_FP_MODE 0x0402
5304
5305/* Put the sensor in its lowest power mode */
5306#define FP_MODE_DEEPSLEEP BIT(0)
5307/* Wait to see a finger on the sensor */
5308#define FP_MODE_FINGER_DOWN BIT(1)
5309/* Poll until the finger has left the sensor */
5310#define FP_MODE_FINGER_UP BIT(2)
5311/* Capture the current finger image */
5312#define FP_MODE_CAPTURE BIT(3)
5313/* Finger enrollment session on-going */
5314#define FP_MODE_ENROLL_SESSION BIT(4)
5315/* Enroll the current finger image */
5316#define FP_MODE_ENROLL_IMAGE BIT(5)
5317/* Try to match the current finger image */
5318#define FP_MODE_MATCH BIT(6)
5319/* Reset and re-initialize the sensor. */
5320#define FP_MODE_RESET_SENSOR BIT(7)
5321/* special value: don't change anything just read back current mode */
5322#define FP_MODE_DONT_CHANGE BIT(31)
5323
5324#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
5325 FP_MODE_FINGER_DOWN | \
5326 FP_MODE_FINGER_UP | \
5327 FP_MODE_CAPTURE | \
5328 FP_MODE_ENROLL_SESSION | \
5329 FP_MODE_ENROLL_IMAGE | \
5330 FP_MODE_MATCH | \
5331 FP_MODE_RESET_SENSOR | \
5332 FP_MODE_DONT_CHANGE)
5333
5334/* Capture types defined in bits [30..28] */
5335#define FP_MODE_CAPTURE_TYPE_SHIFT 28
5336#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
5337/*
5338 * This enum must remain ordered, if you add new values you must ensure that
5339 * FP_CAPTURE_TYPE_MAX is still the last one.
5340 */
5341enum fp_capture_type {
5342 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
5343 FP_CAPTURE_VENDOR_FORMAT = 0,
5344 /* Simple raw image capture (produces width x height x bpp bits) */
5345 FP_CAPTURE_SIMPLE_IMAGE = 1,
5346 /* Self test pattern (e.g. checkerboard) */
5347 FP_CAPTURE_PATTERN0 = 2,
5348 /* Self test pattern (e.g. inverted checkerboard) */
5349 FP_CAPTURE_PATTERN1 = 3,
5350 /* Capture for Quality test with fixed contrast */
5351 FP_CAPTURE_QUALITY_TEST = 4,
5352 /* Capture for pixel reset value test */
5353 FP_CAPTURE_RESET_TEST = 5,
5354 FP_CAPTURE_TYPE_MAX,
5355};
5356/* Extracts the capture type from the sensor 'mode' word */
5357#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
5358 >> FP_MODE_CAPTURE_TYPE_SHIFT)
5359
5360struct ec_params_fp_mode {
5361 uint32_t mode; /* as defined by FP_MODE_ constants */
5362} __ec_align4;
5363
5364struct ec_response_fp_mode {
5365 uint32_t mode; /* as defined by FP_MODE_ constants */
5366} __ec_align4;
5367
5368/* Retrieve Fingerprint sensor information */
5369#define EC_CMD_FP_INFO 0x0403
5370
5371/* Number of dead pixels detected on the last maintenance */
5372#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
5373/* Unknown number of dead pixels detected on the last maintenance */
5374#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
5375/* No interrupt from the sensor */
5376#define FP_ERROR_NO_IRQ BIT(12)
5377/* SPI communication error */
5378#define FP_ERROR_SPI_COMM BIT(13)
5379/* Invalid sensor Hardware ID */
5380#define FP_ERROR_BAD_HWID BIT(14)
5381/* Sensor initialization failed */
5382#define FP_ERROR_INIT_FAIL BIT(15)
5383
5384struct ec_response_fp_info_v0 {
5385 /* Sensor identification */
5386 uint32_t vendor_id;
5387 uint32_t product_id;
5388 uint32_t model_id;
5389 uint32_t version;
5390 /* Image frame characteristics */
5391 uint32_t frame_size;
5392 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
5393 uint16_t width;
5394 uint16_t height;
5395 uint16_t bpp;
5396 uint16_t errors; /* see FP_ERROR_ flags above */
5397} __ec_align4;
5398
5399struct ec_response_fp_info {
5400 /* Sensor identification */
5401 uint32_t vendor_id;
5402 uint32_t product_id;
5403 uint32_t model_id;
5404 uint32_t version;
5405 /* Image frame characteristics */
5406 uint32_t frame_size;
5407 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
5408 uint16_t width;
5409 uint16_t height;
5410 uint16_t bpp;
5411 uint16_t errors; /* see FP_ERROR_ flags above */
5412 /* Template/finger current information */
5413 uint32_t template_size; /* max template size in bytes */
5414 uint16_t template_max; /* maximum number of fingers/templates */
5415 uint16_t template_valid; /* number of valid fingers/templates */
5416 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
5417 uint32_t template_version; /* version of the template format */
5418} __ec_align4;
5419
5420/* Get the last captured finger frame or a template content */
5421#define EC_CMD_FP_FRAME 0x0404
5422
5423/* constants defining the 'offset' field which also contains the frame index */
5424#define FP_FRAME_INDEX_SHIFT 28
5425/* Frame buffer where the captured image is stored */
5426#define FP_FRAME_INDEX_RAW_IMAGE 0
5427/* First frame buffer holding a template */
5428#define FP_FRAME_INDEX_TEMPLATE 1
5429#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
5430#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
5431
5432/* Version of the format of the encrypted templates. */
5433#define FP_TEMPLATE_FORMAT_VERSION 3
5434
5435/* Constants for encryption parameters */
5436#define FP_CONTEXT_NONCE_BYTES 12
5437#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
5438#define FP_CONTEXT_TAG_BYTES 16
5439#define FP_CONTEXT_SALT_BYTES 16
5440#define FP_CONTEXT_TPM_BYTES 32
5441
5442struct ec_fp_template_encryption_metadata {
5443 /*
5444 * Version of the structure format (N=3).
5445 */
5446 uint16_t struct_version;
5447 /* Reserved bytes, set to 0. */
5448 uint16_t reserved;
5449 /*
5450 * The salt is *only* ever used for key derivation. The nonce is unique,
5451 * a different one is used for every message.
5452 */
5453 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
5454 uint8_t salt[FP_CONTEXT_SALT_BYTES];
5455 uint8_t tag[FP_CONTEXT_TAG_BYTES];
5456};
5457
5458struct ec_params_fp_frame {
5459 /*
5460 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
5461 * in the high nibble, and the real offset within the frame in
5462 * FP_FRAME_OFFSET_MASK.
5463 */
5464 uint32_t offset;
5465 uint32_t size;
5466} __ec_align4;
5467
5468/* Load a template into the MCU */
5469#define EC_CMD_FP_TEMPLATE 0x0405
5470
5471/* Flag in the 'size' field indicating that the full template has been sent */
5472#define FP_TEMPLATE_COMMIT 0x80000000
5473
5474struct ec_params_fp_template {
5475 uint32_t offset;
5476 uint32_t size;
5477 uint8_t data[];
5478} __ec_align4;
5479
5480/* Clear the current fingerprint user context and set a new one */
5481#define EC_CMD_FP_CONTEXT 0x0406
5482
5483struct ec_params_fp_context {
5484 uint32_t userid[FP_CONTEXT_USERID_WORDS];
5485} __ec_align4;
5486
5487#define EC_CMD_FP_STATS 0x0407
5488
5489#define FPSTATS_CAPTURE_INV BIT(0)
5490#define FPSTATS_MATCHING_INV BIT(1)
5491
5492struct ec_response_fp_stats {
5493 uint32_t capture_time_us;
5494 uint32_t matching_time_us;
5495 uint32_t overall_time_us;
5496 struct {
5497 uint32_t lo;
5498 uint32_t hi;
5499 } overall_t0;
5500 uint8_t timestamps_invalid;
5501 int8_t template_matched;
5502} __ec_align2;
5503
5504#define EC_CMD_FP_SEED 0x0408
5505struct ec_params_fp_seed {
5506 /*
5507 * Version of the structure format (N=3).
5508 */
5509 uint16_t struct_version;
5510 /* Reserved bytes, set to 0. */
5511 uint16_t reserved;
5512 /* Seed from the TPM. */
5513 uint8_t seed[FP_CONTEXT_TPM_BYTES];
5514} __ec_align4;
5515
5516/*****************************************************************************/
5517/* Touchpad MCU commands: range 0x0500-0x05FF */
5518
5519/* Perform touchpad self test */
5520#define EC_CMD_TP_SELF_TEST 0x0500
5521
5522/* Get number of frame types, and the size of each type */
5523#define EC_CMD_TP_FRAME_INFO 0x0501
5524
5525struct ec_response_tp_frame_info {
5526 uint32_t n_frames;
5527 uint32_t frame_sizes[0];
5528} __ec_align4;
5529
5530/* Create a snapshot of current frame readings */
5531#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
5532
5533/* Read the frame */
5534#define EC_CMD_TP_FRAME_GET 0x0503
5535
5536struct ec_params_tp_frame_get {
5537 uint32_t frame_index;
5538 uint32_t offset;
5539 uint32_t size;
5540} __ec_align4;
5541
5542/*****************************************************************************/
5543/* EC-EC communication commands: range 0x0600-0x06FF */
5544
5545#define EC_COMM_TEXT_MAX 8
5546
5547/*
5548 * Get battery static information, i.e. information that never changes, or
5549 * very infrequently.
5550 */
5551#define EC_CMD_BATTERY_GET_STATIC 0x0600
5552
5553/**
5554 * struct ec_params_battery_static_info - Battery static info parameters
5555 * @index: Battery index.
5556 */
5557struct ec_params_battery_static_info {
5558 uint8_t index;
5559} __ec_align_size1;
5560
5561/**
5562 * struct ec_response_battery_static_info - Battery static info response
5563 * @design_capacity: Battery Design Capacity (mAh)
5564 * @design_voltage: Battery Design Voltage (mV)
5565 * @manufacturer: Battery Manufacturer String
5566 * @model: Battery Model Number String
5567 * @serial: Battery Serial Number String
5568 * @type: Battery Type String
5569 * @cycle_count: Battery Cycle Count
5570 */
5571struct ec_response_battery_static_info {
5572 uint16_t design_capacity;
5573 uint16_t design_voltage;
5574 char manufacturer[EC_COMM_TEXT_MAX];
5575 char model[EC_COMM_TEXT_MAX];
5576 char serial[EC_COMM_TEXT_MAX];
5577 char type[EC_COMM_TEXT_MAX];
5578 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
5579 uint32_t cycle_count;
5580} __ec_align4;
5581
5582/*
5583 * Get battery dynamic information, i.e. information that is likely to change
5584 * every time it is read.
5585 */
5586#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
5587
5588/**
5589 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
5590 * @index: Battery index.
5591 */
5592struct ec_params_battery_dynamic_info {
5593 uint8_t index;
5594} __ec_align_size1;
5595
5596/**
5597 * struct ec_response_battery_dynamic_info - Battery dynamic info response
5598 * @actual_voltage: Battery voltage (mV)
5599 * @actual_current: Battery current (mA); negative=discharging
5600 * @remaining_capacity: Remaining capacity (mAh)
5601 * @full_capacity: Capacity (mAh, might change occasionally)
5602 * @flags: Flags, see EC_BATT_FLAG_*
5603 * @desired_voltage: Charging voltage desired by battery (mV)
5604 * @desired_current: Charging current desired by battery (mA)
5605 */
5606struct ec_response_battery_dynamic_info {
5607 int16_t actual_voltage;
5608 int16_t actual_current;
5609 int16_t remaining_capacity;
5610 int16_t full_capacity;
5611 int16_t flags;
5612 int16_t desired_voltage;
5613 int16_t desired_current;
5614} __ec_align2;
5615
5616/*
5617 * Control charger chip. Used to control charger chip on the slave.
5618 */
5619#define EC_CMD_CHARGER_CONTROL 0x0602
5620
5621/**
5622 * struct ec_params_charger_control - Charger control parameters
5623 * @max_current: Charger current (mA). Positive to allow base to draw up to
5624 * max_current and (possibly) charge battery, negative to request current
5625 * from base (OTG).
5626 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
5627 * >= 0.
5628 * @allow_charging: Allow base battery charging (only makes sense if
5629 * max_current > 0).
5630 */
5631struct ec_params_charger_control {
5632 int16_t max_current;
5633 uint16_t otg_voltage;
5634 uint8_t allow_charging;
5635} __ec_align_size1;
5636
5637/*****************************************************************************/
5638/*
5639 * Reserve a range of host commands for board-specific, experimental, or
5640 * special purpose features. These can be (re)used without updating this file.
5641 *
5642 * CAUTION: Don't go nuts with this. Shipping products should document ALL
5643 * their EC commands for easier development, testing, debugging, and support.
5644 *
5645 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
5646 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
5647 *
5648 * In your experimental code, you may want to do something like this:
5649 *
5650 * #define EC_CMD_MAGIC_FOO 0x0000
5651 * #define EC_CMD_MAGIC_BAR 0x0001
5652 * #define EC_CMD_MAGIC_HEY 0x0002
5653 *
5654 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
5655 * EC_VER_MASK(0);
5656 *
5657 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
5658 * EC_VER_MASK(0);
5659 *
5660 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
5661 * EC_VER_MASK(0);
5662 */
5663#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
5664#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
5665
5666/*
5667 * Given the private host command offset, calculate the true private host
5668 * command value.
5669 */
5670#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
5671 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
3502 5672
3503/*****************************************************************************/ 5673/*****************************************************************************/
3504/* 5674/*
@@ -3538,4 +5708,6 @@ struct ec_response_usb_pd_mux_info {
3538#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1 5708#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3539#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE 5709#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3540 5710
5711
5712
3541#endif /* __CROS_EC_COMMANDS_H */ 5713#endif /* __CROS_EC_COMMANDS_H */